def test_no_title(self): form = TodoListForm({}) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, {'title': [u'This field is required.']} )
def test_too_long_title(self): form = TodoListForm(self.too_long_title) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, {'title': [u'Ensure this value has at most 128 ' + 'characters (it has 129).']} )
def test_too_long_title(self): form = TodoListForm(self.too_long_title) self.assertFalse(form.is_valid()) self.assertEqual( form.errors, { "title": [ "Ensure this value has at most 128 " + "characters (it has 129)." ] }, )
def add_todolist(request): if request.method == 'POST': form = TodoListForm(request.POST) if form.is_valid(): user = request.user if request.user.is_authenticated() else None todolist = TodoList(title=request.POST['title'], creator=user) todolist.save() return redirect('lists:todolist', todolist_id=todolist.id) else: return render(request, 'lists/overview.html', {'form': form}) return redirect('lists:index')
def add_todolist(request): if request.method == "POST": form = TodoListForm(request.POST) if form.is_valid(): user = request.user if request.user.is_authenticated else None todolist = TodoList(title=request.POST["title"], creator=user) todolist.save() return redirect("lists:todolist", todolist_id=todolist.id) else: return render(request, "lists/overview.html", {"form": form}) return redirect("lists:index")
def new_todolist(request): if request.method == "POST": form = TodoListForm(request.POST) print("#" * 40) print(form) print("#" * 40) print(request.POST) if form.is_valid(): # create default todolist user = request.user if request.user.is_authenticated else None print(request) todolist = TodoList(creator=user, title=request.POST['title']) todolist.save() return redirect("lists:todolist", todolist_id=todolist.id) else: return render(request, "lists/index.html", {"form": TodoListForm}) return redirect("lists:index")
def add_todolist(request): if request.method == 'POST': form = TodoListForm(request.POST) if form.is_valid(): user = request.user title = request.POST['title'] is_group_list = (title in Group.objects.all().values_list("name", flat=True)) title_exists = TodoList.objects.filter(title=title).exists() if is_group_list and title_exists and not user.is_superuser: messages.error( request, "A todolist with title {} already exists!".format(title)) return render(request, 'lists/overview.html', {'form': form}) todolist = TodoList(title=title, creator=user) todolist.save() return redirect('lists:todolist', todolist_id=todolist.id) else: return render(request, 'lists/overview.html', {'form': form}) return redirect('lists:index')
def test_valid_input(self): form = TodoListForm(self.vaild_form_data) self.assertTrue(form.is_valid())
def overview(request): if request.method == 'POST': return redirect('lists:add_todolist') return render(request, 'lists/overview.html', {'form': TodoListForm()})
def test_empty_title(self): form = TodoListForm({"title": ""}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors, {"title": ["This field is required."]})
def overview(request): if request.method == "POST": return redirect("lists:add_todolist") return render(request, "lists/overview.html", {"form": TodoListForm()})
def index(request): return render(request, "lists/index.html", {"form": TodoListForm()})