def editQuestion(request, question_id): context = RequestContext(request) question = Question.objects.get(pk=question_id) cardSetList = CardSet.objects.filter(user=request.user) message = "" questionType = "" if request.method == "POST": questionForm = QuestionForm(request.POST, instance=question) if questionForm.is_valid(): question = questionForm.save(commit=False) question, questionType = classifyQuestionType(question) if questionType != "Invalid": question.questionType = questionType selectedCardSet = request.POST["cardSet"] question.cardSet = CardSet.objects.get(name=selectedCardSet) question.save() question.cardSet.save() message = "Question successfully edited." questionType = "The questionType is: " + questionType else: questionType = "The Question is invalid" else: print questionForm.errors else: questionForm = QuestionForm(instance=question) context_dict = { "questionForm": questionForm, "message": message, "question": question, "questionType": questionType, "cardSetList": cardSetList, } return render_to_response("flash/editQuestion.html", context_dict, context)
def addQuestion(request, cardset_id): context = RequestContext(request) message = "" questionType = "" if request.method == "POST": questionForm = QuestionForm(request.POST) # It the question field is filled out, it is valid. if questionForm.is_valid(): question = questionForm.save(commit=False) question, questionType = classifyQuestionType(question) if questionType != "Invalid": question.questionType = questionType question.cardSet = CardSet.objects.get(pk=cardset_id) question.save() question.cardSet.save() # Refresh to new form questionForm = QuestionForm() message = "Question successfully created." questionType = "The questionType is: " + questionType else: questionType = "The Question is invalid" else: print questionForm.errors else: questionForm = QuestionForm() context_dict = { "questionForm": questionForm, "message": message, "cardset_id": cardset_id, "questionType": questionType, } return render_to_response("flash/addQuestion.html", context_dict, context)