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):
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',
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):
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
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',
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