123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- from django.urls.base import reverse
- from django.utils.translation import gettext as _
- from themes import empty_entry_parameters, color_icon_url
- from . import url_login, url_logout, url_register, url_profile, url_recover
- from . import parameter
-
- ADMIN_ENTRY_UID = 'admin-main'
- LOGIN_ENTRY_UID = 'login-main'
- LOGOUT_ENTRY_UID = 'logout-main'
- PROFILE_ENTRY_UID = 'profile-main'
- RECOVER_ENTRY_UID = 'recover-main'
- REGISTER_ENTRY_UID = 'register-main'
-
-
- def context_adaption(context, request, title, **kwargs):
- context.set_additional_title(title)
- menubar(context[context.MENUBAR], request)
- context[context.NAVIGATIONBAR].append_entry(*empty_entry_parameters(request))
- actionbar(context[context.ACTIONBAR], request)
- for key in kwargs:
- context[key] = kwargs[key]
-
-
- def menubar(bar, request):
- if not request.user.is_authenticated:
- bar.append_entry(*login_entry_parameters(request))
- else:
- bar.append_entry(*logout_entry_parameters(request))
- if request.user.is_staff or request.user.is_superuser:
- bar.append_entry(*admin_entry_parameters(request))
- bar.append_entry(*profile_entry_parameters(request))
-
-
- def actionbar(bar, request):
- bar.append_entry(*login_entry_parameters(request, left=True))
- if parameter.get(parameter.USERS_PASSWORD_RECOVERY) or request.user.is_superuser:
- bar.append_entry(*recover_entry_parameters(request, left=True))
- if parameter.get(parameter.USERS_SELF_REGISTRATION) or request.user.is_superuser:
- bar.append_entry(*register_entry_parameters(request, left=True))
-
-
- def login_entry_parameters(request, left=False):
- return (
- LOGIN_ENTRY_UID, # uid
- _('Login'), # name
- color_icon_url(request, 'login.png'), # icon
- url_login(request), # url
- left, # left
- request.path == url_login(request, True) # active
- )
-
-
- def recover_entry_parameters(request, left=False):
- return (
- RECOVER_ENTRY_UID, # uid
- _('Recover'), # name
- color_icon_url(request, 'recover.png'), # icon
- url_recover(request), # url
- left, # left
- request.path == url_recover(request, True) # active
- )
-
-
- def register_entry_parameters(request, left=False):
- return (
- REGISTER_ENTRY_UID, # uid
- _('Register'), # name
- color_icon_url(request, 'register.png'), # icon
- url_register(request), # url
- left, # left
- request.path == url_register(request, True) # active
- )
-
-
- def logout_entry_parameters(request):
- return (
- LOGOUT_ENTRY_UID, # uid
- _('Logout'), # name
- color_icon_url(request, 'logout.png'), # icon
- url_logout(request), # url
- False, # left
- False, # active
- )
-
-
- def admin_entry_parameters(request):
- return (
- ADMIN_ENTRY_UID, # uid
- _('Administration'), # name
- color_icon_url(request, 'admin.png'), # icon
- reverse('admin:index'), # url
- False, # left
- False # active
- )
-
-
- def profile_entry_parameters(request):
- return (
- PROFILE_ENTRY_UID, # uid
- request.user.username, # name
- color_icon_url(request, 'user.png'), # icon
- url_profile(request), # url
- False, # left
- request.path == url_profile(request, True) # active
- )
|