Django Library Users
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

context.py 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from django.urls.base import reverse
  2. from django.utils.translation import gettext as _
  3. from themes import empty_entry_parameters, color_icon_url
  4. from . import url_login, url_logout, url_register, url_profile
  5. from . import parameter
  6. ADMIN_ENTRY_UID = 'admin-main'
  7. LOGIN_ENTRY_UID = 'login-main'
  8. LOGOUT_ENTRY_UID = 'logout-main'
  9. PROFILE_ENTRY_UID = 'profile-main'
  10. REGISTER_ENTRY_UID = 'register-main'
  11. def context_adaption(context, request, title):
  12. context.set_additional_title(title)
  13. menubar(context[context.MENUBAR], request)
  14. context[context.NAVIGATIONBAR].append_entry(*empty_entry_parameters(request))
  15. actionbar(context[context.ACTIONBAR], request)
  16. def menubar(bar, request):
  17. if not request.user.is_authenticated:
  18. bar.append_entry(*login_entry_parameters(request))
  19. else:
  20. bar.append_entry(*logout_entry_parameters(request))
  21. if request.user.is_staff or request.user.is_superuser:
  22. bar.append_entry(*admin_entry_parameters(request))
  23. bar.append_entry(*profile_entry_parameters(request))
  24. def actionbar(bar, request):
  25. bar.append_entry(*login_entry_parameters(request, left=True))
  26. if parameter.get(parameter.USERS_SELF_REGISTRATION):
  27. bar.append_entry(*register_entry_parameters(request, left=True))
  28. def login_entry_parameters(request, left=False):
  29. return (
  30. LOGIN_ENTRY_UID, # uid
  31. _('Login'), # name
  32. color_icon_url(request, 'login.png'), # icon
  33. url_login(request), # url
  34. left, # left
  35. False # active
  36. )
  37. def register_entry_parameters(request, left=False):
  38. return (
  39. REGISTER_ENTRY_UID, # uid
  40. _('Register'), # name
  41. color_icon_url(request, 'register.png'), # icon
  42. url_register(request), # url
  43. left, # left
  44. False # active
  45. )
  46. def logout_entry_parameters(request):
  47. return (
  48. LOGOUT_ENTRY_UID, # uid
  49. _('Logout'), # name
  50. color_icon_url(request, 'logout.png'), # icon
  51. url_logout(request), # url
  52. False, # left
  53. False, # active
  54. )
  55. def admin_entry_parameters(request):
  56. return (
  57. ADMIN_ENTRY_UID, # uid
  58. _('Administration'), # name
  59. color_icon_url(request, 'admin.png'), # icon
  60. reverse('admin:index'), # url
  61. False, # left
  62. False # active
  63. )
  64. def profile_entry_parameters(request):
  65. return (
  66. PROFILE_ENTRY_UID, # uid
  67. request.user.username, # name
  68. color_icon_url(request, 'user.png'), # icon
  69. url_profile(request), # url
  70. False, # left
  71. False # active
  72. )