Send notification emails on deletes
authorMagnus Hagander <magnus@hagander.net>
Tue, 20 Dec 2011 12:55:33 +0000 (13:55 +0100)
committerMagnus Hagander <magnus@hagander.net>
Tue, 20 Dec 2011 12:56:53 +0000 (13:56 +0100)
There are no signals for them, but it appears to work to just override
the delete() method in PgModel.

Fixes #121

pgweb/util/bases.py

index c4573e7dac1ed32b3e47a0e711b72ff3385782d8..ec2fa9610a31b83df1202315d26a4c70ec08af54 100644 (file)
@@ -53,6 +53,24 @@ class PgModel(object):
                else:
                        sendmail(msg)
 
+       def delete(self):
+               # We can't compare the object, but we should be able to construct something anyway
+               if self.send_notification:
+                       subject = "%s id %s has been deleted by %s" % (
+                               self._meta.verbose_name,
+                               self.id,
+                               get_current_user())
+                       msg = MIMEText(self.full_text_representation(), _charset='utf-8')
+                       msg['Subject'] = subject
+                       msg['To'] = settings.NOTIFICATION_EMAIL
+                       msg['From'] = settings.NOTIFICATION_FROM
+                       if hasattr(settings,'SUPPRESS_NOTIFICATIONS') and settings.SUPPRESS_NOTIFICATIONS:
+                               print msg.as_string()
+                       else:
+                               sendmail(msg)
+
+               # Now call our super to actually delete the object
+               super(PgModel, self).delete()
                
        def _get_changes_texts(self):
                try: