Small code style improvements
This commit is contained in:
parent
c3f9e6626b
commit
ac99a23a3b
@ -26,13 +26,10 @@ urlpatterns = [
|
|||||||
path('admin/', admin.site.urls, name='admin'),
|
path('admin/', admin.site.urls, name='admin'),
|
||||||
path('', main_page),
|
path('', main_page),
|
||||||
path('register/', CustomRegistrationView.as_view(), name='registration'),
|
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('profile/', profile_page, name='profile'),
|
||||||
path('accounts/login/', LoginView.as_view(extra_context={})), # TODO add extra context
|
path('accounts/login/', LoginView.as_view(extra_context={})), # TODO add extra context
|
||||||
path('accounts/', include('django.contrib.auth.urls'))
|
path('accounts/', include('django.contrib.auth.urls'))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
@ -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
|
Функция устанавливает поле :class:`username` текущим именем в Zendesk
|
||||||
|
|
||||||
@ -19,10 +19,10 @@ def set_and_get_name(UP: UserProfile):
|
|||||||
:return: Имя пользователя
|
:return: Имя пользователя
|
||||||
:rtype: :class:`str`
|
: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
|
Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ def set_and_get_email(UP: UserProfile): # TODO: Переделать с пол
|
|||||||
:return: Почта пользователя
|
:return: Почта пользователя
|
||||||
:rtype: :class:`str`
|
: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
|
Функция устанавливает поле :class:`role` текущей ролью в Zendesk
|
||||||
|
|
||||||
@ -43,10 +43,10 @@ def set_and_get_role(UP: UserProfile): # TODO: Переделать с полу
|
|||||||
:return: Роль пользователя
|
:return: Роль пользователя
|
||||||
:rtype: :class:`str`
|
: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`
|
Функция загружает и устанавливает изображение в поле :class:`image`
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def load_and_get_image(UP: UserProfile): # TODO: Переделать с пол
|
|||||||
:return: Название изображения
|
:return: Название изображения
|
||||||
:rtype: :class:`str`
|
:rtype: :class:`str`
|
||||||
"""
|
"""
|
||||||
return UP.image.name
|
return user_profile.image.name
|
||||||
|
|
||||||
|
|
||||||
def check_user_exist(email: str) -> bool:
|
def check_user_exist(email: str) -> bool:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse_lazy
|
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, \
|
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
|
check_user_auth
|
||||||
from main.models import UserProfile
|
from main.models import UserProfile
|
||||||
@ -44,9 +43,9 @@ class CustomRegistrationView(RegistrationView):
|
|||||||
else:
|
else:
|
||||||
self.is_allowed = False
|
self.is_allowed = False
|
||||||
|
|
||||||
def get_success_url(self, request):
|
def get_success_url(self, user=None):
|
||||||
"""
|
"""
|
||||||
Вовзращет url-адресс страницы, куда нужно перейти после успешной/неуспешной регистрации
|
Возвращает url-адрес страницы, куда нужно перейти после успешной/неуспешной регистрации
|
||||||
Используется самой django-registration
|
Используется самой django-registration
|
||||||
"""
|
"""
|
||||||
if self.is_allowed:
|
if self.is_allowed:
|
||||||
@ -54,6 +53,7 @@ class CustomRegistrationView(RegistrationView):
|
|||||||
else:
|
else:
|
||||||
return reverse_lazy('django_registration_disallowed')
|
return reverse_lazy('django_registration_disallowed')
|
||||||
|
|
||||||
|
|
||||||
@login_required()
|
@login_required()
|
||||||
def profile_page(request):
|
def profile_page(request):
|
||||||
"""
|
"""
|
||||||
@ -65,10 +65,10 @@ def profile_page(request):
|
|||||||
:return: объект ответа сервера с HTML-кодом внутри
|
:return: объект ответа сервера с HTML-кодом внутри
|
||||||
"""
|
"""
|
||||||
if request.user.is_authenticated:
|
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)
|
UP = UserProfile.objects.get(user=request.user)
|
||||||
#else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
|
# else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
|
||||||
#UP = UserProfile.objects.get(user=1)
|
# UP = UserProfile.objects.get(user=1)
|
||||||
context = {
|
context = {
|
||||||
'name': set_and_get_name(UP),
|
'name': set_and_get_name(UP),
|
||||||
'email': set_and_get_email(UP),
|
'email': set_and_get_email(UP),
|
||||||
@ -81,4 +81,3 @@ def profile_page(request):
|
|||||||
|
|
||||||
def main_page(request):
|
def main_page(request):
|
||||||
return render(request, 'pages/index.html')
|
return render(request, 'pages/index.html')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user