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
- Email on new comments by nikolaj 5 years, 9 months ago
- Unobtrusive comment moderation by ubernostrum 6 years, 2 months ago
- LinkSleeve comment moderation by zgoda 5 years, 1 month ago
- Using manager methods by ubernostrum 6 years, 3 months ago
- View Permission Decorator Helper by jgeewax 4 years, 10 months ago
Comments
What is this polymorphism you speak of? :)
#