def test_row_formsets(self): formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm)) for row in sort_formset(formsets): assert row[1]['A'] is not None assert row[1]['S'] is None assert row[1]['O'] is None assert row[1]['P'] is None
def test_tokens(self): formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm)) rows = sort_formset(formsets) assert rows[0][0] == u'1st (excl) Person Singular' assert rows[1][0] == u'2nd Person Singular' assert rows[2][0] == u'3rd Person Singular'
def test_four_per_row(self): formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm)) for row in sort_formset(formsets): assert len(row[1]) == 4 assert 'A' in row[1] assert 'S' in row[1] assert 'O' in row[1] assert 'P' in row[1]
def edit(request, paradigm_id): pdm = get_object_or_404(Paradigm, pk=paradigm_id) paradigm_form = ParadigmForm(request.POST or None, instance=pdm, prefix='pdm') pronoun_form = create_pronoun_formset(pdm, request.POST or None) # save if valid. if pronoun_formsets_are_valid(pronoun_form) and paradigm_form.is_valid(): pdm = paradigm_form.save(commit=False) pdm.editor = request.user pdm.save() for pronoun, formset in pronoun_form: save_pronoun_formset(pdm, pronoun, formset, request.user) return redirect('pronouns:detail', paradigm_id=pdm.id) # the initial view and the error view return render_to_response('pronouns/edit.html', { 'paradigm': pdm, 'paradigm_form': paradigm_form, 'pronouns': sort_formset(pronoun_form), }, context_instance=RequestContext(request))
def edit(request, paradigm_id): pdm = get_object_or_404(Paradigm, pk=paradigm_id) paradigm_form = ParadigmForm(request.POST or None, instance=pdm, prefix='pdm') pronoun_form = create_pronoun_formset(pdm, request.POST or None) # save if valid. if pronoun_formsets_are_valid(pronoun_form) and paradigm_form.is_valid(): pdm = paradigm_form.save(commit=False) pdm.editor = request.user pdm.save() for pronoun, formset in pronoun_form: save_pronoun_formset(pdm, pronoun, formset, request.user) return redirect('pronouns:detail', paradigm_id=pdm.id) # the initial view and the error view return render( request, 'pronouns/edit.html', { 'paradigm': pdm, 'paradigm_form': paradigm_form, 'pronouns': sort_formset(pronoun_form), })
def test_number_of_rows(self): formsets = create_pronoun_formset(self.pdm, self._generate_post_data(self.pdm)) sortf = sort_formset(formsets) assert len(sortf) == 3