- if request.method == "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.real_name,
- "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")
-
- return _create_post(request, Question, form)
- else:
- return HttpResponseRedirect(reverse('auth_action_signin', kwargs={'action': 'newquestion'}))
- elif request.method == "POST" and "go" in request.POST:
- form = AskForm({'title': request.POST['q']})
- else:
- form = AskForm()
+ form = None
+
+ if request.POST:
+ if request.session.pop('reviewing_pending_data', False):
+ form = AskForm(initial=request.POST, user=request.user)
+ elif "text" in request.POST:
+ form = AskForm(request.POST, user=request.user)
+ if form.is_valid():
+ if request.user.is_authenticated() and request.user.email_valid_and_can_ask():
+ ask_action = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+ question = ask_action.node
+
+ if settings.WIKI_ON and request.POST.get('wiki', False):
+ question.nstate.wiki = ask_action
+
+ return HttpResponseRedirect(question.get_absolute_url())
+ else:
+ request.session[PENDING_SUBMISSION_SESSION_ATTR] = {
+ 'POST': request.POST,
+ 'data_name': _("question"),
+ 'type': 'ask',
+ 'submission_url': reverse('ask'),
+ 'time': datetime.datetime.now()
+ }
+
+ if request.user.is_authenticated():
+ messages.info(request, _("Your question is pending until you %s.") % html.hyperlink(
+ django_settings.APP_URL + reverse('send_validation_email', prefix='/'), _("validate your email")
+ ))
+ return HttpResponseRedirect(reverse('index'))
+ else:
+ return HttpResponseRedirect(reverse('auth_signin'))
+ elif "go" in request.POST:
+ form = AskForm({'title': request.POST['q']}, user=request.user)
+
+ if not form:
+ form = AskForm(user=request.user)