From 28da67abe6d7b5469a3b6f076ce337c164ff3018 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 26 Feb 2019 09:46:44 +0100 Subject: [PATCH] Improve partially broken Delete Views, show success message on deletion --- passbook/admin/views/applications.py | 8 +++++- passbook/admin/views/factors.py | 7 +++++- passbook/admin/views/invitations.py | 7 +++++- passbook/admin/views/policy.py | 6 ++++- passbook/admin/views/providers.py | 7 +++++- passbook/admin/views/sources.py | 9 +++++-- passbook/admin/views/users.py | 8 ++++-- passbook/core/templates/generic/delete.html | 28 ++++++++++++--------- 8 files changed, 59 insertions(+), 21 deletions(-) diff --git a/passbook/admin/views/applications.py b/passbook/admin/views/applications.py index e2059dba5..b6ba4ed4c 100644 --- a/passbook/admin/views/applications.py +++ b/passbook/admin/views/applications.py @@ -1,4 +1,5 @@ """passbook Application administration""" +from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.urls import reverse_lazy from django.utils.translation import ugettext as _ @@ -45,5 +46,10 @@ class ApplicationDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView) model = Application + template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:applications') - success_message = _('Successfully updated Application') + success_message = _('Successfully deleted Application') + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/admin/views/factors.py b/passbook/admin/views/factors.py index 07b2c3d4b..b43c97090 100644 --- a/passbook/admin/views/factors.py +++ b/passbook/admin/views/factors.py @@ -1,4 +1,5 @@ """passbook Factor administration""" +from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.http import Http404 from django.urls import reverse_lazy @@ -73,7 +74,11 @@ class FactorDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): model = Factor template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:factors') - success_message = _('Successfully updated Factor') + success_message = _('Successfully deleted Factor') def get_object(self, queryset=None): return Factor.objects.filter(pk=self.kwargs.get('pk')).select_subclasses().first() + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/admin/views/invitations.py b/passbook/admin/views/invitations.py index 2680cb236..1b957e23b 100644 --- a/passbook/admin/views/invitations.py +++ b/passbook/admin/views/invitations.py @@ -1,4 +1,5 @@ """passbook Invitation administration""" +from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.http import HttpResponseRedirect from django.urls import reverse_lazy @@ -42,4 +43,8 @@ class InvitationDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): model = Invitation template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:invitations') - success_message = _('Successfully updated Invitation') + success_message = _('Successfully deleted Invitation') + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/admin/views/policy.py b/passbook/admin/views/policy.py index 371b75ce3..2760ff032 100644 --- a/passbook/admin/views/policy.py +++ b/passbook/admin/views/policy.py @@ -68,11 +68,15 @@ class PolicyDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): model = Policy template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:policies') - success_message = _('Successfully updated Policy') + success_message = _('Successfully deleted Policy') def get_object(self, queryset=None): return Policy.objects.filter(pk=self.kwargs.get('pk')).select_subclasses().first() + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) + class PolicyTestView(AdminRequiredMixin, DetailView, FormView): """View to test policy(s)""" diff --git a/passbook/admin/views/providers.py b/passbook/admin/views/providers.py index f093755c7..7986489b9 100644 --- a/passbook/admin/views/providers.py +++ b/passbook/admin/views/providers.py @@ -1,4 +1,5 @@ """passbook Provider administration""" +from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.http import Http404 from django.urls import reverse_lazy @@ -64,7 +65,11 @@ class ProviderDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): model = Provider template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:providers') - success_message = _('Successfully updated Provider') + success_message = _('Successfully deleted Provider') def get_object(self, queryset=None): return Provider.objects.filter(pk=self.kwargs.get('pk')).select_subclasses().first() + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/admin/views/sources.py b/passbook/admin/views/sources.py index 3c409f794..998c9e69b 100644 --- a/passbook/admin/views/sources.py +++ b/passbook/admin/views/sources.py @@ -1,4 +1,5 @@ """passbook Source administration""" +from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.http import Http404 from django.urls import reverse_lazy @@ -66,9 +67,13 @@ class SourceDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): """Delete source""" model = Source - + template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:sources') - success_message = _('Successfully updated Source') + success_message = _('Successfully deleted Source') def get_object(self, queryset=None): return Source.objects.filter(pk=self.kwargs.get('pk')).select_subclasses().first() + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/admin/views/users.py b/passbook/admin/views/users.py index a6bfc9e85..0140078c6 100644 --- a/passbook/admin/views/users.py +++ b/passbook/admin/views/users.py @@ -34,9 +34,13 @@ class UserDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): """Delete user""" model = User - + template_name = 'generic/delete.html' success_url = reverse_lazy('passbook_admin:users') - success_message = _('Successfully updated User') + success_message = _('Successfully deleted User') + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) class UserPasswordResetView(AdminRequiredMixin, View): diff --git a/passbook/core/templates/generic/delete.html b/passbook/core/templates/generic/delete.html index 948ac9817..19e570e32 100644 --- a/passbook/core/templates/generic/delete.html +++ b/passbook/core/templates/generic/delete.html @@ -5,16 +5,20 @@ {% block content %}
- {% block above_form %} -

{% trans 'Delete' %}

- {% endblock %} -
-
- {% csrf_token %} -

Are you sure you want to delete "{{ object }}"?

- {% trans 'Back' %} - -
-
+ {% block above_form %} +

{% blocktrans with object_type=object|fieldtype|title %}Delete {{ object_type }}{% endblocktrans %}

+ {% endblock %} +
+
+ {% csrf_token %} +

+ {% blocktrans with object_type=object|fieldtype|title name=object %} + Are you sure you want to delete {{ object_type }} "{{ object }}"? + {% endblocktrans %} +

+ {% trans 'Back' %} + +
+
-{% endblock %} \ No newline at end of file +{% endblock %}