Ticket #21936: 0001-Add-deletemessagemixin.patch

File 0001-Add-deletemessagemixin.patch, 1.2 KB (added by david.fischer.ch@…, 13 months ago)

The patch for this contribution

  • django/contrib/messages/views.py

    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): 
    1818        if hasattr(self, 'object'):
    1919            cleaned_data['object'] = self.object
    2020        return self.success_message % cleaned_data
     21
     22
     23class 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)
Back to Top