Add profile page and temporary base.html
This commit is contained in:
parent
2919761b2f
commit
981e793e3e
@ -15,7 +15,6 @@ from pathlib import Path
|
|||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||||
|
|
||||||
@ -27,7 +26,6 @@ DEBUG = True
|
|||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
@ -72,7 +70,6 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = 'access_controller.wsgi.application'
|
WSGI_APPLICATION = 'access_controller.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||||
|
|
||||||
@ -83,7 +80,6 @@ DATABASES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
@ -102,7 +98,6 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
# https://docs.djangoproject.com/en/3.1/topics/i18n/
|
||||||
|
|
||||||
@ -116,7 +111,6 @@ USE_L10N = True
|
|||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
@ -126,3 +120,4 @@ STATICFILES_DIRS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
MEDIA_ROOT = BASE_DIR / 'media'
|
MEDIA_ROOT = BASE_DIR / 'media'
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
@ -13,9 +13,15 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
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.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from access_controller import settings
|
||||||
|
from main.views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('profile/', profile_page, name="Profile"),
|
||||||
]
|
]
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
46
main/extra_func.py
Normal file
46
main/extra_func.py
Normal file
@ -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
|
35
main/templates/base/base.html
Normal file
35
main/templates/base/base.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<link
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css"
|
||||||
|
rel="stylesheet"
|
||||||
|
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
/>
|
||||||
|
<style>
|
||||||
|
{% block extra_css %}{% endblock %}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<div class="container">
|
||||||
|
<h1 class="mb-4">
|
||||||
|
{% block heading %}{% endblock %}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container" >
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
<script
|
||||||
|
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js"
|
||||||
|
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
|
||||||
|
crossorigin="anonymous"
|
||||||
|
></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
35
main/templates/pages/profile.html
Normal file
35
main/templates/pages/profile.html
Normal file
@ -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 %}
|
||||||
|
<br>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="container">
|
||||||
|
<img src="/media/{{image_name}}" class="img img-thumbnail" alt="Нет изображения"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col g-5">
|
||||||
|
<div class="row g-5">
|
||||||
|
<h4><span class="badge bg-secondary">Имя пользователя</span> {{name}}</h4>
|
||||||
|
<h4><span class="badge bg-secondary">Электронная почта</span> {{email}}</h4>
|
||||||
|
<h4><span class="badge bg-secondary">Текущая роль</span> {{role}}</h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -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.
|
# 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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user