From ac99a23a3b12b20225959768c91cda3800bad84a Mon Sep 17 00:00:00 2001 From: Andrew Smirnov Date: Thu, 11 Feb 2021 20:15:46 +0300 Subject: [PATCH] Small code style improvements --- access_controller/urls.py | 7 ++----- main/extra_func.py | 16 ++++++++-------- main/views.py | 13 ++++++------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/access_controller/urls.py b/access_controller/urls.py index 0063265..350e189 100644 --- a/access_controller/urls.py +++ b/access_controller/urls.py @@ -26,13 +26,10 @@ urlpatterns = [ path('admin/', admin.site.urls, name='admin'), path('', main_page), path('register/', CustomRegistrationView.as_view(), name='registration'), - #path('', include('django_registration.backends.one_step.urls')), + # path('', include('django_registration.backends.one_step.urls')), path('profile/', profile_page, name='profile'), path('accounts/login/', LoginView.as_view(extra_context={})), # TODO add extra context path('accounts/', include('django.contrib.auth.urls')) - ] - - - +] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/main/extra_func.py b/main/extra_func.py index 50eecc6..305e897 100644 --- a/main/extra_func.py +++ b/main/extra_func.py @@ -7,7 +7,7 @@ from main.models import UserProfile # Дополнительные функции -def set_and_get_name(UP: UserProfile): +def set_and_get_name(user_profile: UserProfile): """ Функция устанавливает поле :class:`username` текущим именем в Zendesk @@ -19,10 +19,10 @@ def set_and_get_name(UP: UserProfile): :return: Имя пользователя :rtype: :class:`str` """ - return UP.user.username + return user_profile.user.username -def set_and_get_email(UP: UserProfile): # TODO: Переделать с получением данных через API +def set_and_get_email(user_profile: UserProfile): # TODO: Переделать с получением данных через API """ Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk @@ -31,10 +31,10 @@ def set_and_get_email(UP: UserProfile): # TODO: Переделать с пол :return: Почта пользователя :rtype: :class:`str` """ - return UP.user.email + return user_profile.user.email -def set_and_get_role(UP: UserProfile): # TODO: Переделать с получением данных через API +def set_and_get_role(user_profile: UserProfile): # TODO: Переделать с получением данных через API """ Функция устанавливает поле :class:`role` текущей ролью в Zendesk @@ -43,10 +43,10 @@ def set_and_get_role(UP: UserProfile): # TODO: Переделать с полу :return: Роль пользователя :rtype: :class:`str` """ - return UP.role + return user_profile.role -def load_and_get_image(UP: UserProfile): # TODO: Переделать с получением изображения через API +def load_and_get_image(user_profile: UserProfile): # TODO: Переделать с получением изображения через API """ Функция загружает и устанавливает изображение в поле :class:`image` @@ -55,7 +55,7 @@ def load_and_get_image(UP: UserProfile): # TODO: Переделать с пол :return: Название изображения :rtype: :class:`str` """ - return UP.image.name + return user_profile.image.name def check_user_exist(email: str) -> bool: diff --git a/main/views.py b/main/views.py index bd260b2..8dbfe9d 100644 --- a/main/views.py +++ b/main/views.py @@ -1,7 +1,6 @@ from django.shortcuts import render from django.urls import reverse_lazy - from main.extra_func import set_and_get_name, set_and_get_email, load_and_get_image, set_and_get_role, check_user_exist, \ check_user_auth from main.models import UserProfile @@ -44,9 +43,9 @@ class CustomRegistrationView(RegistrationView): else: self.is_allowed = False - def get_success_url(self, request): + def get_success_url(self, user=None): """ - Вовзращет url-адресс страницы, куда нужно перейти после успешной/неуспешной регистрации + Возвращает url-адрес страницы, куда нужно перейти после успешной/неуспешной регистрации Используется самой django-registration """ if self.is_allowed: @@ -54,6 +53,7 @@ class CustomRegistrationView(RegistrationView): else: return reverse_lazy('django_registration_disallowed') + @login_required() def profile_page(request): """ @@ -65,10 +65,10 @@ def profile_page(request): :return: объект ответа сервера с HTML-кодом внутри """ if request.user.is_authenticated: - #UP = UserProfile.objects.get(user=request.user) + # UP = UserProfile.objects.get(user=request.user) UP = UserProfile.objects.get(user=request.user) - #else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required() - #UP = UserProfile.objects.get(user=1) + # else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required() + # UP = UserProfile.objects.get(user=1) context = { 'name': set_and_get_name(UP), 'email': set_and_get_email(UP), @@ -81,4 +81,3 @@ def profile_page(request): def main_page(request): return render(request, 'pages/index.html') -