예제 #1
0
def create(request):
    form = TodoForm(request.POST)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect('/')
    else:
        return HttpResponseBadRequest()
예제 #2
0
def add(request, todolist_id):
    """
    View created to add a new Todo,
    Receiving an POST request and send it
    to the TodoForm, for beeing saved,
    if the form is valid.
    """
    todolist = get_object_or_404(TodoList, pk=todolist_id)
    todo_form = TodoForm(request.POST or None)

    if todo_form.is_valid():
        todo = todo_form.save(todolist=todolist)
        messages.success(request, u'Todo "%s" created with success.' % todo)
    else:
        messages.error(request, u'The form was not filled correctly.')

    return redirect('todos', todolist_id)
예제 #3
0
def add(request, todolist_id):
    """
    View created to add a new Todo,
    Receiving an POST request and send it
    to the TodoForm, for beeing saved,
    if the form is valid.
    """
    todolist = get_object_or_404(TodoList, pk=todolist_id)
    todo_form = TodoForm(request.POST or None)

    if todo_form.is_valid():
        todo = todo_form.save(todolist=todolist)
        messages.success(request, u'Todo "%s" created with success.' % todo)
    else:
        messages.error(request, u'The form was not filled correctly.')

    return redirect('todos', todolist_id)
예제 #4
0
def home(request):
    form = TodoForm()
    todos = Todo.objects.all()
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render(request, 'core/home.html', {'form': form, 'todos': todos})
예제 #5
0
def update(request, todo_id):
    todo = Todo.objects.get(id=todo_id)
    form = TodoForm(instance=todo)
    if request.method == 'POST':
        form = TodoForm(request.POST, instance=todo)
        if form.is_valid():
            form.save()
            return redirect('home')
    return render(request, 'core/update.html', {'form': form, 'todo': todo})
예제 #6
0
def list(request, todolist_id, page=1):
    """
    View created to list all the Todos,
    paginated by Five itens per page, and
    display in the last <li> a input for
    add new Todos.
    """
    todolist = get_object_or_404(TodoList, pk=todolist_id)
    paginator = Paginator(todolist.todos.all(), 5)

    try:
        todos = paginator.page(int(page))
    except EmptyPage:
        todos = []

    data = {
        'todolist': todolist,
        'todo_form': TodoForm(),
        'todos': todos,
        'page': page,
    }
    return render_to_response('todos.html',
                              data,
                              context_instance=RequestContext(request))