Vues de suppression

On rajoute un bouton de suppression d'un compte utilisable avec la perm
`kfet.delete_account`, avec message de vérif. On en profite pour
cleanup un peu le css de `jconfirm`.
This commit is contained in:
Ludovic Stephan 2019-05-24 14:30:00 +02:00
parent 63fff6ca7c
commit 08ac0ac890
5 changed files with 84 additions and 4 deletions

View file

@ -57,12 +57,20 @@ aside .heading .sub {
aside .buttons { aside .buttons {
margin-left: -15px; margin-left: -15px;
margin-right: -15px; margin-right: -15px;
flex-wrap: wrap;
} }
aside .buttons > * { aside .buttons > * {
flex: 0 1 auto !important; flex: 0 1 auto !important;
} }
aside .buttons > hr {
flex-basis: 100%;
height: 0;
margin: 0;
border: 0;
}
/* Aside - Text */ /* Aside - Text */

View file

@ -23,11 +23,19 @@
} }
.jconfirm .jconfirm-box .content-pane { .jconfirm .jconfirm-box .content-pane {
margin:0 !important; border-bottom:1px solid #ddd;
margin: 0px !important;
} }
.jconfirm .jconfirm-box .content { .jconfirm .jconfirm-box .content {
border-bottom:1px solid #ddd; padding: 5px;
}
.jconfirm .jconfirm-box .content div.warning {
font-size: 16px;
font-weight: bold;
text-align: center;
margin: 5px 0px;
} }
.jconfirm .jconfirm-box input { .jconfirm .jconfirm-box input {
@ -43,7 +51,7 @@
} }
.jconfirm .jconfirm-box .buttons { .jconfirm .jconfirm-box .buttons {
margin-top:-5px; /* j'arrive pas à voir pk y'a un espace au dessus sinon... */ margin-top:-6px; /* j'arrive pas à voir pk y'a un espace au dessus sinon... */
padding:0; padding:0;
height:40px; height:40px;
} }

View file

@ -18,6 +18,15 @@
<a class="btn btn-default" disabled> <a class="btn btn-default" disabled>
<span class="glyphicon glyphicon-credit-card"></span><span>Créditer</span> <span class="glyphicon glyphicon-credit-card"></span><span>Créditer</span>
</a> </a>
{% if perms.kfet.delete_account %}
<hr>
<button class="btn btn-default" id="button-delete">
<span class="glyphicon glyphicon-remove"></span><span>Supprimer</span>
</button>
<form method="post" action="{% url 'kfet.account.delete' account.trigramme %}" id="account-delete-form">
{% csrf_token %}
</form>
{% endif %}
</div> </div>
<div class="text"> <div class="text">
@ -92,5 +101,24 @@ $( function() {
$(this).addClass('focus'); $(this).addClass('focus');
}); });
// Delete button
$('#button-delete').click(function() {
$.confirm({
title: 'Confirmer la suppression',
content: `
<div class="warning">
<span class='glyphicon glyphicon-warning-sign'></span><span>Cette opération est irréversible !</span>
</div>
<span>Toutes les données associées à ce compte seront anonymisées.</span>
`,
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
confirm: function() {
$('#account-delete-form').submit();
}
})
})
}); });
</script> </script>

View file

@ -57,6 +57,12 @@ urlpatterns = [
views.account_update, views.account_update,
name="kfet.account.update", name="kfet.account.update",
), ),
# Account - Delete
path(
"accounts/<trigramme:trigramme>/delete",
views.AccountDeleteView.as_view(),
name="kfet.account.delete",
),
# Account - Groups # Account - Groups
path("accounts/groups", views.account_group, name="kfet.account.group"), path("accounts/groups", views.account_group, name="kfet.account.group"),
path( path(

View file

@ -7,6 +7,7 @@ from urllib.parse import urlencode
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.models import Permission, User from django.contrib.auth.models import Permission, User
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -20,7 +21,7 @@ from django.utils import timezone
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.generic import DetailView, FormView, ListView, TemplateView from django.views.generic import DetailView, FormView, ListView, TemplateView
from django.views.generic.detail import BaseDetailView from django.views.generic.detail import BaseDetailView
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, DeleteView, UpdateView
from gestioncof.models import CofProfile from gestioncof.models import CofProfile
from kfet import consumers from kfet import consumers
@ -467,6 +468,35 @@ def account_update(request, trigramme):
}, },
) )
# Account - Delete
class AccountDeleteView(PermissionRequiredMixin, DeleteView):
model = Account
slug_field = "trigramme"
slug_url_kwarg = "trigramme"
success_url = reverse_lazy("kfet.account")
success_message = "Compte supprimé avec succès !"
permission_required = "kfet.delete_account"
def get(self, request, *args, **kwargs):
return redirect("kfet.account.read", self.kwargs.get(self.get_slug_field()))
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
if self.object.balance > 0.01:
messages.error(
request,
"Impossible de supprimer un compte "
"avec une balance strictement positive !",
)
return redirect("kfet.account.read", self.object.trigramme)
# SuccessMessageMixin does not work with DeleteView, see :
# https://code.djangoproject.com/ticket/21926
messages.success(request, self.success_message)
return super().delete(request, *args, **kwargs)
class AccountNegativeList(ListView): class AccountNegativeList(ListView):
queryset = AccountNegative.objects.select_related( queryset = AccountNegative.objects.select_related(