Beispiel #1
0
def create_question(request):
    question_form = QuestionsForm(request.POST or None)
    if question_form.is_valid:
        save_it = question_form.save(commit=False)
        save_it.user = request.user
        save_it.save()
    context = {"form": question_form}
    template = 'poll/QuestionsManagement/CreateQuestion/createQuestion.html'
    return render(request, template, context)
Beispiel #2
0
def update_question(request):
    if "id" in request.POST:
        a = Questions.objects.get(id=request.POST.get("id2"))
        if type(a) is not None:
            if "btn" in request.POST:

                btn = request.POST.get("btn")
                if btn == "search":
                    questions_form = QuestionsForm({'id': a.id, 'question': a.question, 'option1': a.option1,
                                                    'option2': a.option2, 'option3': a.option3, 'option4': a.option4,
                                                    'answer': a.answer},
                                                   instance=a)
                    print "Submit, Search"
                    if questions_form.is_valid:
                        questions_form.save(commit=False)
                elif btn == "update":
                    questions_form = QuestionsForm(request.POST or None, instance=a)
                    print "Submit, Update"
                    if questions_form.is_valid:
                        save_it = questions_form.save(commit=False)
                        save_it.user = request.user
                        save_it.save()
                elif btn == "delete":
                    questions_form = QuestionsForm(request.POST or None, instance=a)
                    print "Submit delete"
                    if questions_form.is_valid:
                        delete_it = questions_form.save(commit=False)
                        delete_it.user = request.user
                        delete_it.delete()
        else:
            questions_form = QuestionsForm()
    else:
        # show a page without any post
        questions_form = QuestionsForm()

    context = {"form": questions_form}
    template = "poll/QuestionsManagement/UpdateQuestion/updateQuestion.html"
    return render(request, template, context)