def get(self, request, *args, **kwargs): questionnaire = Questionnaire.objects.get( id=self.kwargs['questionnaire_id']) section = Section.objects.get(id=self.kwargs['section_id']) initial = { 'status': 'Draft', 'country': self.request.user.user_profile.country } required_answers = 'show' in request.GET formsets = QuestionnaireEntryFormService(section, initial=initial, highlight=required_answers) printable = 'printable' in request.GET preview = 'preview' in request.GET context = { 'questionnaire': questionnaire, 'section': section, 'printable': printable, 'preview': preview, 'formsets': formsets, 'ordered_sections': questionnaire.sections.order_by('order'), 'form': SectionForm(initial={'questionnaire': questionnaire}), 'action': reverse('new_section_page', args=(questionnaire.id, )), 'subsection_form': SubSectionForm(), 'subsection_action': reverse('new_subsection_page', args=(questionnaire.id, section.id)) } return self.render_to_response(context)
def test_valid_with_initial(self): section_form = SectionForm( data=self.form_data, initial={'questionnaire': self.questionnaire.id}) self.assertTrue(section_form.is_valid())
def test_valid(self): section_form = SectionForm( initial={'questionnaire': self.questionnaire.id}, data=self.form_data) self.assertTrue(section_form.is_valid())