Django Library Users
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

context.py 3.4KB

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