def editQuestion(request, questionId): args={} args.update(csrf(request)) objQuestionForm = QuestionForm(request.POST or None) objOptionForm = OptionFrom(request.POST or None) if request.method == 'POST': flag=False if request.POST['type_text'] == 'MCQ': # objOptionForm.clean_optionheadertext(sOptionHeaderText=request.POST['option_header_text'],nOptionHeaderID=request.POST['option_header_id']) if objQuestionForm.is_valid() and objOptionForm.is_valid(): flag=True else: objOptionForm = OptionFrom() if objQuestionForm.is_valid(): flag=True if flag == True: iOptionHeaderID = None i_UserId = UserDetails.objects.get(user_id=request.session['UserID']) if request.POST['type_text'] == 'MCQ': if request.POST['option_header_id']=='0': objOptionHeader = OptionHeader.objects.create(title=request.POST['option_header_text'], modified_by=i_UserId, modified_on=timezone.now()) iOptionHeaderID = OptionHeader.objects.latest('option_header_id') objOptionForm.save(commit=False, userId=i_UserId, optionHeaderId=iOptionHeaderID) else: iOptionHeaderID = OptionHeader.objects.get(option_header_id=request.POST['option_header_id']) Question.objects.filter(question_id=request.POST['questionID']).update(question=request.POST['question'],level=request.POST['level'],weight=request.POST['weight'],info=request.POST['info'],intent=request.POST['intent'],type=request.POST['type_text'],option_header=iOptionHeaderID) return HttpResponseRedirect("/question/QuestionList") else: args['optionCreateform']=objOptionForm args['questionCreateform']=objQuestionForm else: objQuestion=Question.objects.get(question_id=int(questionId)) if objQuestion.type=='MCQ': objOptionHeader=OptionHeader.objects.get(option_header_id=objQuestion.option_header_id) objOption=Option.objects.filter(option_header=objOptionHeader.option_header_id) optionText='' for option in objOption: optionText+=option.option_text + '|#|' + str(option.option_level)+'|,|' optionText=optionText[:-3] objOptionForm = OptionFrom(initial={'option_header_id':str(objOptionHeader.option_header_id),'option_text':optionText,'option_header_text':objOptionHeader.title}) args['optionCreateform']=objOptionForm objQuestionForm = QuestionForm(initial={'questionID':questionId,'question':objQuestion.question,'level':objQuestion.level,'weight':objQuestion.weight,'info':objQuestion.info,'intent':objQuestion.intent,'type_text':objQuestion.type}) args['questionCreateform']=objQuestionForm return render_to_response('Questions/CreateQuestion.html',args)
def questionCreateView(request): args={} args.update(csrf(request)) args['error']='' objQuestionForm = QuestionForm(request.POST or None) objOptionForm = OptionFrom(request.POST or None) if request.method == 'POST': if request.POST['type_text'] == 'MCQ': # objOptionForm.clean_optionheadertext(sOptionHeaderText=request.POST['option_header_text'],nOptionHeaderID=request.POST['option_header_id']) if objQuestionForm.is_valid() and objOptionForm.is_valid(): flag=True else: flag=False else: objOptionForm = OptionFrom() if objQuestionForm.is_valid(): flag=True else: flag=False if flag == True: iOptionHeaderID = 0 i_UserId = UserDetails.objects.get(user_id=request.session['UserID']) if request.POST['type_text'] == 'MCQ': if request.POST['option_header_id']=='0': objOptionHeader = OptionHeader.objects.create(title=request.POST['option_header_text'], modified_by=i_UserId, modified_on=timezone.now()) iOptionHeaderID = OptionHeader.objects.latest('option_header_id') objOptionForm.save(commit=False, userId=i_UserId, optionHeaderId=iOptionHeaderID) else: iOptionHeaderID = OptionHeader.objects.get(option_header_id=request.POST['option_header_id']) objQuestionForm.save(commit=False, userId = i_UserId, optionHeaderId = iOptionHeaderID) args['successMsg']="Question created successfully" objOptionForm = OptionFrom() initial = {'type_text' : request.POST['type_text']} objQuestionForm = QuestionForm() args['questionCreateform']=objQuestionForm args['optionCreateform']=objOptionForm return render_to_response('Questions/CreateQuestion.html',args) else: args['questionCreateform']=objQuestionForm args['optionCreateform']=objOptionForm return render_to_response('Questions/CreateQuestion.html',args) else: args['questionCreateform']=objQuestionForm args['optionCreateform']=objOptionForm return render_to_response('Questions/CreateQuestion.html',args)