Added button highlights depending on current page
This commit is contained in:
parent
4dd48a5e4b
commit
94b5061301
@ -19,7 +19,7 @@ from django.urls import path, include
|
||||
|
||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView
|
||||
from main.views import work_page, work_hand_over, work_become_engineer, \
|
||||
AdminPageView, statistic_page
|
||||
AdminPageView, statistic_page, testing_page
|
||||
from main.urls import router
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ urlpatterns = [
|
||||
path('accounts/', include('django_registration.backends.activation.urls')),
|
||||
path('accounts/login/', include('django.contrib.auth.urls')),
|
||||
path('control/', AdminPageView.as_view(), name='control'),
|
||||
path('statistic/', statistic_page, name='statistic')
|
||||
path('statistic/', statistic_page, name='statistic'),
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
|
@ -10,11 +10,23 @@
|
||||
</a>
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-secondary" href="{% url 'profile' %}">Профиль</a>
|
||||
{% if perms.main.has_control_access %}
|
||||
<a class="btn btn-secondary" href="{% url 'control' %}">Управление</a>
|
||||
{% if profile_lit %}
|
||||
<a class="btn btn-primary" href="{% url 'profile' %}">Профиль</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary" href="{% url 'work' request.user.id %}">Запрос прав</a>
|
||||
<a class="btn btn-secondary" href="{% url 'profile' %}">Профиль</a>
|
||||
{% endif %}
|
||||
{% if perms.main.has_control_access %}
|
||||
{% if control_lit %}
|
||||
<a class="btn btn-primary" href="{% url 'control' %}">Управление</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary" href="{% url 'control' %}">Управление</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if work_lit %}
|
||||
<a class="btn btn-primary" href="{% url 'work' request.user.id %}">Запрос прав</a>
|
||||
{% else %}
|
||||
<a class="btn btn-secondary" href="{% url 'work' request.user.id %}">Запрос прав</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<a class="btn btn-secondary" href="{% url 'logout' %}">Выйти</a>
|
||||
</div>
|
||||
|
@ -121,6 +121,15 @@ class CustomRegistrationView(RegistrationView):
|
||||
return reverse_lazy('django_registration_disallowed')
|
||||
|
||||
|
||||
def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False):
|
||||
context = {
|
||||
'profile_lit': profile_lit,
|
||||
'control_lit': control_lit,
|
||||
'work_lit': work_lit,
|
||||
}
|
||||
return context
|
||||
|
||||
|
||||
@login_required()
|
||||
def profile_page(request: WSGIRequest) -> HttpResponse:
|
||||
"""
|
||||
@ -131,11 +140,12 @@ def profile_page(request: WSGIRequest) -> HttpResponse:
|
||||
"""
|
||||
user_profile: UserProfile = request.user.userprofile
|
||||
update_profile(user_profile)
|
||||
context = {
|
||||
context = setup_context(profile_lit=True)
|
||||
context.update({
|
||||
'profile': user_profile,
|
||||
'pagename': 'Страница профиля',
|
||||
'ZENDESK_ROLES': ZENDESK_ROLES,
|
||||
}
|
||||
})
|
||||
return render(request, 'pages/profile.html', context)
|
||||
|
||||
|
||||
@ -171,13 +181,14 @@ def work_page(request: WSGIRequest, id: int) -> HttpResponse:
|
||||
elif user.custom_role_id == ZENDESK_ROLES['light_agent']:
|
||||
light_agents.append(user)
|
||||
|
||||
context = {
|
||||
context = setup_context(work_lit=True)
|
||||
context.update({
|
||||
'engineers': engineers,
|
||||
'agents': light_agents,
|
||||
'messages': messages.get_messages(request),
|
||||
'licences_remaining': max(0, ZENDESK_MAX_AGENTS - len(engineers)),
|
||||
'pagename': 'Управление правами'
|
||||
}
|
||||
})
|
||||
return render(request, 'pages/work.html', context)
|
||||
return redirect("login")
|
||||
|
||||
@ -284,13 +295,17 @@ class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMi
|
||||
"""
|
||||
Функция формирования контента страницы администратора (с проверкой прав доступа)
|
||||
"""
|
||||
context = super().get_context_data(**kwargs)
|
||||
context = setup_context(control_lit=True)
|
||||
context.update(super().get_context_data(**kwargs))
|
||||
users = get_list_or_404(
|
||||
UserProfile, role='agent')
|
||||
context['users'] = users
|
||||
context['ZENDESK_ROLES'] = ZENDESK_ROLES
|
||||
context['engineers'], context['light_agents'] = count_users(get_users_list())
|
||||
context['licences_remaining'] = max(0, ZENDESK_MAX_AGENTS - context['engineers'])
|
||||
context.update({
|
||||
'users': users,
|
||||
'ZENDESK_ROLES': ZENDESK_ROLES,
|
||||
'engineers': count_users(get_users_list()),
|
||||
'light_agents': count_users(get_users_list()),
|
||||
'licences_remaining': max(0, ZENDESK_MAX_AGENTS - context['engineers']),
|
||||
})
|
||||
return context # TODO: need to get profile page url
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user