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 %} {% block extra_css %}
<style> <style>
.img{ .img {
width:auto; width:auto;
height:auto; height:auto;
max-width:100px!important; max-width:100px!important;
max-height:100px!important; max-height:100px!important;
} }
</style>
</style>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -28,24 +25,24 @@
<div class="row"> <div class="row">
<div class="col-auto"> <div class="col-auto">
<div class="container"> <div class="container">
{% if image_url %} <img
<img src={{image_url}} class="img img-thumbnail" alt="Аватар"> src="{% if profile.image %}{{ profile.image }}{% else %}{% static 'no_avatar.png' %}{% endif %}"
{% else %} class="img img-thumbnail"
<img src="{% static 'no_avatar.png' %}" class="img img-thumbnail" alt="Нет изображения"> alt="Нет изображения"
{% endif %} >
</div> </div>
</div> </div>
<div class="col"> <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> <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> <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> </div>
<div align="center"> <div align="center">
<form action=""> <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> </form>
</div> </div>
{% endblock %} {% 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.forms import PasswordResetForm
from django.contrib.auth.views import LoginView from django.contrib.auth.views import LoginView
from django.contrib.contenttypes.models import ContentType 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.shortcuts import render, get_list_or_404, redirect
from django.urls import reverse_lazy, reverse from django.urls import reverse_lazy, reverse
from django.views.generic import FormView from django.views.generic import FormView
@ -95,19 +96,14 @@ class CustomRegistrationView(RegistrationView):
@login_required() @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) update_profile(user_profile)
context = { context = {
'email': user_profile.user.email, 'profile': user_profile,
'name': user_profile.name,
'role': user_profile.role,
'id': user_profile.id,
'image_url': user_profile.image,
'pagename': 'Страница профиля' 'pagename': 'Страница профиля'
} }
return render(request, 'pages/profile.html', context) return render(request, 'pages/profile.html', context)