def _process_question_form(request, options, response, instance=None): question_form = QuestionForm(data=request.POST, instance=instance) action_str = "edit" if instance else "add" if question_form.is_valid(): question_form.save(**request.POST) messages.success(request, "Question successfully %sed." % action_str) response = HttpResponseRedirect("/questions/") else: messages.error(request, "Question was not %sed." % action_str) options = dict(request.POST).get("options", None) return response, options, question_form
def _save_subquestion(request, batch_id, instance=None): #possible subquestions are questions not bound to any interviewer yet batch = get_object_or_404(Batch, pk=batch_id) questionform = QuestionForm(batch, instance=instance) if request.method == 'POST': questionform = QuestionForm(batch, data=request.POST, instance=instance) if questionform.is_valid(): if instance: zombify = False else: zombify = True question = questionform.save(zombie=zombify) if request.is_ajax(): return HttpResponse(json.dumps({'id' : question.pk, 'text' : question.text, 'identifier': question.identifier}), content_type='application/json') messages.info(request, 'Sub Question saved') if instance: heading = 'Edit Subquestion' else: heading = 'New Subquestion' context = {'questionform': questionform, 'button_label': 'Create', 'id': 'add-sub_question-form', 'save_url' : reverse('add_batch_subquestion_page', args=(batch.pk, )), 'cancel_url': reverse('batch_questions_page', args=(batch.pk, )), 'class': 'question-form', 'heading': heading} request.breadcrumbs([ ('Surveys', reverse('survey_list_page')), (batch.survey.name, reverse('batch_index_page', args=(batch.survey.pk, ))), (batch.name, reverse('batch_questions_page', args=(batch.pk, ))), ]) template_name = 'questions/new.html' if request.is_ajax(): template_name = 'questions/_add_question.html' return render(request, template_name, context) else: return HttpResponseRedirect(reverse('batch_questions_page', args=(batch.pk, )))
def _process_question_form(request, batch, response, instance=None): question_form = QuestionForm(batch, data=request.POST, instance=instance) action_str = 'edit' if instance else 'add' if question_form.is_valid(): question = question_form.save(**request.POST) if request.POST.has_key('add_to_lib_button'): qt = QuestionTemplate.objects.create(identifier=question.identifier, group=question.group, text=question.text, answer_type=question.answer_type, module=question.module) options = question.options.all() if options: topts = [] for option in options: topts.append(TemplateOption(question=qt, text=option.text, order=option.order)) TemplateOption.objects.bulk_create(topts) messages.success(request, 'Question successfully %sed. to library' % action_str) messages.success(request, 'Question successfully %sed.' % action_str) response = HttpResponseRedirect(reverse('batch_questions_page', args=(batch.pk, ))) else: messages.error(request, 'Question was not %sed.' % action_str) # options = dict(request.POST).get('options', None) return response, question_form
def _save_subquestion(request, batch_id, instance=None): #possible subquestions are questions not bound to any interviewer yet batch = get_object_or_404(Batch, pk=batch_id) questionform = QuestionForm(batch, instance=instance) if request.method == 'POST': questionform = QuestionForm(batch, data=request.POST, instance=instance) if questionform.is_valid(): if instance: zombify = False else: zombify = True question = questionform.save(zombie=zombify) if request.is_ajax(): return HttpResponse(json.dumps({'id' : question.pk, 'text' : question.text, 'identifier': question.identifier}), mimetype='application/json') messages.info(request, 'Sub Question saved') if instance: heading = 'Edit Subquestion' else: heading = 'New Subquestion' context = {'questionform': questionform, 'button_label': 'Create', 'id': 'add-sub_question-form', 'save_url' : reverse('add_batch_subquestion_page', args=(batch.pk, )), 'cancel_url': reverse('batch_questions_page', args=(batch.pk, )), 'class': 'question-form', 'heading': heading} request.breadcrumbs([ ('Surveys', reverse('survey_list_page')), (batch.survey.name, reverse('batch_index_page', args=(batch.survey.pk, ))), (batch.name, reverse('batch_questions_page', args=(batch.pk, ))), ]) template_name = 'questions/new.html' if request.is_ajax(): template_name = 'questions/_add_question.html' return render(request, template_name, context) else: return HttpResponseRedirect(reverse('batch_questions_page', args=(batch.pk, )))
def _save_subquestion(request, batch_id, instance=None): # possible subquestions are questions not bound to any interviewer yet batch = QuestionSet.get(pk=batch_id) QuestionForm = get_question_form(batch.question_model()) questionform = QuestionForm(batch, instance=instance) if request.method == 'POST': questionform = QuestionForm(batch, data=request.POST, instance=instance) if questionform.is_valid(): if instance: zombify = False else: zombify = True question = questionform.save(zombie=zombify) if request.is_ajax(): return HttpResponse(json.dumps({ 'id': question.pk, 'text': question.text, 'identifier': question.identifier }), content_type='application/json') messages.info(request, 'Sub Question saved') if instance: heading = 'Edit Subquestion' else: heading = 'New Subquestion' context = { 'questionform': questionform, 'button_label': 'Create', 'id': 'add-sub_question-form', 'USSD_MAX_CHARS': settings.USSD_MAX_CHARS, 'save_url': reverse('%s_home' % batch.resolve_tag()), 'cancel_url': reverse('qset_questions_page', args=(batch.pk, )), 'class': 'question-form', 'heading': heading } breadcrumbs = Question.edit_breadcrumbs(qset=batch) if breadcrumbs: request.breadcrumbs(breadcrumbs) template_name = 'set_questions/new.html' if request.is_ajax(): template_name = 'set_questions/_add_question.html' return render(request, template_name, context) else: return HttpResponseRedirect( reverse('qset_questions_page', args=(batch.pk, )))