Profile view page refactoring

This commit is contained in:
Andrew Smirnov 2021-03-04 20:01:10 +03:00
parent 3a448a399a
commit 656081295e
No known key found for this signature in database
GPG Key ID: 0EFE318E5BB2A82A
2 changed files with 17 additions and 24 deletions

View File

@ -10,17 +10,14 @@
{% block extra_css %}
<style>
.img{
<style>
.img {
width:auto;
height:auto;
max-width:100px!important;
max-height:100px!important;
}
</style>
</style>
{% endblock %}
{% block content %}
@ -28,24 +25,24 @@
<div class="row">
<div class="col-auto">
<div class="container">
{% if image_url %}
<img src={{image_url}} class="img img-thumbnail" alt="Аватар">
{% else %}
<img src="{% static 'no_avatar.png' %}" class="img img-thumbnail" alt="Нет изображения">
{% endif %}
<img
src="{% if profile.image %}{{ profile.image }}{% else %}{% static 'no_avatar.png' %}{% endif %}"
class="img img-thumbnail"
alt="Нет изображения"
>
</div>
</div>
<div class="col">
<h5><span class="badge bg-secondary text-light">Имя пользователя</span> {{name}}</h5>
<h5><span class="badge bg-secondary text-light">Имя пользователя</span> {{ profile.name }}</h5>
<br>
<h5><span class="badge bg-secondary text-light">Электронная почта</span> {{email}}</h5>
<h5><span class="badge bg-secondary text-light">Электронная почта</span> {{ profile.user.email }}</h5>
<br>
<h5><span class="badge bg-secondary text-light">Текущая роль</span> {{role}}</h5>
<h5><span class="badge bg-secondary text-light">Текущая роль</span> {{ profile.role }}</h5>
</div>
</div>
<div align="center">
<form action="">
<a href="/work/{{ id }}" class="btn btn-primary"><big>Запросить права доступа</big></a>
<a href="{% url 'work' profile.user.id %}" class="btn btn-primary"><big>Запросить права доступа</big></a>
</form>
</div>
{% endblock %}

View File

@ -5,7 +5,8 @@ from django.contrib.auth.tokens import default_token_generator
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.views import LoginView
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render, get_list_or_404, redirect
from django.urls import reverse_lazy, reverse
from django.views.generic import FormView
@ -95,19 +96,14 @@ class CustomRegistrationView(RegistrationView):
@login_required()
def profile_page(request: UserProfile) -> UserProfile:
def profile_page(request: WSGIRequest) -> HttpResponse:
"""
Отображение страницы профиля
"""
user_profile = request.user.userprofile
user_profile: UserProfile = request.user.userprofile
update_profile(user_profile)
context = {
'email': user_profile.user.email,
'name': user_profile.name,
'role': user_profile.role,
'id': user_profile.id,
'image_url': user_profile.image,
'profile': user_profile,
'pagename': 'Страница профиля'
}
return render(request, 'pages/profile.html', context)