]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/writers.py
Closing OSQA 91. Give admins a way to make users new admins or moderators.
[osqa.git] / forum / views / writers.py
index 98b523e6f0eb85ca912b06a82a1a2d2220ada89d..3b3e90b5c951792f414a62529d63afee56ceeb6f 100644 (file)
@@ -14,11 +14,10 @@ from django.core.urlresolvers import reverse
 from django.core.exceptions import PermissionDenied
 
 from forum.actions import AskAction, AnswerAction, ReviseAction, RollbackAction, RetagAction
+from forum.modules.decorators import decoratable
 from forum.forms import *
 from forum.models import *
-from forum.const import *
 from forum.utils.forms import get_next_url
-from forum.views.commands import SpamNotAllowedException
 
 
 def upload(request):#ajax upload file to a question or answer
@@ -29,7 +28,6 @@ def upload(request):#ajax upload file to a question or answer
     class UploadPermissionNotAuthorized(Exception):
         pass
 
-    #<result><msg><![CDATA[%s]]></msg><error><![CDATA[%s]]></error><file_url>%s</file_url></result>
     xml_template = "<result><msg><![CDATA[%s]]></msg><error><![CDATA[%s]]></error><file_url>%s</file_url></result>"
 
     try:
@@ -66,24 +64,13 @@ def upload(request):#ajax upload file to a question or answer
 
     return HttpResponse(result, mimetype="application/xml")
 
-
+@decoratable
 def ask(request):
     if request.POST and "text" in request.POST:
         form = AskForm(request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
-                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":request.POST['text']
-                }
-                if Node.isSpam(request.POST['text'], data):
-                    raise SpamNotAllowedException("question")
-
-                question = AskAction(user=request.user).save(data=form.cleaned_data).node
+                question = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data).node
                 return HttpResponseRedirect(question.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST
@@ -118,7 +105,7 @@ def _retag_question(request, question):
         form = RetagQuestionForm(question, request.POST)
         if form.is_valid():
             if form.has_changed():
-                RetagAction(user=request.user, node=question).save(data=dict(tagnames=form.cleaned_data['tags']))
+                RetagAction(user=request.user, node=question, ip=request.META['REMOTE_ADDR']).save(data=dict(tagnames=form.cleaned_data['tags']))
 
             return HttpResponseRedirect(question.get_absolute_url())
     else:
@@ -142,7 +129,7 @@ def _edit_question(request, question):
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
-                ReviseAction(user=request.user, node=question).save(data=form.cleaned_data)
+                ReviseAction(user=request.user, node=question, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
             else:
                 if not revision == question.active_revision:
                     RollbackAction(user=request.user, node=question).save(data=dict(activate=revision))
@@ -179,10 +166,10 @@ def edit_answer(request, id):
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
-                ReviseAction(user=request.user, node=answer).save(data=form.cleaned_data)
+                ReviseAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
             else:
                 if not revision == answer.active_revision:
-                    RollbackAction(user=request.user, node=answer).save(data=dict(activate=revision))
+                    RollbackAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=dict(activate=revision))
 
             return HttpResponseRedirect(answer.get_absolute_url())
 
@@ -195,24 +182,14 @@ def edit_answer(request, id):
                               'form': form,
                               }, context_instance=RequestContext(request))
 
+@decoratable
 def answer(request, id):
     question = get_object_or_404(Question, id=id)
     if request.POST:
         form = AnswerForm(question, request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
-                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":request.POST['text']
-                }
-                if Node.isSpam(request.POST['text'], data):
-                    raise SpamNotAllowedException("answer")
-
-                answer = AnswerAction(user=request.user).save(dict(question=question, **form.cleaned_data)).node
+                answer = AnswerAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(dict(question=question, **form.cleaned_data)).node
                 return HttpResponseRedirect(answer.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST