def questionnaire_edit(request, questionnaire_id): questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id) QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire', )) form = QuestionnaireForm(request.POST or None, instance=questionnaire) formset = QuestionFormset(request.POST or None, instance=questionnaire) if questionnaire.obsolete: messages.add_message(request, messages.INFO, _("Obsolete questionnaires cannot be edited.")) return redirect('evap.fsr.views.questionnaire_index') if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.add_message(request, messages.INFO, _("Successfully updated questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(questionnaire=questionnaire, form=form, formset=formset), context_instance=RequestContext(request))
def questionnaire_create(request): questionnaire = Questionnaire() QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire',)) form = QuestionnaireForm(request.POST or None, instance=questionnaire) formset = QuestionFormset(request.POST or None, instance=questionnaire) if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.success(request, _("Successfully created questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request))
def questionnaire_create(request): questionnaire = Questionnaire() QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire',)) form = QuestionnaireForm(request.POST or None, instance=questionnaire) formset = QuestionFormset(request.POST or None, instance=questionnaire) if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.add_message(request, messages.INFO, _("Successfully created questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request))
def questionnaire_edit(request, questionnaire_id): questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id) QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire',)) form = QuestionnaireForm(request.POST or None, instance=questionnaire) formset = QuestionFormset(request.POST or None, instance=questionnaire) if questionnaire.obsolete: messages.info(request, _("Obsolete questionnaires cannot be edited.")) return redirect('evap.fsr.views.questionnaire_index') if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.success(request, _("Successfully updated questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(questionnaire=questionnaire, form=form, formset=formset), context_instance=RequestContext(request))
def questionnaire_copy(request, questionnaire_id): if request.method == "POST": questionnaire = Questionnaire() QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire',)) form = QuestionnaireForm(request.POST, instance=questionnaire) formset = QuestionFormset(request.POST.copy(), instance=questionnaire, save_as_new=True) if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.success(request, _("Successfully created questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request)) else: questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id) QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=IdLessQuestionFormSet, form=QuestionForm, extra=1, exclude=('questionnaire',)) form = QuestionnaireForm(instance=questionnaire) formset = QuestionFormset(instance=Questionnaire(), queryset=questionnaire.question_set.all()) return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request))
def questionnaire_copy(request, questionnaire_id): if request.method == "POST": questionnaire = Questionnaire() QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=AtLeastOneFormSet, form=QuestionForm, extra=1, exclude=('questionnaire', )) form = QuestionnaireForm(request.POST, instance=questionnaire) formset = QuestionFormset(request.POST.copy(), instance=questionnaire, save_as_new=True) if form.is_valid() and formset.is_valid(): form.save() formset.save() messages.add_message(request, messages.INFO, _("Successfully created questionnaire.")) return redirect('evap.fsr.views.questionnaire_index') else: return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request)) else: questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id) QuestionFormset = inlineformset_factory(Questionnaire, Question, formset=IdLessQuestionFormSet, form=QuestionForm, extra=1, exclude=('questionnaire', )) form = QuestionnaireForm(instance=questionnaire) formset = QuestionFormset(instance=Questionnaire(), queryset=questionnaire.question_set.all()) return render_to_response("fsr_questionnaire_form.html", dict(form=form, formset=formset), context_instance=RequestContext(request))