From 3b70a6c7cc93ba900fc94ba89847bf585a0e51e0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Oct 2024 17:04:33 +0200 Subject: [PATCH 1/3] add form for edit institution details --- admin/templates/admin_panel.html | 7 +++++++ admin/urls.py | 1 + admin/views.py | 23 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/admin/templates/admin_panel.html b/admin/templates/admin_panel.html index 6d3bd14..3dd5ed1 100644 --- a/admin/templates/admin_panel.html +++ b/admin/templates/admin_panel.html @@ -8,5 +8,12 @@ +
+ +
{% endblock %} diff --git a/admin/urls.py b/admin/urls.py index cd79c3f..9a26cbf 100644 --- a/admin/urls.py +++ b/admin/urls.py @@ -9,4 +9,5 @@ urlpatterns = [ path("users/new", views.CreateUserView.as_view(), name="new_user"), path("users/edit/", views.EditUserView.as_view(), name="edit_user"), path("users/delete/", views.DeleteUserView.as_view(), name="delete_user"), + path("institution/", views.InstitutionView.as_view(), name="institution"), ] diff --git a/admin/views.py b/admin/views.py index bcc8889..1ba392f 100644 --- a/admin/views.py +++ b/admin/views.py @@ -8,7 +8,7 @@ from django.views.generic.edit import ( DeleteView, ) from dashboard.mixins import DashboardView -from user.models import User +from user.models import User, Institution class PanelView(DashboardView, TemplateView): @@ -87,3 +87,24 @@ class EditUserView(DashboardView, UpdateView): #self.object.set_password(self.object.password) kwargs = super().get_form_kwargs() return kwargs + + +class InstitutionView(DashboardView, UpdateView): + template_name = "institution.html" + title = _("Edit institution") + section = "admin" + subtitle = _('Edit institution') + model = Institution + success_url = reverse_lazy('admin:panel') + fields = ( + "name", + "logo", + "location", + "responsable_person", + "supervisor_person" + ) + + def get_form_kwargs(self): + self.object = self.request.user.institution + kwargs = super().get_form_kwargs() + return kwargs From 59d99fa43439694c98548fb0cb5c8bed18357996 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Oct 2024 17:04:47 +0200 Subject: [PATCH 2/3] add form for edit institution details with template --- admin/templates/institution.html | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 admin/templates/institution.html diff --git a/admin/templates/institution.html b/admin/templates/institution.html new file mode 100644 index 0000000..88014b9 --- /dev/null +++ b/admin/templates/institution.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block content %} +
+
+

{{ subtitle }}

+
+
+ +{% load django_bootstrap5 %} +
+{% csrf_token %} +{% if form.errors %} + +{% endif %} +{% bootstrap_form form %} + + +
+{% endblock %} From 0c36e12da6b83019e5f3c3647490ede77b5b4f6f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Oct 2024 17:15:37 +0200 Subject: [PATCH 3/3] only admin users can see admin pages --- admin/views.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/admin/views.py b/admin/views.py index 1ba392f..14627cb 100644 --- a/admin/views.py +++ b/admin/views.py @@ -7,11 +7,19 @@ from django.views.generic.edit import ( UpdateView, DeleteView, ) -from dashboard.mixins import DashboardView +from dashboard.mixins import DashboardView, Http403 from user.models import User, Institution -class PanelView(DashboardView, TemplateView): +class AdminView(DashboardView): + def get(self, *args, **kwargs): + response = super().get(*args, **kwargs) + if not self.request.user.is_admin: + raise Http403 + + return response + +class PanelView(AdminView, TemplateView): template_name = "admin_panel.html" title = _("Admin") breadcrumb = _("admin") + " /" @@ -21,7 +29,7 @@ class PanelView(DashboardView, TemplateView): return context -class UsersView(DashboardView, TemplateView): +class UsersView(AdminView, TemplateView): template_name = "admin_users.html" title = _("Users") breadcrumb = _("admin / Users") + " /" @@ -34,7 +42,7 @@ class UsersView(DashboardView, TemplateView): return context -class CreateUserView(DashboardView, CreateView): +class CreateUserView(AdminView, CreateView): template_name = "user.html" title = _("User") breadcrumb = _("admin / User") + " /" @@ -53,7 +61,7 @@ class CreateUserView(DashboardView, CreateView): return response -class DeleteUserView(DashboardView, DeleteView): +class DeleteUserView(AdminView, DeleteView): template_name = "delete_user.html" title = _("Delete user") breadcrumb = "admin / Delete user" @@ -70,7 +78,7 @@ class DeleteUserView(DashboardView, DeleteView): return response -class EditUserView(DashboardView, UpdateView): +class EditUserView(AdminView, UpdateView): template_name = "user.html" title = _("Edit user") breadcrumb = "admin / Edit user" @@ -89,7 +97,7 @@ class EditUserView(DashboardView, UpdateView): return kwargs -class InstitutionView(DashboardView, UpdateView): +class InstitutionView(AdminView, UpdateView): template_name = "institution.html" title = _("Edit institution") section = "admin"