diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 3e2a1f0..d96dcbc 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -14,3 +14,7 @@ class ProfileForm(forms.ModelForm): class MembershipForm(forms.ModelForm): MANDATORY_FIELDS = ['type'] + +class RolForm(forms.ModelForm): + MANDATORY_FIELDS = ['name'] + diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 05cc8b3..7e54d5d 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -7,9 +7,9 @@ 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.models import Membership +from idhub.models import Membership, Rol from idhub.mixins import AdminView -from idhub.admin.forms import ProfileForm, MembershipForm +from idhub.admin.forms import ProfileForm, MembershipForm, RolForm class AdminDashboardView(AdminView, TemplateView): @@ -214,6 +214,76 @@ class AdminRolesView(AccessControl): subtitle = _('Roles Management') icon = '' + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update({ + 'roles': Rol.objects, + }) + return context + +class AdminRolRegisterView(AccessControl, CreateView): + template_name = "idhub/admin_rol_register.html" + subtitle = _('Add Rol') + icon = 'bi bi-person' + model = Rol + from_class = RolForm + fields = ('name',) + success_url = reverse_lazy('idhub:admin_roles') + object = None + +# class AdminPeopleMembershipRegisterView(People, CreateView): + # template_name = "idhub/admin_people_membership_register.html" + + # def get(self, request, *args, **kwargs): + # self.pk = kwargs['pk'] + # self.user = get_object_or_404(User, pk=self.pk) + # return super().get(request, *args, **kwargs) + + # def post(self, request, *args, **kwargs): + # self.pk = kwargs['pk'] + # self.user = get_object_or_404(User, pk=self.pk) + # return super().post(request, *args, **kwargs) + + # def get_form(self): + # form = super().get_form() + # form.fields['start_date'].widget.input_type = 'date' + # form.fields['end_date'].widget.input_type = 'date' + # return form + + # def get_form_kwargs(self): + # self.object = self.model(user=self.user) + # kwargs = super().get_form_kwargs() + # return kwargs + + +class AdminRolEditView(AccessControl, CreateView): + template_name = "idhub/admin_rol_register.html" + subtitle = _('Add Rol') + icon = 'bi bi-person' + model = Rol + from_class = RolForm + fields = ('name',) + success_url = reverse_lazy('idhub:admin_roles') + + def get_form_kwargs(self): + pk = self.kwargs.get('pk') + if pk: + self.object = get_object_or_404(self.model, pk=pk) + kwargs = super().get_form_kwargs() + return kwargs + + +class AdminRolDeleteView(AccessControl): + model = Rol + + def get(self, request, *args, **kwargs): + self.pk = kwargs['pk'] + self.object = get_object_or_404(self.model, pk=self.pk) + + self.object.delete() + return redirect('idhub:admin_roles') + + class AdminServicesView(AccessControl): template_name = "idhub/admin_services.html" diff --git a/idhub/models.py b/idhub/models.py index ba5d953..1c5091b 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -80,3 +80,7 @@ class Membership(models.Model): def get_type(self): return dict(self.Types.choices).get(self.type) + + +class Rol(models.Model): + name = models.CharField(max_length=250) diff --git a/idhub/templates/idhub/admin_rol_register.html b/idhub/templates/idhub/admin_rol_register.html new file mode 100644 index 0000000..8c591bc --- /dev/null +++ b/idhub/templates/idhub/admin_rol_register.html @@ -0,0 +1,34 @@ +{% extends "idhub/base_admin.html" %} +{% load i18n %} + +{% block content %} +