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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. def list_classes(request):
  7. if 'allclasses' in request.GET:
  8. allclasses = request.GET['allclasses']
  9. else:
  10. allclasses = 1
  11. return get_response('listing/list_classes.html', my_classes=dyncode.dynclasses, allclasses = allclasses)
  12. def show_class(request):
  13. if 'classname' in request.GET:
  14. classname = request.GET['classname']
  15. if len(classname) > 1:
  16. raise HttpException(400)
  17. classname = classname[0]
  18. try:
  19. target_leo = dyncode.Object.name2class(classname)
  20. except LeApiError:
  21. classname = None
  22. else:
  23. raise HttpException(400)
  24. return get_response('listing/show_class.html', classname=classname)
  25. def show_object(request):
  26. if 'classname' in request.GET:
  27. classname = request.GET['classname']
  28. if len(classname) > 1:
  29. raise HttpException(400)
  30. classname = classname[0]
  31. try:
  32. target_leo = dyncode.Object.name2class(classname)
  33. except LeApiError:
  34. classname = None
  35. else:
  36. raise HttpException(400)
  37. logger.warning('Composed uids broken here')
  38. uid_field = target_leo.uid_fieldname()[0]
  39. test_valid = uid_field in request.GET \
  40. and len(request.GET[uid_field]) == 1
  41. if test_valid:
  42. try:
  43. lodel_id = int(request.GET[uid_field][0])
  44. except (ValueError, TypeError):
  45. test_valid = False
  46. if not test_valid:
  47. raise HttpException(400)
  48. else:
  49. query_filters = list()
  50. query_filters.append((uid_field,'=',lodel_id))
  51. obj = dyncode.Object.get(query_filters)
  52. if len(obj) == 0:
  53. raise HttpException(404)
  54. return get_response('listing/show_object.html', lodel_id=lodel_id, uidfield = uid_field, classname=classname)