Login

Email on new comments

Author:
ubernostrum
Posted:
August 15, 2007
Language:
Python
Version:
.96
Tags:
email comments
Score:
4 (after 4 ratings)

In response to #366, this is a subclass of the CommentModerator class from comment_utils which does nothing except email the "owner" of an object whenever a new comment is posted on it; all other moderation options remain inactive.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.contrib.sites.models import Site
from django.template import Context, loader
from comment_utils.moderation import CommentModerator

class EmailOwner(CommentModerator):
    """                                                                                                                                                                                                   
    Subclass of ``CommentModerator`` which emails the "owner" of an                                                                                                                                       
    object whenever a new comment is posted on it.                                                                                                                                                        
                                                                                                                                                                                                          
    Assumes that the 'owner' is specified by a ``ForeignKey`` named                                                                                                                                       
    'user'; edit that if your field is named something else.                                                                                                                                              
                                                                                                                                                                                                          
    """
    email_notification = True

    def email(self, comment, content_object):
        t = loader.get_template('comment_email_owner.txt')
        c = Context({ 'comment': comment,
                      'content_object': content_object })
        subject = '[%s] New comment posted on "%s"' % (Site.objects.get_current().name,
                                                       content_object)
        message = t.render(c)
        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                  [content_object.user.email], fail_silently=True)

More like this

  1. Email on new comments by nikolaj 7 years, 9 months ago
  2. Signal to notify new saved comments by arthurfurlan 5 years, 11 months ago
  3. Reset / Send account details email by Ciantic 4 years, 9 months ago
  4. New forms signup validation by Batiste 8 years, 1 month ago
  5. MultipleEmailsField by spanasik 6 years ago

Comments

nikolaj (on August 15, 2007):

What is this polymorphism you speak of? :)

#

Please login first before commenting.