]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/commands.py
OSQA - 19
[osqa.git] / forum / views / commands.py
index a55ac5670b01936639878ed9300f85aea562a1dd..d0599b330af754b83d9d49163c1a06fa320d3e9f 100644 (file)
@@ -41,6 +41,12 @@ class AnonymousNotAllowedException(Exception):
             """ % {'action': action, 'signin_url': reverse('auth_signin')})
         )
 
+class SpamNotAllowedException(Exception):
+    def __init__(self, action = "comment"):
+        super(SpamNotAllowedException, self).__init__(
+            _("""Your %s has been marked as spam.""" % action)
+        )
+
 class NotEnoughLeftException(Exception):
     def __init__(self, action, limit):
         super(NotEnoughLeftException, self).__init__(
@@ -244,6 +250,17 @@ def comment(request, id):
 
     comment.create_revision(user, body=comment_text)
 
+    data = {
+        "user_ip":request.META["REMOTE_ADDR"],
+        "user_agent":request.environ['HTTP_USER_AGENT'],
+        "comment_author":request.user.real_name,
+        "comment_author_email":request.user.email,
+        "comment_author_url":request.user.website,
+        "comment":comment_text
+    }
+    if Node.isSpam(comment_text, data):
+        raise SpamNotAllowedException()
+
     if comment.active_revision.revision == 1:
         return {
             'commands': {