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 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #
  2. # This file is part of Lodel 2 (https://github.com/OpenEdition)
  3. #
  4. # Copyright (C) 2015-2017 Cléo UMS-3287
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published
  8. # by the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. from lodel.context import LodelContext
  20. LodelContext.expose_modules(globals(), {'lodel.logger': 'logger'})
  21. LodelContext.expose_dyncode(globals(), 'dyncode')
  22. from .base import get_response
  23. from .utils import *
  24. from ...exceptions import *
  25. ##@brief These functions are called by the rules defined in ../urls.py
  26. ## To browse the editorial model
  27. ##@brief Controller's function to list all types (classes) of the editorial model
  28. # @param request : the request (get or post)
  29. # @note the response is given in a html page called in get_response_function
  30. def list_classes(request):
  31. if 'allclasses' in request.GET:
  32. allclasses = request.GET['allclasses']
  33. else:
  34. allclasses = 1
  35. return get_response('listing/list_classes.html', my_classes=dyncode.dynclasses, allclasses = allclasses)
  36. ##@brief Controller's function to list all types (classes) of the editorial model
  37. # @param request : the request (get or post)
  38. # @note the response is given in a html page called in get_response_function
  39. def collections(request):
  40. return get_response('listing/collections.html', my_classes=dyncode, get_authors=get_authors)
  41. ##@brief Controller's function to list all types (classes) of the editorial model
  42. # @param request : the request (get or post)
  43. # @note the response is given in a html page called in get_response_function
  44. def issue(request):
  45. lodel_id = request.GET['lodel_id']
  46. return get_response('listing/issue.html', lodel_id=lodel_id[0], my_classes=dyncode )
  47. ##@brief Controller's function to display a type (class) of the editorial model
  48. # @param request : the request (get or post)
  49. # @note the response is given in a html page called in get_response_function
  50. def show_class(request):
  51. if 'classname' in request.GET:
  52. classname = request.GET['classname']
  53. if len(classname) > 1:
  54. raise HttpException(400)
  55. classname = classname[0]
  56. try:
  57. target_leo = dyncode.Object.name2class(classname)
  58. except LeApiError:
  59. classname = None
  60. else:
  61. raise HttpException(400)
  62. return get_response('listing/show_class.html', classname=classname)
  63. ##@brief Controller's function to display an instance or a certain type
  64. # @param request : the request (get or post)
  65. # @note the response is given in a html page called in get_response_function
  66. def show_object(request):
  67. if 'classname' in request.GET:
  68. classname = request.GET['classname']
  69. if len(classname) > 1:
  70. raise HttpException(400)
  71. classname = classname[0]
  72. try:
  73. target_leo = dyncode.Object.name2class(classname)
  74. except LeApiError:
  75. classname = None
  76. else:
  77. raise HttpException(400)
  78. logger.warning('Composed uids broken here')
  79. uid_field = target_leo.uid_fieldname()[0]
  80. test_valid = 'lodel_id' in request.GET \
  81. and len(request.GET['lodel_id']) == 1
  82. if test_valid:
  83. try:
  84. dh = target_leo.field(uid_field)
  85. lodel_id = dh.cast_type(request.GET['lodel_id'][0])
  86. except (ValueError, TypeError):
  87. test_valid = False
  88. if not test_valid:
  89. raise HttpException(400)
  90. else:
  91. query_filters = list()
  92. query_filters.append((uid_field,'=',lodel_id))
  93. obj = target_leo.get(query_filters)
  94. if len(obj) == 0:
  95. raise HttpException(404)
  96. return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
  97. ##@brief Controller's function to display an instance or a certain type
  98. # @param request : the request (get or post)
  99. # @note the response is given in a html page called in get_response_function
  100. def show_object_detailled(request):
  101. if 'classname' in request.GET:
  102. classname = request.GET['classname']
  103. if len(classname) > 1:
  104. raise HttpException(400)
  105. classname = classname[0]
  106. try:
  107. target_leo = dyncode.Object.name2class(classname)
  108. except LeApiError:
  109. classname = None
  110. else:
  111. raise HttpException(400)
  112. logger.warning('Composed uids broken here')
  113. uid_field = target_leo.uid_fieldname()[0]
  114. test_valid = 'lodel_id' in request.GET \
  115. and len(request.GET['lodel_id']) == 1
  116. if test_valid:
  117. try:
  118. dh = target_leo.field(uid_field)
  119. lodel_id = dh.cast_type(request.GET['lodel_id'][0])
  120. except (ValueError, TypeError):
  121. test_valid = False
  122. if not test_valid:
  123. raise HttpException(400)
  124. else:
  125. query_filters = list()
  126. query_filters.append((uid_field,'=',lodel_id))
  127. obj = target_leo.get(query_filters)
  128. if len(obj) == 0:
  129. raise HttpException(404)
  130. return get_response('listing/show_object_detailled.html', lodel_id=lodel_id, classname=classname)