Django Library Users
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

context.py 3.2KB

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