From 9ad6be8db690adda838910c3646be5c2b665e8db Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 13 Oct 2023 13:37:26 +0200 Subject: [PATCH] create a new user and edit it --- idhub/admin/forms.py | 10 ++++++ idhub/admin/views.py | 20 +++++++++--- idhub/templates/idhub/admin_credentials.html | 4 +++ idhub/templates/idhub/admin_dashboard.html | 4 +++ idhub/templates/idhub/admin_export.html | 4 +++ idhub/templates/idhub/admin_import.html | 4 +++ .../idhub/admin_issue_credentials.html | 4 +++ idhub/templates/idhub/admin_people.html | 4 +++ .../idhub/admin_people_register.html | 27 ++++++++++++++++ .../idhub/admin_revoke_credentials.html | 4 +++ idhub/templates/idhub/admin_roles.html | 4 +++ idhub/templates/idhub/admin_schemes.html | 4 +++ .../templates/idhub/admin_schemes_export.html | 4 +++ .../templates/idhub/admin_schemes_import.html | 4 +++ idhub/templates/idhub/admin_services.html | 4 +++ idhub/templates/idhub/admin_user_edit.html | 32 +++++++++++++++++++ .../idhub/admin_wallet_credentials.html | 4 +++ .../idhub/admin_wallet_identities.html | 4 +++ .../templates/idhub/admin_wallet_issues.html | 4 +++ idhub/templates/idhub/base_admin.html | 4 --- idhub/urls.py | 2 +- 21 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 idhub/admin/forms.py create mode 100644 idhub/templates/idhub/admin_user_edit.html diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py new file mode 100644 index 0000000..2293aac --- /dev/null +++ b/idhub/admin/forms.py @@ -0,0 +1,10 @@ +from django import forms +from django.contrib.auth.models import User + + +class ProfileForm(forms.ModelForm): + MANDATORY_FIELDS = ['first_name', 'last_name', 'email'] + + class Meta: + model = User + fields = ('first_name', 'last_name', 'email') \ No newline at end of file diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 35c37f0..26852c7 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -2,11 +2,13 @@ import logging from django.utils.translation import gettext_lazy as _ from django.views.generic.base import TemplateView +from django.views.generic.edit import UpdateView, CreateView from django.contrib.auth.models import User from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.contrib import messages from idhub.mixins import AdminView +from idhub.admin.forms import ProfileForm class AdminDashboardView(AdminView, TemplateView): @@ -16,7 +18,7 @@ class AdminDashboardView(AdminView, TemplateView): icon = 'bi bi-bell' section = "Home" -class People(AdminView, TemplateView): +class People(AdminView): title = _("People Management") section = "People" @@ -41,7 +43,7 @@ class ImportExport(AdminView, TemplateView): section = "ImportExport" -class AdminPeopleListView(People): +class AdminPeopleListView(People, TemplateView): template_name = "idhub/admin_people.html" subtitle = _('People list') icon = 'bi bi-person' @@ -54,7 +56,7 @@ class AdminPeopleListView(People): return context -class AdminPeopleView(People): +class AdminPeopleView(People, TemplateView): template_name = "idhub/admin_user.html" subtitle = _('User Profile') icon = 'bi bi-person' @@ -98,11 +100,21 @@ class AdminPeopleDeleteView(AdminPeopleView): return redirect('idhub:admin_people_list') +class AdminPeopleEditView(AdminPeopleView, UpdateView): + template_name = "idhub/admin_user_edit.html" + from_class = ProfileForm + fields = ('first_name', 'last_name', 'email') + success_url = reverse_lazy('idhub:admin_people_list') -class AdminPeopleRegisterView(People): + +class AdminPeopleRegisterView(People, CreateView): template_name = "idhub/admin_people_register.html" subtitle = _('People Register') icon = 'bi bi-person' + model = User + from_class = ProfileForm + fields = ('first_name', 'last_name', 'email') + success_url = reverse_lazy('idhub:admin_people_list') class AdminRolesView(AccessControl): diff --git a/idhub/templates/idhub/admin_credentials.html b/idhub/templates/idhub/admin_credentials.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_credentials.html +++ b/idhub/templates/idhub/admin_credentials.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_dashboard.html b/idhub/templates/idhub/admin_dashboard.html index cddd2ee..90f0050 100644 --- a/idhub/templates/idhub/admin_dashboard.html +++ b/idhub/templates/idhub/admin_dashboard.html @@ -2,6 +2,10 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

diff --git a/idhub/templates/idhub/admin_export.html b/idhub/templates/idhub/admin_export.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_export.html +++ b/idhub/templates/idhub/admin_export.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_import.html b/idhub/templates/idhub/admin_import.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_import.html +++ b/idhub/templates/idhub/admin_import.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_issue_credentials.html b/idhub/templates/idhub/admin_issue_credentials.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_issue_credentials.html +++ b/idhub/templates/idhub/admin_issue_credentials.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_people.html b/idhub/templates/idhub/admin_people.html index 947e0bc..8f5d6fc 100644 --- a/idhub/templates/idhub/admin_people.html +++ b/idhub/templates/idhub/admin_people.html @@ -2,6 +2,10 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

diff --git a/idhub/templates/idhub/admin_people_register.html b/idhub/templates/idhub/admin_people_register.html index db4eecd..a48b4de 100644 --- a/idhub/templates/idhub/admin_people_register.html +++ b/idhub/templates/idhub/admin_people_register.html @@ -2,4 +2,31 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

+{% load django_bootstrap5 %} + +{% csrf_token %} +{% if form.errors %} + +{% endif %} +{% bootstrap_form form %} + + + {% endblock %} diff --git a/idhub/templates/idhub/admin_revoke_credentials.html b/idhub/templates/idhub/admin_revoke_credentials.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_revoke_credentials.html +++ b/idhub/templates/idhub/admin_revoke_credentials.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_roles.html b/idhub/templates/idhub/admin_roles.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_roles.html +++ b/idhub/templates/idhub/admin_roles.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_schemes.html b/idhub/templates/idhub/admin_schemes.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_schemes.html +++ b/idhub/templates/idhub/admin_schemes.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_schemes_export.html b/idhub/templates/idhub/admin_schemes_export.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_schemes_export.html +++ b/idhub/templates/idhub/admin_schemes_export.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_schemes_import.html b/idhub/templates/idhub/admin_schemes_import.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_schemes_import.html +++ b/idhub/templates/idhub/admin_schemes_import.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_services.html b/idhub/templates/idhub/admin_services.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_services.html +++ b/idhub/templates/idhub/admin_services.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_user_edit.html b/idhub/templates/idhub/admin_user_edit.html new file mode 100644 index 0000000..a48b4de --- /dev/null +++ b/idhub/templates/idhub/admin_user_edit.html @@ -0,0 +1,32 @@ +{% extends "idhub/base_admin.html" %} +{% load i18n %} + +{% block content %} +

+ + {{ subtitle }} +

+{% load django_bootstrap5 %} + +{% csrf_token %} +{% if form.errors %} + +{% endif %} +{% bootstrap_form form %} + + + +{% endblock %} diff --git a/idhub/templates/idhub/admin_wallet_credentials.html b/idhub/templates/idhub/admin_wallet_credentials.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_wallet_credentials.html +++ b/idhub/templates/idhub/admin_wallet_credentials.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_wallet_identities.html b/idhub/templates/idhub/admin_wallet_identities.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_wallet_identities.html +++ b/idhub/templates/idhub/admin_wallet_identities.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/admin_wallet_issues.html b/idhub/templates/idhub/admin_wallet_issues.html index db4eecd..f5849fd 100644 --- a/idhub/templates/idhub/admin_wallet_issues.html +++ b/idhub/templates/idhub/admin_wallet_issues.html @@ -2,4 +2,8 @@ {% load i18n %} {% block content %} +

+ + {{ subtitle }} +

{% endblock %} diff --git a/idhub/templates/idhub/base_admin.html b/idhub/templates/idhub/base_admin.html index a90b0c7..bbb9251 100644 --- a/idhub/templates/idhub/base_admin.html +++ b/idhub/templates/idhub/base_admin.html @@ -216,10 +216,6 @@ -

- - {{ subtitle }} -

{% block content %} {% endblock content %} diff --git a/idhub/urls.py b/idhub/urls.py index c302824..326790c 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -56,7 +56,7 @@ urlpatterns = [ name='admin_people_list'), path('admin/people/', views_admin.AdminPeopleView.as_view(), name='admin_people'), - path('admin/people//edit', views_admin.AdminPeopleView.as_view(), + path('admin/people//edit', views_admin.AdminPeopleEditView.as_view(), name='admin_people_edit'), path('admin/people//del', views_admin.AdminPeopleDeleteView.as_view(), name='admin_people_delete'),