Merge remote-tracking branch 'origin/feature/profile_page' into feature/registration
# Conflicts: # access_controller/urls.py # main/views.py
This commit is contained in:
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:`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
|
||||
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,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)
|
||||
|
||||
Reference in New Issue
Block a user