]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/commands.py
Put the badge count denormalization back.
[osqa.git] / forum / views / commands.py
index 8591930c7ae2233543ae7c3ac15d1466fbaf6cc1..6220bc229344e288eb3ef88180401ef4f8b3e414 100644 (file)
@@ -1,5 +1,5 @@
 import datetime
 import datetime
-from django.conf import settings
+from forum import settings
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils import simplejson
 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils import simplejson
 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden
@@ -7,11 +7,11 @@ from django.shortcuts import get_object_or_404, render_to_response
 from django.utils.translation import ungettext, ugettext as _
 from django.template import RequestContext
 from forum.models import *
 from django.utils.translation import ungettext, ugettext as _
 from django.template import RequestContext
 from forum.models import *
-from forum.forms import CloseForm
 from forum.actions import *
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 from forum.utils.decorators import ajax_method, ajax_login_required
 from forum.actions import *
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 from forum.utils.decorators import ajax_method, ajax_login_required
+from forum.modules.decorators import decoratable
 from decorators import command, CommandException
 from forum import settings
 import logging
 from decorators import command, CommandException
 from forum import settings
 import logging
@@ -19,53 +19,31 @@ import logging
 class NotEnoughRepPointsException(CommandException):
     def __init__(self, action):
         super(NotEnoughRepPointsException, self).__init__(
 class NotEnoughRepPointsException(CommandException):
     def __init__(self, action):
         super(NotEnoughRepPointsException, self).__init__(
-            _("""
-            Sorry, but you don't have enough reputation points to %(action)s.<br />
-            Please check the <a href'%(faq_url)s'>faq</a>
-            """ % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry, but you don't have enough reputation points to %(action)s.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
         )
 
 class CannotDoOnOwnException(CommandException):
     def __init__(self, action):
         super(CannotDoOnOwnException, self).__init__(
         )
 
 class CannotDoOnOwnException(CommandException):
     def __init__(self, action):
         super(CannotDoOnOwnException, self).__init__(
-            _("""
-            Sorry but you cannot %(action)s your own post.<br />
-            Please check the <a href'%(faq_url)s'>faq</a>
-            """ % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry but you cannot %(action)s your own post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
         )
 
 class AnonymousNotAllowedException(CommandException):
     def __init__(self, action):
         super(AnonymousNotAllowedException, self).__init__(
         )
 
 class AnonymousNotAllowedException(CommandException):
     def __init__(self, action):
         super(AnonymousNotAllowedException, self).__init__(
-            _("""
-            Sorry but anonymous users cannot %(action)s.<br />
-            Please login or create an account <a href'%(signin_url)s'>here</a>.
-            """ % {'action': action, 'signin_url': reverse('auth_signin')})
-        )
-
-class SpamNotAllowedException(CommandException):
-    def __init__(self, action = "comment"):
-        super(SpamNotAllowedException, self).__init__(
-            _("""Your %s has been marked as spam.""" % action)
+            _("""Sorry but anonymous users cannot %(action)s.<br />Please login or create an account <a href='%(signin_url)s'>here</a>.""" % {'action': action, 'signin_url': reverse('auth_signin')})
         )
 
 class NotEnoughLeftException(CommandException):
     def __init__(self, action, limit):
         super(NotEnoughLeftException, self).__init__(
         )
 
 class NotEnoughLeftException(CommandException):
     def __init__(self, action, limit):
         super(NotEnoughLeftException, self).__init__(
-            _("""
-            Sorry, but you don't have enough %(action)s left for today..<br />
-            The limit is %(limit)s per day..<br />
-            Please check the <a href'%(faq_url)s'>faq</a>
-            """ % {'action': action, 'limit': limit, 'faq_url': reverse('faq')})
+            _("""Sorry, but you don't have enough %(action)s left for today..<br />The limit is %(limit)s per day..<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'limit': limit, 'faq_url': reverse('faq')})
         )
 
 class CannotDoubleActionException(CommandException):
     def __init__(self, action):
         super(CannotDoubleActionException, self).__init__(
         )
 
 class CannotDoubleActionException(CommandException):
     def __init__(self, action):
         super(CannotDoubleActionException, self).__init__(
-            _("""
-            Sorry, but you cannot %(action)s twice the same post.<br />
-            Please check the <a href'%(faq_url)s'>faq</a>
-            """ % {'action': action, 'faq_url': reverse('faq')})
+            _("""Sorry, but you cannot %(action)s twice the same post.<br />Please check the <a href='%(faq_url)s'>faq</a>""" % {'action': action, 'faq_url': reverse('faq')})
         )
 
 
         )
 
 
@@ -232,6 +210,7 @@ def mark_favorite(request, id):
         }
     }
 
         }
     }
 
+@decoratable
 @command
 def comment(request, id):
     post = get_object_or_404(Node, id=id)
 @command
 def comment(request, id):
     post = get_object_or_404(Node, id=id)
@@ -254,17 +233,6 @@ def comment(request, id):
     if len(comment_text) > settings.FORM_MAX_COMMENT_BODY:
         raise CommandException(_("No more than %d characters on comment body.") % settings.FORM_MAX_COMMENT_BODY)
 
     if len(comment_text) > settings.FORM_MAX_COMMENT_BODY:
         raise CommandException(_("No more than %d characters on comment body.") % settings.FORM_MAX_COMMENT_BODY)
 
-    data = {
-        "user_ip":request.META["REMOTE_ADDR"],
-        "user_agent":request.environ['HTTP_USER_AGENT'],
-        "comment_author":request.user.username,
-        "comment_author_email":request.user.email,
-        "comment_author_url":request.user.website,
-        "comment":comment_text
-    }
-    if Node.isSpam(comment_text, data):
-        raise SpamNotAllowedException()
-
     if 'id' in request.POST:
         comment = get_object_or_404(Comment, id=request.POST['id'])
 
     if 'id' in request.POST:
         comment = get_object_or_404(Comment, id=request.POST['id'])