Exemple #1
0
 def _form_valid(self):
     subsection = self.form.save(commit=False)
     subsection.order = SubSection.get_next_order(self.section.id)
     subsection.region = self.request.user.user_profile.region
     subsection.save()
     messages.success(self.request, "Subsection successfully created." )
     return HttpResponseRedirect(self.referer_url)
Exemple #2
0
 def save(self, commit=True, *args, **kwargs):
     subsection = super(SubSectionForm, self).save(commit=False, *args, **kwargs)
     if not self.instance.order:
         subsection.order = SubSection.get_next_order(self.instance.section.id)
     if commit:
         subsection.save()
     return subsection
Exemple #3
0
 def save(self, commit=True, *args, **kwargs):
     subsection = super(SubSectionForm, self).save(commit=False,
                                                   *args,
                                                   **kwargs)
     subsection.order = SubSection.get_next_order(self.instance.section.id)
     if commit:
         subsection.save()
     return subsection
Exemple #4
0
 def post(self, request, *args, **kwargs):
     questionnaire_id = kwargs.get('questionnaire_id')
     section_id = kwargs.get('section_id')
     section = Section.objects.get(id=section_id)
     self.form = SubSectionForm(instance=SubSection(section=section),
                                data=request.POST)
     self.referer_url = reverse('questionnaire_entry_page',
                                args=(questionnaire_id, section_id))
     if self.form.is_valid():
         return self._form_valid()
     return self._form_invalid()
    def test_save_increment_order(self):
        existing_subs = SubSection.objects.create(title="subsection 1",
                                                  section=self.section,
                                                  order=1)
        data = self.form_data.copy()

        subsection_form = SubSectionForm(
            instance=SubSection(section=self.section), data=data)
        subsection_form.save()
        new_subs = SubSection.objects.filter(section=self.section, **data)
        self.failUnless(new_subs)
        self.assertEqual(1, new_subs.count())
        self.assertEqual(existing_subs.order + 1, new_subs[0].order)