Fix/header

This commit is contained in:
Андреев Дмитрий 2021-05-10 15:05:34 +00:00 committed by Татищев Юрий
parent e886004069
commit 63949dd54e
3 changed files with 29 additions and 41 deletions

View File

@ -22,8 +22,9 @@
"pk": 1,
"fields": {
"name": "ZendeskAdmin",
"user": 1,
"role": "admin"
"user": 3,
"role": "admin",
"user_id": 1
}
},
{

View File

@ -3,56 +3,62 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<nav class="navbar navbar-light" style="background-color: #113A60;">
<nav class="navbar navbar-light py-3" style="background-color: #113A60;">
<a class="navbar-brand" href="{% url 'index' %}">
<img src="{% static 'main/img/logo_real.png' %}" width="107" height="22" class="d-inline-block align-top" style="margin-left: 15px" alt="" loading="lazy">
<t style="color:#FFFFFF">Access Controller</t>
<t class="px-2" style="color:#FFFFFF">Access Controller</t>
</a>
{% if request.user.is_authenticated %}
<div class="btn-group" role="group" aria-label="Basic example" style="margin-right: 9px">
<a {% if profile_lit %}
{% url 'profile' as profile_url %}
<a {% if request.path == profile_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="{% url 'profile' %}">Профиль</a>
href="{{ profile_url }}">Профиль</a>
{% if perms.main.has_control_access %}
<a {% if control_lit %}
{% url 'control' as control_url %}
<a {% if request.path == control_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="{% url 'control' %}">Управление</a>
<a {% if stats_lit %}
href="{{ control_url }}">Управление</a>
{% url 'statistic' as statistic_url %}
<a {% if request.path == statistic_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="{% url 'statistic' %}">Статистика</a>
href="{{ statistic_url }}">Статистика</a>
{% else %}
<a {% if work_lit %}
{% url 'work' request.user.id as work_url %}
<a {% if request.path == work_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="{% url 'work' request.user.id %}">Запрос прав</a>
href="{{ work_url }}">Запрос прав</a>
{% endif %}
<a class="btn btn-secondary" href="{% url 'logout' %}">Выйти</a>
</div>
{% else %}
<div class="btn-group" role="group" aria-label="Basic example" style="margin-right: 9px">
<a {% if login_lit %}
{% url 'login' as login_url %}
<a {% if request.path == login_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="/accounts/login">Войти</a>
<a {% if registration_lit %}
href="{{ login_url }}">Войти</a>
{% url 'registration' as registration_url %}
<a {% if request.path == registration_url %}
class="btn btn-primary"
{% else %}
class="btn btn-secondary"
{% endif %}
href="/accounts/register">Зарегистрироваться</a>
href="{{ registration_url }}">Зарегистрироваться</a>
</div>
{% endif %}
</nav>

View File

@ -32,20 +32,6 @@ from main.serializers import ProfileSerializer, ZendeskUserSerializer
from .models import UserProfile
def setup_context(profile_lit: bool = False, control_lit: bool = False, work_lit: bool = False,
registration_lit: bool = False, login_lit: bool = False, stats_lit: bool = False) -> Dict[str, Any]:
context = {
'profile_lit': profile_lit,
'control_lit': control_lit,
'work_lit': work_lit,
'registration_lit': registration_lit,
'login_lit': login_lit,
'stats_lit': stats_lit,
}
return context
class CustomRegistrationView(RegistrationView):
"""
Отображение и логика работы страницы регистрации пользователя.
@ -59,7 +45,6 @@ class CustomRegistrationView(RegistrationView):
:param is_allowed: Определение зарегистрирован ли пользователь с введенным email на Zendesk и принадлежит ли он к организации SYSTEM
:type is_allowed: :class:`bool`
"""
extra_context = setup_context(registration_lit=True)
form_class = CustomRegistrationForm
template_name = 'django_registration/registration_form.html'
urls = {
@ -151,12 +136,11 @@ def profile_page(request: WSGIRequest) -> HttpResponse:
"""
user_profile: UserProfile = request.user.userprofile
update_profile(user_profile)
context = setup_context(profile_lit=True)
context.update({
context = {
'profile': user_profile,
'pagename': 'Страница профиля',
'ZENDESK_ROLES': ZENDESK_ROLES,
})
}
return render(request, 'pages/profile.html', context)
@ -188,14 +172,13 @@ def work_page(request: WSGIRequest, id: int) -> HttpResponse:
engineers.append(user)
elif user.custom_role_id == ZENDESK_ROLES['light_agent']:
light_agents.append(user)
context = setup_context(work_lit=True)
context.update({
context = {
'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")
@ -311,7 +294,6 @@ class CustomLoginView(LoginView):
"""
Отображение страницы авторизации пользователя
"""
extra_context = setup_context(login_lit=True)
form_class = CustomAuthenticationForm
@ -369,11 +351,10 @@ def statistic_page(request: WSGIRequest) -> HttpResponse:
if not request.user.has_perm("main.has_control_access"):
return redirect('index')
context = setup_context(stats_lit=True)
context.update({
context = {
'pagename': 'страница статистики',
'errors': list(),
})
}
if request.method == "POST":
form = StatisticForm(request.POST)
if form.is_valid():