Ejemplo n.º 1
0
def view_list(request, list_id):
    list_ = List.objects.get(id=list_id)
    form = ExistingListItemForm(for_list=list_)
    if request.method == 'POST':
        form = ExistingListItemForm(for_list=list_, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(list_)         
    return render(request, 'list.html', {'list': list_, "form": form})
Ejemplo n.º 2
0
 def test_form_save(self):
     list_ = List.objects.create()
     form = ExistingListItemForm(for_list=list_, data={'text': 'hi'})
     new_item = form.save()
     self.assertEqual(new_item, Item.objects.all()[0])
Ejemplo n.º 3
0
 def test_form_validation_for_blank_items(self):
     list_ = List.objects.create()
     form = ExistingListItemForm(for_list=list_, data={'text': ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['text'], [EMPTY_ITEM_ERROR])
Ejemplo n.º 4
0
 def test_form_validation_for_duplicate_items(self):
     list_ = List.objects.create()
     Item.objects.create(list=list_, text='no twins!')
     form = ExistingListItemForm(for_list=list_, data={'text': 'no twins!'})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['text'], [DUPLICATE_ITEM_ERROR])
Ejemplo n.º 5
0
 def test_form_renders_item_text_input(self):
     list_ = List.objects.create()
     form = ExistingListItemForm(for_list=list_)
     self.assertIn('placeholder="Enter name"', form.as_p())