add deactivate user and delete user

This commit is contained in:
Cayo Puigdefabregas 2023-10-13 12:35:06 +02:00
parent 39b8ab53bc
commit e0cceda122
10 changed files with 127 additions and 58 deletions

View File

@ -3,7 +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.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy
from django.contrib import messages
from idhub.mixins import AdminView
@ -73,6 +73,32 @@ class AdminPeopleView(People):
return context
class AdminPeopleActivateView(AdminPeopleView):
def get(self, request, *args, **kwargs):
self.pk = kwargs['pk']
self.object = get_object_or_404(self.model, pk=self.pk)
if self.object.is_active:
self.object.is_active = False
else:
self.object.is_active = True
self.object.save()
return redirect('idhub:admin_people', self.object.id)
class AdminPeopleDeleteView(AdminPeopleView):
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_people_list')
class AdminPeopleRegisterView(People):
template_name = "idhub/admin_people_register.html"
subtitle = _('People Register')

View File

@ -165,3 +165,7 @@ h3 {
.btn-yellow {
background-color: #efe3b4;
}
.btn-orange {
background-color: #f5b587;
}

7
idhub/static/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,53 +0,0 @@
/* globals Chart:false, feather:false */
(function () {
'use strict'
feather.replace({ 'aria-hidden': 'true' })
// Graphs
var ctx = document.getElementById('myChart')
// eslint-disable-next-line no-unused-vars
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
],
datasets: [{
data: [
15339,
21345,
18483,
24003,
23489,
24092,
12034
],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
borderWidth: 4,
pointBackgroundColor: '#007bff'
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: false
}
}]
},
legend: {
display: false
}
}
})
})()

File diff suppressed because one or more lines are too long

6
idhub/static/js/popper.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,68 @@
{% extends "idhub/base_admin.html" %}
{% load i18n %}
{% block content %}
<div class="row">
<div class="col">
<h3 class="{% if not object.is_active %}bg-danger text-white{% endif %}">
<i class="{{ icon }}"></i>
{{ subtitle }}
</h3>
</div>
<div class="col">
<a href="{% url 'idhub:admin_people_edit' object.id %}" type="button" class="btn btn-green-admin">{% trans 'Modify' %}</a>
<a href="{% url 'idhub:admin_people_activate' object.id %}" type="button" class="btn btn-yellow ms-3 me-3">{% if object.is_active %}{% trans 'Deactivate' %}{% else %}{% trans 'Activate' %}{% endif %}</a>
<a href="#" type="button" class="btn btn-orange" data-bs-toggle="modal" data-bs-target="#confirm-delete">{% trans 'Delete' %}</a>
</div>
</div>
<div class="row">
<div class="col">
<div class="card mb-3">
<div class="card-body">
<div class="row border-bottom">
<div class="col-3">
First Name:
</div>
<div class="col-9 text-secondary">
{{ object.first_name }}
</div>
</div>
<div class="row border-bottom mt-3">
<div class="col-3">
Last Name:
</div>
<div class="col-9 text-secondary">
{{ object.last_name }}
</div>
</div>
<div class="row mt-3">
<div class="col-3">
Email:
</div>
<div class="col-9 text-secondary">
{{ object.email }}
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal" id="confirm-delete" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Delete user' %} {{ object.username }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% trans 'Are you sure that you want delete this user?' %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Clancel</button>
<a href="{% url 'idhub:admin_people_delete' object.id %}" type="button" class="btn btn-danger">{% trans 'Delete' %}</a>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -227,9 +227,11 @@
</div>
</div>
<script src="/static/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js" integrity="sha384-uO3SXW5IuS1ZpFPKugNNWqTZRRglnUJK6UAZ/gxOX80nxEkN9NcGZTftn6RzhGWE" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" integrity="sha384-zNy6FEbO50N+Cg5wap8IKA4M/ZnLJgzc6w2NqACZaK0u0FXfOWRRJOnQtpZun8ha" crossorigin="anonymous"></script>
<script src="/static/js/dashboard.js"></script>
{% block script %}
<script src="{% static "js/jquery-3.3.1.slim.min.js" %}"></script>
<script src="{% static "js/popper.min.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
{% block extrascript %}{% endblock %}
{% endblock %}
</body>
</html>

View File

@ -56,6 +56,12 @@ urlpatterns = [
name='admin_people_list'),
path('admin/people/<int:pk>', views_admin.AdminPeopleView.as_view(),
name='admin_people'),
path('admin/people/<int:pk>/edit', views_admin.AdminPeopleView.as_view(),
name='admin_people_edit'),
path('admin/people/<int:pk>/del', views_admin.AdminPeopleDeleteView.as_view(),
name='admin_people_delete'),
path('admin/people/<int:pk>/activate', views_admin.AdminPeopleActivateView.as_view(),
name='admin_people_activate'),
path('admin/people/new/', views_admin.AdminPeopleRegisterView.as_view(),
name='admin_people_new'),
path('admin/roles/', views_admin.AdminRolesView.as_view(),