Sign up to create your own snipts, or login.

Public snipts » patrickbeeson's snipts » Code to use Akismet in Django blog that also emails the comment to the admin if it's set to is_public.

posted on Feb 21, 2009 at 11:02 a.m. EST in 
  • 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)
    

    copy | embed

2 Comments

on May 19, 2010 at 12:25 a.m. EDT
As time has progressed, computers have made giant leaps in the area of processing power. This has brought about newer programming languages that are more abstracted from the underlying hardware. Although these high-level languages usually incur greater overhead,<a href="http://www.icndexams.com">icnd</a> the increase in speed of modern computers has made the use of these languages much more practical than in the past
on May 19, 2010 at 12:26 a.m. EDT
As time has progressed, computers have made giant leaps in the area of processing power. This has brought about newer programming languages that are more abstracted from the underlying hardware. Although these high-level languages usually incur greater overhead,[url=http://www.icndexams.com]icnd[/url] the increase in speed of modern computers has made the use of these languages much more practical than in the past
Sign up, or login to leave a comment.