From 656081295ee723b9e734e187129f0337e4bbefcc Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Thu, 4 Mar 2021 20:01:10 +0300 Subject: [PATCH] Profile view page refactoring --- main/templates/pages/profile.html | 27 ++++++++++++--------------- main/views.py | 14 +++++--------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/main/templates/pages/profile.html b/main/templates/pages/profile.html index 6c6ecd2..a0f21f9 100644 --- a/main/templates/pages/profile.html +++ b/main/templates/pages/profile.html @@ -10,17 +10,14 @@ {% block extra_css %} - + {% endblock %} {% block content %} @@ -28,24 +25,24 @@
- {% if image_url %} - Аватар - {% else %} - Нет изображения - {% endif %} + Нет изображения
-
Имя пользователя {{name}}
+
Имя пользователя {{ profile.name }}

-
Электронная почта {{email}}
+
Электронная почта {{ profile.user.email }}

-
Текущая роль {{role}}
+
Текущая роль {{ profile.role }}
- Запросить права доступа + Запросить права доступа
{% endblock %} diff --git a/main/views.py b/main/views.py index 5c5ed12..b5d953a 100644 --- a/main/views.py +++ b/main/views.py @@ -5,7 +5,8 @@ from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.forms import PasswordResetForm from django.contrib.auth.views import LoginView from django.contrib.contenttypes.models import ContentType -from django.http import HttpResponseRedirect +from django.core.handlers.wsgi import WSGIRequest +from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import render, get_list_or_404, redirect from django.urls import reverse_lazy, reverse from django.views.generic import FormView @@ -95,19 +96,14 @@ class CustomRegistrationView(RegistrationView): @login_required() -def profile_page(request: UserProfile) -> UserProfile: +def profile_page(request: WSGIRequest) -> HttpResponse: """ Отображение страницы профиля """ - user_profile = request.user.userprofile + user_profile: UserProfile = request.user.userprofile update_profile(user_profile) - context = { - 'email': user_profile.user.email, - 'name': user_profile.name, - 'role': user_profile.role, - 'id': user_profile.id, - 'image_url': user_profile.image, + 'profile': user_profile, 'pagename': 'Страница профиля' } return render(request, 'pages/profile.html', context)