From 981e793e3e856eacdb4b0418c6fa42100319aa59 Mon Sep 17 00:00:00 2001 From: Sokurov Idar Date: Sat, 6 Feb 2021 14:33:55 +0300 Subject: [PATCH 1/4] Add profile page and temporary base.html --- access_controller/settings.py | 7 +---- access_controller/urls.py | 6 ++++ main/extra_func.py | 46 +++++++++++++++++++++++++++++++ main/templates/base/base.html | 35 +++++++++++++++++++++++ main/templates/pages/profile.html | 35 +++++++++++++++++++++++ main/views.py | 27 +++++++++++++++++- 6 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 main/extra_func.py create mode 100644 main/templates/base/base.html create mode 100644 main/templates/pages/profile.html diff --git a/access_controller/settings.py b/access_controller/settings.py index dc44189..91aed60 100644 --- a/access_controller/settings.py +++ b/access_controller/settings.py @@ -15,7 +15,6 @@ from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ @@ -27,7 +26,6 @@ DEBUG = True ALLOWED_HOSTS = [] - # Application definition INSTALLED_APPS = [ @@ -72,7 +70,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'access_controller.wsgi.application' - # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases @@ -83,7 +80,6 @@ DATABASES = { } } - # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators @@ -102,7 +98,6 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ @@ -116,7 +111,6 @@ USE_L10N = True USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ @@ -126,3 +120,4 @@ STATICFILES_DIRS = [ ] MEDIA_ROOT = BASE_DIR / 'media' +MEDIA_URL = '/media/' diff --git a/access_controller/urls.py b/access_controller/urls.py index e0ecf63..12b2b8c 100644 --- a/access_controller/urls.py +++ b/access_controller/urls.py @@ -13,9 +13,15 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf.urls.static import static from django.contrib import admin from django.urls import path +from access_controller import settings +from main.views import * + urlpatterns = [ path('admin/', admin.site.urls), + path('profile/', profile_page, name="Profile"), ] +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/main/extra_func.py b/main/extra_func.py new file mode 100644 index 0000000..a5ca8d2 --- /dev/null +++ b/main/extra_func.py @@ -0,0 +1,46 @@ +from main.models import UserProfile + + +# Дополнительные функции +def set_and_get_username(UP: UserProfile): # TODO: Переделать с получением данных через API + """ + Функция устанавливает поле :class:`user.username` текущим именем в Zendesk + + :param UP: Объект профиля пользователя + :type UP: :class:`UserProfile` + :return: Имя пользователя + """ + return UP.user.username + + +def set_and_get_email(UP: UserProfile): # TODO: Переделать с получением данных через API + """ + Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk + + :param UP: Объект профиля пользователя + :type UP: :class:`UserProfile` + :return: Почта пользователя + """ + return UP.user.email + + +def set_and_get_role(UP: UserProfile): # TODO: Переделать с получением данных через API + """ + Функция устанавливает поле :class:`role` текущей ролью в Zendesk + + :param UP: Объект профиля пользователя + :type UP: :class:`UserProfile` + :return: Роль пользователя + """ + return UP.role + + +def load_and_get_image(UP: UserProfile): # TODO: Переделать с получением изображения через API + """ + Функция загружает и устанавливает изображение в поле :class:`image` + + :param UP: Объект профиля пользователя + :type UP: :class:`UserProfile` + :return: Название изображения + """ + return UP.image.name diff --git a/main/templates/base/base.html b/main/templates/base/base.html new file mode 100644 index 0000000..b53080c --- /dev/null +++ b/main/templates/base/base.html @@ -0,0 +1,35 @@ + + + + + {% block title %}{% endblock %} + + + + + +
+
+

+ {% block heading %}{% endblock %} +

+
+ +
+ {% block content %}{% endblock %} +
+
+ + + diff --git a/main/templates/pages/profile.html b/main/templates/pages/profile.html new file mode 100644 index 0000000..c6c1780 --- /dev/null +++ b/main/templates/pages/profile.html @@ -0,0 +1,35 @@ +{% extends 'base/base.html' %} +{% load static %} + +{% block title %} + {{ pagename }} +{% endblock %} + +{% block heading %} + Профиль +{% endblock %} + +{% block extra_css%} + .img{ + width:auto; + height:auto; + max-width:400px!important; + max-height:500px!important; + } +{% endblock %} +{% block content %} +
+
+
+
+ Нет изображения
+
+
+
+

Имя пользователя {{name}}

+

Электронная почта {{email}}

+

Текущая роль {{role}}

+
+
+
+{% endblock %} diff --git a/main/views.py b/main/views.py index 91ea44a..19fe76c 100644 --- a/main/views.py +++ b/main/views.py @@ -1,3 +1,28 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect + +from main.extra_func import set_and_get_username, set_and_get_email, load_and_get_image, set_and_get_role +from main.models import UserProfile + # Create your views here. + +def profile_page(request): + """ + Отображение страницы профиля + + :param request: объект с деталями запроса + :type request: :class:`django.http.HttpResponse + :return: объект ответа сервера с HTML-кодом внутри + """ + if request.user.is_authenticated: + UP = UserProfile.objects.get(user=request.user) + else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required() + UP = UserProfile.objects.get(user=1) + context = { + 'name': set_and_get_username(UP), + 'email': set_and_get_email(UP), + 'role': set_and_get_role(UP), + 'image_name': load_and_get_image(UP), + 'pagename': 'Страница профиля' + } + return render(request, 'pages/profile.html', context) From 3d4a49a3500bf56b5be9918519e71583752f80be Mon Sep 17 00:00:00 2001 From: Sokurov Idar Date: Sat, 6 Feb 2021 14:45:39 +0300 Subject: [PATCH 2/4] fix typo --- main/extra_func.py | 8 ++++---- main/views.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main/extra_func.py b/main/extra_func.py index a5ca8d2..6d74db6 100644 --- a/main/extra_func.py +++ b/main/extra_func.py @@ -7,7 +7,7 @@ def set_and_get_username(UP: UserProfile): # TODO: Переделать с по Функция устанавливает поле :class:`user.username` текущим именем в Zendesk :param UP: Объект профиля пользователя - :type UP: :class:`UserProfile` + :type UP: :class:`main.models.UserProfile` :return: Имя пользователя """ return UP.user.username @@ -18,7 +18,7 @@ def set_and_get_email(UP: UserProfile): # TODO: Переделать с пол Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk :param UP: Объект профиля пользователя - :type UP: :class:`UserProfile` + :type UP: :class:`main.models.UserProfile` :return: Почта пользователя """ return UP.user.email @@ -29,7 +29,7 @@ def set_and_get_role(UP: UserProfile): # TODO: Переделать с полу Функция устанавливает поле :class:`role` текущей ролью в Zendesk :param UP: Объект профиля пользователя - :type UP: :class:`UserProfile` + :type UP: :class:`main.models.UserProfile` :return: Роль пользователя """ return UP.role @@ -40,7 +40,7 @@ def load_and_get_image(UP: UserProfile): # TODO: Переделать с пол Функция загружает и устанавливает изображение в поле :class:`image` :param UP: Объект профиля пользователя - :type UP: :class:`UserProfile` + :type UP: :class:`main.models.UserProfile` :return: Название изображения """ return UP.image.name diff --git a/main/views.py b/main/views.py index 19fe76c..39054cc 100644 --- a/main/views.py +++ b/main/views.py @@ -11,7 +11,7 @@ def profile_page(request): Отображение страницы профиля :param request: объект с деталями запроса - :type request: :class:`django.http.HttpResponse + :type request: :class:`django.http.HttpResponse` :return: объект ответа сервера с HTML-кодом внутри """ if request.user.is_authenticated: From 0583e350dbac6cfd973d7526dd3d2d4cd6b1d574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=BA=D1=83=D1=80=D0=BE=D0=B2=20=D0=98=D0=B4?= =?UTF-8?q?=D0=B0=D1=80?= Date: Sat, 6 Feb 2021 12:27:45 +0000 Subject: [PATCH 3/4] Add request access button --- main/templates/pages/profile.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main/templates/pages/profile.html b/main/templates/pages/profile.html index c6c1780..4066d5a 100644 --- a/main/templates/pages/profile.html +++ b/main/templates/pages/profile.html @@ -29,6 +29,9 @@

Имя пользователя {{name}}

Электронная почта {{email}}

Текущая роль {{role}}

+
+ +
From d686a1566e4a8c60ea27abb243d37c0bdf4f89ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=BA=D1=83=D1=80=D0=BE=D0=B2=20=D0=98=D0=B4?= =?UTF-8?q?=D0=B0=D1=80?= Date: Sun, 7 Feb 2021 14:13:50 +0000 Subject: [PATCH 4/4] Small fix profile.html --- main/templates/base/base.html | 4 +--- main/templates/pages/profile.html | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main/templates/base/base.html b/main/templates/base/base.html index b53080c..e6d3628 100644 --- a/main/templates/base/base.html +++ b/main/templates/base/base.html @@ -9,9 +9,7 @@ integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous" /> - + {% block extra_css %}{% endblock %} diff --git a/main/templates/pages/profile.html b/main/templates/pages/profile.html index 4066d5a..b6ee09c 100644 --- a/main/templates/pages/profile.html +++ b/main/templates/pages/profile.html @@ -10,11 +10,13 @@ {% endblock %} {% block extra_css%} + } {% endblock %} {% block content %}