]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/writers.py
merge hernani > trunk
[osqa.git] / forum / views / writers.py
index 017914b793727c2465ae941d2d26b347c1ec0260..a5c5d704f817f926f28d5328842ed72ad02494e9 100644 (file)
@@ -18,6 +18,7 @@ from forum.models import *
 from forum.forms import get_next_url
 from forum.utils import html
 
+from vars import PENDING_SUBMISSION_SESSION_ATTR
 
 def upload(request):#ajax upload file to a question or answer
     class FileTypeNotAllow(Exception):
@@ -84,7 +85,7 @@ def ask(request):
 
                     return HttpResponseRedirect(question.get_absolute_url())
                 else:
-                    request.session['pending_submission_data'] = {
+                    request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
                         'POST': request.POST,
                         'data_name': _("question"),
                         'type': 'ask',
@@ -107,20 +108,11 @@ def ask(request):
 
     return render_to_response('ask.html', {
         'form' : form,
+        'tab' : 'ask'
         }, context_instance=RequestContext(request))
 
 def edit_question(request, id):
-    #question = get_object_or_404(Question, id=id)
-    try:
-        question = Question.objects.get(id=id)
-    except:
-        if slug:
-            question = match_question_slug(slug)
-            if question is not None:
-                return HttpResponseRedirect(question.get_absolute_url())
-
-        raise Http404()
-
+    question = get_object_or_404(Question, id=id)
     if question.nis.deleted and not request.user.can_view_deleted_post(question):
         raise Http404
     if request.user.can_edit_post(question):
@@ -227,7 +219,7 @@ def answer(request, id):
     question = get_object_or_404(Question, id=id)
 
     if request.POST:
-        form = AnswerForm(question, request.POST)
+        form = AnswerForm(request.POST, request.user)
 
         if request.session.pop('reviewing_pending_data', False) or not form.is_valid():
             request.session['redirect_POST_data'] = request.POST
@@ -242,7 +234,7 @@ def answer(request, id):
 
             return HttpResponseRedirect(answer.get_absolute_url())
         else:
-            request.session['pending_submission_data'] = {
+            request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
                 'POST': request.POST,
                 'data_name': _("answer"),
                 'type': 'answer',
@@ -262,7 +254,7 @@ def answer(request, id):
 
 
 def manage_pending_data(request, action, forward=None):
-    pending_data = request.session.pop('pending_submission_data', None)
+    pending_data = request.session.pop(PENDING_SUBMISSION_SESSION_ATTR, None)
 
     if not pending_data:
         raise Http404