Commits

David Chambers committed 4b3abbf

Added support for comment moderation.

Comments (0)

Files changed (2)

 from django.http import HttpResponsePermanentRedirect
 from mango.feeds import atom
 from mango.settings import CONTACT_FORM, PATH_TO_STATIC, TAGS_PAGE
-from mango.views import archives, contact, index, post, redirect, tagged_as, tags
+from mango.views import archives, contact, index, moderate, post, redirect, tagged_as, tags
 
 urlpatterns = patterns('')
 
     (r'^feed/$', atom),
     (r'^archive/$', lambda request: HttpResponsePermanentRedirect('/archives/')),
     (r'^archives/$', archives),
+    (r'^moderate/(approve|delete|spam)$', moderate),
     (r'^(.+?)/redirect/$', redirect),
     (r'^(.+?)/comment/$', post),
     (r'^(.+?)/(m/)?$', post),
 # -*- coding: utf-8 -*-
 
 import datetime
+import hashlib
 import os
 import re
 
 from mango.templatetags.mango_extras import slugify
 from mango.utils import RE
 
+MESSAGES = {
+    'approve': {'do': 'Approve comment', 'done': 'Comment approved.'},
+    'delete': {'do': 'Delete comment', 'done': 'Comment deleted.'},
+    'spam': {'do': 'Mark comment as spam', 'done': 'Comment marked as spam.'},
+}
+
 def redirect(request, path):
     return HttpResponseRedirect('/%s/' % path)
 
         form = ContactForm()
 
     return render_to_response('contact.dhtml', dict({'form': form}, **context_defaults(request)))
+
+def moderate(request, action):
+    if request.GET.get('api_key') != hashlib.sha1(DISQUS['api_key']).hexdigest():
+        return HttpResponseBadRequest('Invalid API key.')
+
+    dsq = disqus.DisqusService(DISQUS_API_VERSION)
+    dsq.login(DISQUS['api_key'])
+    dsq.moderate_post(request.GET.get('post_id'), 'kill' if action == 'delete' else action)
+    return HttpResponse(MESSAGES[action]['done'], content_type='text/plain; charset=utf-8')