Latest 100 public snipts »
patrickbeeson's
snipts » email
showing 1-1 of 1 snipts for email
-
∞ Code to use Akismet in Django blog that also emails the comment to the admin if it's set to is_public.
from django.contrib.comments.signals import comment_was_posted from django.utils.encoding import smart_str from django.core.mail import mail_managers import akismet from django.conf import settings from django.contrib.sites.models import Site ... def moderate_comment(sender, comment, request, **kwargs): ak = akismet.Akismet( key = settings.AKISMET_API_KEY, blog_url = 'http://%s/' % Site.objects.get_current().domain ) data = { 'user_ip': request.META.get('REMOTE_ADDR', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', ''), 'referrer': request.META.get('HTTP_REFERRER', ''), 'comment_type': 'comment', 'comment_author': smart_str(comment.user_name), } if ak.comment_check(smart_str(comment.comment), data=data, build_data=True): comment.is_public = False comment.save() if comment.is_public: email_body = "%s" mail_managers ("New comment posted", email_body % (comment.get_as_text())) comment_was_posted.connect(moderate_comment)


