示例#1
0
def update_todo(request, todo_id):
    todo = get_object_or_404(Todo, id=todo_id)
    form = TodoForm(request.POST or None, request.FILES or None, instance=todo)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('home:todo_list'))
    return render(request, "form.html", {"form": form})
示例#2
0
def add_todo(request):
    form = TodoForm(request.POST or None, request.FILES or None)
    context = {"form": form}
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('home:todo_list'))
    return render(request, "form.html", context)
示例#3
0
 def test_empty_description(self):
     form = TodoForm({'description': ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'description': [u'This field is required.']}
     )
示例#4
0
 def test_too_title(self):
     form = TodoForm(self.too_long_description)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'description': [u'Ensure this value has at most 128 ' +
                          'characters (it has 129).']}
     )
示例#5
0
def add_todo(request, todolist_id):
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            user = request.user if request.user.is_authenticated else None
            todo = Todo(
                description=request.POST['description'],
                todolist_id=todolist_id,
                creator=user
            )
            todo.save()
            return redirect('home:todolist', todolist_id=todolist_id)
        else: 
            return render(request, 'home/todolist.html', {'form': form})

    return redirect('home:index')
示例#6
0
 def test_valid_input(self):
     form = TodoForm(self.valid_form_data)
     self.assertTrue(form.is_valid())