add admin view user

This commit is contained in:
Cayo Puigdefabregas 2023-10-11 18:08:20 +02:00
parent 6491760abc
commit 39b8ab53bc
5 changed files with 29 additions and 6 deletions

View File

@ -3,6 +3,7 @@ import logging
from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from django.contrib import messages
from idhub.mixins import AdminView
@ -40,7 +41,7 @@ class ImportExport(AdminView, TemplateView):
section = "ImportExport"
class AdminPeopleView(People):
class AdminPeopleListView(People):
template_name = "idhub/admin_people.html"
subtitle = _('People list')
icon = 'bi bi-person'
@ -52,6 +53,26 @@ class AdminPeopleView(People):
})
return context
class AdminPeopleView(People):
template_name = "idhub/admin_user.html"
subtitle = _('User Profile')
icon = 'bi bi-person'
model = User
def get(self, request, *args, **kwargs):
self.pk = kwargs['pk']
self.object = get_object_or_404(self.model, pk=self.pk)
return super().get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'object': self.object,
})
return context
class AdminPeopleRegisterView(People):
template_name = "idhub/admin_people_register.html"
subtitle = _('People Register')

View File

@ -25,9 +25,9 @@ class UserView(LoginRequiredMixin):
class AdminView(UserView):
def get(self, request):
def get(self, request, *args, **kwargs):
if not request.user.is_superuser:
url = reverse_lazy('idhub:user_dashboard')
return redirect(url)
return super().get(request)
return super().get(request, *args, **kwargs)

View File

@ -22,7 +22,7 @@
<td>{{ user.username }}</td>
<td>{{ user.get_membership }}</td>
<td>{{ user.get_role }}</td>
<td><a type="button" class="btn btn-green-admin rounded-pill" href="{# url 'admin.profile.edit', user.id #}">{% trans 'View' %}</td>
<td><a type="button" class="btn btn-green-admin rounded-pill" href="{% url 'idhub:admin_people' user.id %}">{% trans 'View' %}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -77,7 +77,7 @@
</a>
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="people" data-bs-parent="#sidebarMenu">
<li class="nav-item">
<a class="nav-link{% if path == 'admin_people' %} active2{% endif %}" href="{% url 'idhub:admin_people' %}">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'idhub:admin_people_list' %}">
People list
</a>
</li>

View File

@ -52,7 +52,9 @@ urlpatterns = [
# Admin
path('admin/dashboard/', views_admin.AdminDashboardView.as_view(),
name='admin_dashboard'),
path('admin/people/', views_admin.AdminPeopleView.as_view(),
path('admin/people/', views_admin.AdminPeopleListView.as_view(),
name='admin_people_list'),
path('admin/people/<int:pk>', views_admin.AdminPeopleView.as_view(),
name='admin_people'),
path('admin/people/new/', views_admin.AdminPeopleRegisterView.as_view(),
name='admin_people_new'),