From c17e0341ee79990cf49e075ccb4a621e119a3e3c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 11 Oct 2023 09:52:05 +0200 Subject: [PATCH] add form for editing profile --- idhub/admin/views.py | 13 +++++++------ idhub/mixins.py | 3 +-- idhub/templates/idhub/user_profile.html | 23 +++++++++++++++++++++++ idhub/{ => user}/forms.py | 5 ++--- idhub/user/views.py | 19 ++++++++++++++----- requirements.txt | 2 +- trustchain_idhub/settings.py | 2 +- 7 files changed, 49 insertions(+), 18 deletions(-) rename idhub/{ => user}/forms.py (59%) diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 3c892ef..5d66788 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -1,39 +1,40 @@ import logging from django.utils.translation import gettext_lazy as _ +from django.views.generic.base import TemplateView from django.urls import reverse_lazy from django.contrib import messages from idhub.mixins import AdminView -class AdminDashboardView(AdminView): +class AdminDashboardView(AdminView, TemplateView): template_name = "idhub/admin_dashboard.html" title = _('Dashboard') subtitle = _('Success') icon = 'bi bi-bell' section = "Home" -class People(AdminView): +class People(AdminView, TemplateView): title = _("People Management") section = "People" -class AccessControl(AdminView): +class AccessControl(AdminView, TemplateView): title = _("Access Control Management") section = "AccessControl" -class Credentials(AdminView): +class Credentials(AdminView, TemplateView): title = _("Credentials Management") section = "Credentials" -class Schemes(AdminView): +class Schemes(AdminView, TemplateView): title = _("Schemes Management") section = "Schemes" -class ImportExport(AdminView): +class ImportExport(AdminView, TemplateView): title = _("Massive Data Management") section = "ImportExport" diff --git a/idhub/mixins.py b/idhub/mixins.py index 57eb933..51d0378 100644 --- a/idhub/mixins.py +++ b/idhub/mixins.py @@ -2,11 +2,10 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth import views as auth_views from django.urls import reverse_lazy, resolve from django.utils.translation import gettext_lazy as _ -from django.views.generic.base import TemplateView from django.shortcuts import redirect -class UserView(LoginRequiredMixin, TemplateView): +class UserView(LoginRequiredMixin): login_url = "/login/" wallet = False diff --git a/idhub/templates/idhub/user_profile.html b/idhub/templates/idhub/user_profile.html index d6520a0..fb129ba 100644 --- a/idhub/templates/idhub/user_profile.html +++ b/idhub/templates/idhub/user_profile.html @@ -2,4 +2,27 @@ {% load i18n %} {% block content %} +{% load django_bootstrap5 %} +
+{% csrf_token %} +{% if form.errors %} + +{% endif %} +{% bootstrap_form form %} + + +
{% endblock %} diff --git a/idhub/forms.py b/idhub/user/forms.py similarity index 59% rename from idhub/forms.py rename to idhub/user/forms.py index f384507..2293aac 100644 --- a/idhub/forms.py +++ b/idhub/user/forms.py @@ -2,10 +2,9 @@ from django import forms from django.contrib.auth.models import User -class ProfileForm(form.ModelForm): +class ProfileForm(forms.ModelForm): MANDATORY_FIELDS = ['first_name', 'last_name', 'email'] - OPTIONAL_FIELDS = [] class Meta: model = User - fields = ('forst_name', 'last_name', 'email') \ No newline at end of file + fields = ('first_name', 'last_name', 'email') \ No newline at end of file diff --git a/idhub/user/views.py b/idhub/user/views.py index 66bba56..7ca1760 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -1,8 +1,11 @@ import logging from django.utils.translation import gettext_lazy as _ +from django.views.generic.edit import UpdateView +from django.views.generic.base import TemplateView from django.urls import reverse_lazy from django.contrib import messages +from idhub.user.forms import ProfileForm from idhub.mixins import UserView @@ -11,12 +14,12 @@ class MyProfile(UserView): section = "MyProfile" -class MyWallet(UserView): +class MyWallet(UserView, TemplateView): title = _("My Wallet") section = "MyWallet" -class UserDashboardView(UserView): +class UserDashboardView(UserView, TemplateView): template_name = "idhub/user_dashboard.html" title = _('Dashboard') subtitle = _('Success') @@ -24,19 +27,25 @@ class UserDashboardView(UserView): section = "Home" -class UserProfileView(MyProfile): +class UserProfileView(MyProfile, UpdateView): template_name = "idhub/user_profile.html" subtitle = _('My personal Data') icon = 'bi bi-person' + from_class = ProfileForm + fields = ('first_name', 'last_name', 'email') + success_url = reverse_lazy('idhub:user_profile') + + def get_object(self): + return self.request.user -class UserRolesView(MyProfile): +class UserRolesView(MyProfile, TemplateView): template_name = "idhub/user_roles.html" subtitle = _('My roles') icon = 'fa-brands fa-critical-role' -class UserGDPRView(MyProfile): +class UserGDPRView(MyProfile, TemplateView): template_name = "idhub/user_gdpr.html" subtitle = _('GDPR info') icon = 'bi bi-file-earmark-medical' diff --git a/requirements.txt b/requirements.txt index eeefcda..93b7ce1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ django==4.2.5 -django-bootstrap4==23.2 +django-bootstrap5==23.3 django-extensions==3.2.3 diff --git a/trustchain_idhub/settings.py b/trustchain_idhub/settings.py index 3f4e7bf..ece4f60 100644 --- a/trustchain_idhub/settings.py +++ b/trustchain_idhub/settings.py @@ -38,7 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django_extensions', - 'bootstrap4', + 'django_bootstrap5', 'idhub' ]