Example #1
0
 def test_no_title(self):
     form = TodoListForm({})
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'title': [u'This field is required.']}
     )
Example #2
0
 def test_no_title(self):
     form = TodoListForm({})
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'title': [u'This field is required.']}
     )
Example #3
0
 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).']}
     )
Example #4
0
 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).']}
     )
Example #5
0
 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)."
             ]
         },
     )
Example #6
0
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')
Example #7
0
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')
Example #8
0
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")
Example #9
0
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")
Example #10
0
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')
Example #11
0
 def test_valid_input(self):
     form = TodoListForm(self.vaild_form_data)
     self.assertTrue(form.is_valid())
Example #12
0
def overview(request):
    if request.method == 'POST':
        return redirect('lists:add_todolist')
    return render(request, 'lists/overview.html', {'form': TodoListForm()})
Example #13
0
 def test_empty_title(self):
     form = TodoListForm({"title": ""})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors, {"title": ["This field is required."]})
Example #14
0
 def test_valid_input(self):
     form = TodoListForm(self.vaild_form_data)
     self.assertTrue(form.is_valid())
Example #15
0
def overview(request):
    if request.method == "POST":
        return redirect("lists:add_todolist")
    return render(request, "lists/overview.html", {"form": TodoListForm()})
Example #16
0
def index(request):
    return render(request, "lists/index.html", {"form": TodoListForm()})