users/context.py

90 lines
3.3 KiB
Python
Raw Normal View History

2020-01-26 20:47:33 +01:00
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
from . import parameter
2020-01-26 20:47:33 +01:00
ADMIN_ENTRY_UID = 'admin-main'
LOGIN_ENTRY_UID = 'login-main'
LOGOUT_ENTRY_UID = 'logout-main'
PROFILE_ENTRY_UID = 'profile-main'
REGISTER_ENTRY_UID = 'register-main'
def context_adaption(context, request, title):
context.set_additional_title(title)
menubar(context[context.MENUBAR], request)
context[context.NAVIGATIONBAR].append_entry(*empty_entry_parameters(request))
actionbar(context[context.ACTIONBAR], request)
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_SELF_REGISTRATION):
bar.append_entry(*register_entry_parameters(request, left=True))
2020-01-26 20:47:33 +01:00
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
False # 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
False # 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
False # active
)