diff --git a/access_controller/settings.py b/access_controller/settings.py index 8f61695..24c1abf 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 = [ @@ -73,7 +71,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'access_controller.wsgi.application' - # Database # https://docs.djangoproject.com/en/3.1/ref/settings/#databases @@ -84,7 +81,6 @@ DATABASES = { } } - # Password validation # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators @@ -103,7 +99,6 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] - # Internationalization # https://docs.djangoproject.com/en/3.1/topics/i18n/ @@ -117,7 +112,6 @@ USE_L10N = True USE_TZ = True - # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ @@ -127,3 +121,4 @@ STATICFILES_DIRS = [ ] MEDIA_ROOT = BASE_DIR / 'media' +MEDIA_URL = '/media/' diff --git a/access_controller/urls.py b/access_controller/urls.py index eb189ef..b9f7386 100644 --- a/access_controller/urls.py +++ b/access_controller/urls.py @@ -13,12 +13,17 @@ 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 main.views import Reg +from access_controller import settings +from main.views import * urlpatterns = [ path('admin/', admin.site.urls, name='admin'), path('register/', Reg.as_view(), name='registration'), + 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..6d74db6 --- /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:`main.models.UserProfile` + :return: Имя пользователя + """ + return UP.user.username + + +def set_and_get_email(UP: UserProfile): # TODO: Переделать с получением данных через API + """ + Функция устанавливает поле :class:`user.email` текущей почтой в Zendesk + + :param UP: Объект профиля пользователя + :type UP: :class:`main.models.UserProfile` + :return: Почта пользователя + """ + return UP.user.email + + +def set_and_get_role(UP: UserProfile): # TODO: Переделать с получением данных через API + """ + Функция устанавливает поле :class:`role` текущей ролью в Zendesk + + :param UP: Объект профиля пользователя + :type UP: :class:`main.models.UserProfile` + :return: Роль пользователя + """ + return UP.role + + +def load_and_get_image(UP: UserProfile): # TODO: Переделать с получением изображения через API + """ + Функция загружает и устанавливает изображение в поле :class:`image` + + :param UP: Объект профиля пользователя + :type UP: :class:`main.models.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 a6208c4..c8271ee 100644 --- a/main/views.py +++ b/main/views.py @@ -1,5 +1,7 @@ -# Create your views here. -from abc import ABC +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 from django.contrib.auth.models import User from django.urls import reverse_lazy @@ -28,7 +30,7 @@ class Reg(RegistrationView): email=form.data['email'], password=form.data['email'], ) - profile=UserProfile.objects.create( + profile = UserProfile.objects.create( image='None.png', user=user, role='None' @@ -36,3 +38,25 @@ class Reg(RegistrationView): user.save() else: raise AttributeError('No such email') + + +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)