- Author:
- ubernostrum
- Posted:
- August 15, 2007
- Language:
- Python
- Version:
- .96
- 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
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
What is this polymorphism you speak of? :)
#
Please login first before commenting.