admin: add basic user admin
This commit is contained in:
parent
196be4b3b0
commit
25fbadc813
|
@ -23,8 +23,8 @@
|
|||
<li class="{% is_active 'passbook_admin:invitations' 'passbook_admin:invitation-create' 'passbook_admin:invitation-update' 'passbook_admin:invitation-delete' 'passbook_admin:invitation-test' %}">
|
||||
<a href="{% url 'passbook_admin:invitations' %}">{% trans 'Invitations' %}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#">{% trans 'Users' %}</a>
|
||||
<li class="{% is_active 'passbook_admin:users' 'passbook_admin:user-update' 'passbook_admin:user-delete' %}">
|
||||
<a href="{% url 'passbook_admin:users' %}">{% trans 'Users' %}</a>
|
||||
</li>
|
||||
<li class="{% is_active 'passbook_admin:audit-log' %}">
|
||||
<a href="{% url 'passbook_admin:audit-log' %}">{% trans 'Audit Log' %}</a>
|
||||
|
|
38
passbook/admin/templates/administration/user/list.html
Normal file
38
passbook/admin/templates/administration/user/list.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
{% extends "administration/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load utils %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1>{% trans "Users" %}</h1>
|
||||
<hr>
|
||||
<table class="table table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans 'Username' %}</th>
|
||||
<th>{% trans 'First Name' %}</th>
|
||||
<th>{% trans 'Last Name' %}</th>
|
||||
<th>{% trans 'Active' %}</th>
|
||||
<th>{% trans 'Last Login' %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in object_list %}
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>{{ user.first_name|default:'-' }}</td>
|
||||
<td>{{ user.last_name|default:'-' }}</td>
|
||||
<td>{{ user.is_active }}</td>
|
||||
<td>{{ user.last_login }}</td>
|
||||
<td>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:user-update' pk=user.pk %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:user-delete' pk=user.pk %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -2,7 +2,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from passbook.admin.views import (applications, audit, invitations, overview,
|
||||
providers, rules, sources)
|
||||
providers, rules, sources, users)
|
||||
|
||||
urlpatterns = [
|
||||
path('', overview.AdministrationOverviewView.as_view(), name='overview'),
|
||||
|
@ -40,6 +40,13 @@ urlpatterns = [
|
|||
invitations.InvitationCreateView.as_view(), name='invitation-create'),
|
||||
path('invitations/<uuid:pk>/delete/',
|
||||
invitations.InvitationDeleteView.as_view(), name='invitation-delete'),
|
||||
# Users
|
||||
path('users/', users.UserListView.as_view(),
|
||||
name='users'),
|
||||
path('users/<int:pk>/update/',
|
||||
users.UserUpdateView.as_view(), name='user-update'),
|
||||
path('users/<int:pk>/delete/',
|
||||
users.UserDeleteView.as_view(), name='user-delete'),
|
||||
# Audit Log
|
||||
path('audit/', audit.AuditEntryListView.as_view(), name='audit-log'),
|
||||
# path('api/v1/', include('passbook.admin.api.v1.urls'))
|
||||
|
|
38
passbook/admin/views/users.py
Normal file
38
passbook/admin/views/users.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""passbook User administration"""
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import DeleteView, ListView, TemplateView, UpdateView
|
||||
|
||||
from passbook.admin.mixins import AdminRequiredMixin
|
||||
from passbook.core.forms.user import UserDetailForm
|
||||
from passbook.core.models import User
|
||||
|
||||
|
||||
class UserListView(AdminRequiredMixin, ListView):
|
||||
"""Show list of all users"""
|
||||
|
||||
model = User
|
||||
template_name = 'administration/user/list.html'
|
||||
|
||||
|
||||
class UserUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView):
|
||||
"""Update user"""
|
||||
|
||||
model = User
|
||||
form_class = UserDetailForm
|
||||
|
||||
template_name = 'generic/update.html'
|
||||
success_url = reverse_lazy('passbook_admin:users')
|
||||
success_message = _('Successfully updated User')
|
||||
|
||||
|
||||
class UserDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView):
|
||||
"""Delete user"""
|
||||
|
||||
model = User
|
||||
|
||||
success_url = reverse_lazy('passbook_admin:users')
|
||||
success_message = _('Successfully updated User')
|
||||
|
Reference in a new issue