No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

listing.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- coding: utf-8 -*-
  2. from .base import get_response
  3. from ...exceptions import *
  4. from lodel import logger
  5. import leapi_dyncode as dyncode
  6. ##@brief These functions are called by the rules defined in ../urls.py
  7. ## To browse the editorial model
  8. ##@brief Controller's function to list all types (classes) of the editorial model
  9. # @param request : the request (get or post)
  10. # @note the response is given in a html page called in get_response_function
  11. def list_classes(request):
  12. if 'allclasses' in request.GET:
  13. allclasses = request.GET['allclasses']
  14. else:
  15. allclasses = 1
  16. return get_response('listing/list_classes.html', my_classes=dyncode.dynclasses, allclasses = allclasses)
  17. ##@brief Controller's function to display a type (class) of the editorial model
  18. # @param request : the request (get or post)
  19. # @note the response is given in a html page called in get_response_function
  20. def show_class(request):
  21. if 'classname' in request.GET:
  22. classname = request.GET['classname']
  23. if len(classname) > 1:
  24. raise HttpException(400)
  25. classname = classname[0]
  26. try:
  27. target_leo = dyncode.Object.name2class(classname)
  28. except LeApiError:
  29. classname = None
  30. else:
  31. raise HttpException(400)
  32. return get_response('listing/show_class.html', classname=classname)
  33. ##@brief Controller's function to display an instance or a certain type
  34. # @param request : the request (get or post)
  35. # @note the response is given in a html page called in get_response_function
  36. def show_object(request):
  37. if 'classname' in request.GET:
  38. classname = request.GET['classname']
  39. if len(classname) > 1:
  40. raise HttpException(400)
  41. classname = classname[0]
  42. try:
  43. target_leo = dyncode.Object.name2class(classname)
  44. except LeApiError:
  45. classname = None
  46. else:
  47. raise HttpException(400)
  48. logger.warning('Composed uids broken here')
  49. uid_field = target_leo.uid_fieldname()[0]
  50. test_valid = 'lodel_id' in request.GET \
  51. and len(request.GET['lodel_id']) == 1
  52. if test_valid:
  53. try:
  54. dh = target_leo.field(uid_field)
  55. lodel_id = dh.cast_type(request.GET['lodel_id'][0])
  56. except (ValueError, TypeError):
  57. test_valid = False
  58. if not test_valid:
  59. raise HttpException(400)
  60. else:
  61. query_filters = list()
  62. query_filters.append((uid_field,'=',lodel_id))
  63. obj = target_leo.get(query_filters)
  64. if len(obj) == 0:
  65. raise HttpException(404)
  66. return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
  67. ##@brief Controller's function to display an instance or a certain type
  68. # @param request : the request (get or post)
  69. # @note the response is given in a html page called in get_response_function
  70. def show_object_detailled(request):
  71. if 'classname' in request.GET:
  72. classname = request.GET['classname']
  73. if len(classname) > 1:
  74. raise HttpException(400)
  75. classname = classname[0]
  76. try:
  77. target_leo = dyncode.Object.name2class(classname)
  78. except LeApiError:
  79. classname = None
  80. else:
  81. raise HttpException(400)
  82. logger.warning('Composed uids broken here')
  83. uid_field = target_leo.uid_fieldname()[0]
  84. test_valid = 'lodel_id' in request.GET \
  85. and len(request.GET['lodel_id']) == 1
  86. if test_valid:
  87. try:
  88. dh = target_leo.field(uid_field)
  89. lodel_id = dh.cast_type(request.GET['lodel_id'][0])
  90. except (ValueError, TypeError):
  91. test_valid = False
  92. if not test_valid:
  93. raise HttpException(400)
  94. else:
  95. query_filters = list()
  96. query_filters.append((uid_field,'=',lodel_id))
  97. obj = target_leo.get(query_filters)
  98. if len(obj) == 0:
  99. raise HttpException(404)
  100. return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)