add roles management
This commit is contained in:
parent
021410e316
commit
b4074005b4
|
@ -14,3 +14,7 @@ class ProfileForm(forms.ModelForm):
|
|||
class MembershipForm(forms.ModelForm):
|
||||
MANDATORY_FIELDS = ['type']
|
||||
|
||||
|
||||
class RolForm(forms.ModelForm):
|
||||
MANDATORY_FIELDS = ['name']
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
{% extends "idhub/base_admin.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h3>
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
{% bootstrap_form form %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'idhub:admin_roles' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -6,4 +6,31 @@
|
|||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
<div class="row mt-5">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Rol' %}</button></th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rol in roles.all %}
|
||||
<tr>
|
||||
<td>{{ rol.name }}</td>
|
||||
<td><a href="{% url 'idhub:admin_rol_edit' rol.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
|
||||
<td><a href="{% url 'idhub:admin_rol_del' rol.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-green-admin" href="{% url 'idhub:admin_rol_new' %}">{% translate "Add Rol" %} <i class="bi bi-plus"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -72,6 +72,12 @@ urlpatterns = [
|
|||
name='admin_people_membership_del'),
|
||||
path('admin/roles/', views_admin.AdminRolesView.as_view(),
|
||||
name='admin_roles'),
|
||||
path('admin/roles/new', views_admin.AdminRolRegisterView.as_view(),
|
||||
name='admin_rol_new'),
|
||||
path('admin/roles/<int:pk>', views_admin.AdminRolEditView.as_view(),
|
||||
name='admin_rol_edit'),
|
||||
path('admin/roles/<int:pk>/del', views_admin.AdminRolDeleteView.as_view(),
|
||||
name='admin_rol_del'),
|
||||
path('admin/services/', views_admin.AdminServicesView.as_view(),
|
||||
name='admin_services'),
|
||||
path('admin/credentials/', views_admin.AdminCredentialsView.as_view(),
|
||||
|
|
Loading…
Reference in New Issue