Django Library Users
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

context.py 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, url_recover
  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. RECOVER_ENTRY_UID = 'recover-main'
  11. REGISTER_ENTRY_UID = 'register-main'
  12. def context_adaption(context, request, title, **kwargs):
  13. context.set_additional_title(title)
  14. menubar(context[context.MENUBAR], request)
  15. context[context.NAVIGATIONBAR].append_entry(*empty_entry_parameters(request))
  16. actionbar(context[context.ACTIONBAR], request)
  17. for key in kwargs:
  18. context[key] = kwargs[key]
  19. def menubar(bar, request):
  20. if not request.user.is_authenticated:
  21. bar.append_entry(*login_entry_parameters(request))
  22. else:
  23. bar.append_entry(*logout_entry_parameters(request))
  24. if request.user.is_staff or request.user.is_superuser:
  25. bar.append_entry(*admin_entry_parameters(request))
  26. bar.append_entry(*profile_entry_parameters(request))
  27. def actionbar(bar, request):
  28. bar.append_entry(*login_entry_parameters(request, left=True))
  29. bar.append_entry(*recover_entry_parameters(request, left=True))
  30. if parameter.get(parameter.USERS_SELF_REGISTRATION):
  31. bar.append_entry(*register_entry_parameters(request, left=True))
  32. def login_entry_parameters(request, left=False):
  33. return (
  34. LOGIN_ENTRY_UID, # uid
  35. _('Login'), # name
  36. color_icon_url(request, 'login.png'), # icon
  37. url_login(request), # url
  38. left, # left
  39. request.path == url_login(request, True) # active
  40. )
  41. def recover_entry_parameters(request, left=False):
  42. return (
  43. RECOVER_ENTRY_UID, # uid
  44. _('Recover'), # name
  45. color_icon_url(request, 'recover.png'), # icon
  46. url_recover(request), # url
  47. left, # left
  48. request.path == url_recover(request, True) # active
  49. )
  50. def register_entry_parameters(request, left=False):
  51. return (
  52. REGISTER_ENTRY_UID, # uid
  53. _('Register'), # name
  54. color_icon_url(request, 'register.png'), # icon
  55. url_register(request), # url
  56. left, # left
  57. request.path == url_register(request, True) # active
  58. )
  59. def logout_entry_parameters(request):
  60. return (
  61. LOGOUT_ENTRY_UID, # uid
  62. _('Logout'), # name
  63. color_icon_url(request, 'logout.png'), # icon
  64. url_logout(request), # url
  65. False, # left
  66. False, # active
  67. )
  68. def admin_entry_parameters(request):
  69. return (
  70. ADMIN_ENTRY_UID, # uid
  71. _('Administration'), # name
  72. color_icon_url(request, 'admin.png'), # icon
  73. reverse('admin:index'), # url
  74. False, # left
  75. False # active
  76. )
  77. def profile_entry_parameters(request):
  78. return (
  79. PROFILE_ENTRY_UID, # uid
  80. request.user.username, # name
  81. color_icon_url(request, 'user.png'), # icon
  82. url_profile(request), # url
  83. False, # left
  84. request.path == url_profile(request, True) # active
  85. )