From 57003f0ef22c76543cf8277c5af8954d42e7f07e Mon Sep 17 00:00:00 2001
From: David Fischer <david.fischer.ch@gmail.com>
Date: Wed, 30 Oct 2013 15:47:39 +0100
Subject: [PATCH] Add delete message mixin
---
django/contrib/messages/views.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/django/contrib/messages/views.py b/django/contrib/messages/views.py
index a0e3bd6..1de732c 100644
a
|
b
|
class SuccessMessageMixin(object):
|
18 | 18 | if hasattr(self, 'object'): |
19 | 19 | cleaned_data['object'] = self.object |
20 | 20 | return self.success_message % cleaned_data |
| 21 | |
| 22 | |
| 23 | class DeleteMessageMixin(object): |
| 24 | """ |
| 25 | Adds a delete message on successful object deletion. |
| 26 | """ |
| 27 | delete_message = '' |
| 28 | |
| 29 | def get_delete_message(self): |
| 30 | return self.delete_message % {'object': self.get_object()} |
| 31 | |
| 32 | def delete(self, request, *args, **kwargs): |
| 33 | delete_message = self.get_delete_message() |
| 34 | if delete_message: |
| 35 | messages.success(request, delete_message) |
| 36 | return super(DeleteMessageMixin, self).delete(request, *args, **kwargs) |