Exemplo n.º 1
0
def addQuestion(request):
    action = "/question/add/"
    if(request.method == "POST"):
        form = QuestionForm(user=request.user, data=request.POST)
        if form.is_valid():
            q = form.save(commit=False)
            q.creator = request.user
            q.save()
            if(not request.session.get("written_questions", False)):
                request.session['written_questions'] = 0
            request.session['written_questions'] = int(request.session['written_questions']) + 1
            request.session['last_group'] = q.group.id if q.group is not None else None
            request.session['last_subject'] = q.subject.id
            return redirect("qset.views.addQuestion")
    else:
        form = QuestionForm(user=request.user, s_group=request.session.get("last_group", None), s_subject=request.session.get("last_subject", None))
    return render_to_response('qset/addquestion.html', {"form": form, "tot_written": request.session.get("written_questions", 0), "q_count": user_q_status(request.user), "action": action, "title": "Add Question", "success": request.GET.get("success", "false")})
Exemplo n.º 2
0
def editQuestion(request, q_id):
    question = get_object_or_404(Question, uid=q_id)
    action = question.get_edit_url()
    if(question.is_used == 0 and (request.user == question.creator)) or (request.GET.get("f", False) == "1" and request.user == question.creator):
        if request.method == "POST":
            form = QuestionForm(user=request.user, data=request.POST, instance=question)
            if form.is_valid():
                form.save()
                messages.info(request, "Question saved.")
                return redirect("/close/")
        else:
            form = QuestionForm(user=request.user, instance=question)
        return render_to_response('qset/addquestion.html', {"form": form, "q_count": user_q_status(request.user), "action": action, "question": question, "ans": question.answer.strip().lower(), "type": "question", "title": "Edit question", "success": "false"})
    elif question.is_used != 0:
        message = "Sorry, this question is being used in a set. You may not edit it."
        if request.user == question.creator:
            message = "This set is already in a set, are you sure you want to edit it? <a href='/question/edit/" + question.uid + "/?f=1'>Continue</a>"
        return render_to_response('qset/question_view.html', {"question": question, "msg": message})
    else:
        # Is the user is not the creator of the question (or staff)
        return HttpResponseRedirect('/')
Exemplo n.º 3
0
def addQuestion(request):
    action = "/question/add/"
    if (request.method == "POST"):
        form = QuestionForm(user=request.user, data=request.POST)
        if form.is_valid():
            q = form.save(commit=False)
            q.creator = request.user
            q.save()
            if (not request.session.get("written_questions", False)):
                request.session['written_questions'] = 0
            request.session['written_questions'] = int(
                request.session['written_questions']) + 1
            request.session[
                'last_group'] = q.group.id if q.group is not None else None
            request.session['last_subject'] = q.subject.id
            return redirect("qset.views.addQuestion")
    else:
        form = QuestionForm(user=request.user,
                            s_group=request.session.get("last_group", None),
                            s_subject=request.session.get(
                                "last_subject", None))
    return render_to_response(
        'qset/addquestion.html', {
            "form": form,
            "tot_written": request.session.get("written_questions", 0),
            "q_count": user_q_status(request.user),
            "action": action,
            "title": "Add Question",
            "success": request.GET.get("success", "false")
        })
Exemplo n.º 4
0
def editQuestion(request, q_id):
    question = get_object_or_404(Question, uid=q_id)
    action = question.get_edit_url()
    if (question.is_used == 0 and
        (request.user == question.creator)) or (request.GET.get(
            "f", False) == "1" and request.user == question.creator):
        if request.method == "POST":
            form = QuestionForm(user=request.user,
                                data=request.POST,
                                instance=question)
            if form.is_valid():
                form.save()
                messages.info(request, "Question saved.")
                return redirect("/close/")
        else:
            form = QuestionForm(user=request.user, instance=question)
        return render_to_response(
            'qset/addquestion.html', {
                "form": form,
                "q_count": user_q_status(request.user),
                "action": action,
                "question": question,
                "ans": question.answer.strip().lower(),
                "type": "question",
                "title": "Edit question",
                "success": "false"
            })
    elif question.is_used != 0:
        message = "Sorry, this question is being used in a set. You may not edit it."
        if request.user == question.creator:
            message = "This set is already in a set, are you sure you want to edit it? <a href='/question/edit/" + question.uid + "/?f=1'>Continue</a>"
        return render_to_response('qset/question_view.html', {
            "question": question,
            "msg": message
        })
    else:
        # Is the user is not the creator of the question (or staff)
        return HttpResponseRedirect('/')