Пример #1
0
def create_todo(request):
    form = TodoForm(request.POST)

    if form.is_valid():
        todo = Todo(title=form.cleaned_data['title'],
                    description=form.cleaned_data['description'],
                    is_done=False)
        todo.save()
        return redirect('todos index')

    return index(request, form)
Пример #2
0
def update(request, pk):
    todo = Todo.objects.get(pk=pk)
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            todo.title = form.cleaned_data['title']
            todo.description = form.cleaned_data['description']
            todo.save()
            return redirect('all_todos')
    form = TodoForm(initial=todo.__dict__)
    return render(request, 'todo_app/create.html', {'form': form})
Пример #3
0
def edit_todo(request, pk):
    todo = Todo.objects.get(pk=pk)
    if request.method == 'GET':
        form = TodoForm(initial=todo.__dict__)
        return index(request, form, 'edit todo', pk=pk)
    else:
        form = TodoForm(request.POST)
        if form.is_valid():
            todo.title = form.cleaned_data['title']
            todo.description = form.cleaned_data['description']
            todo.save()
        return index(request, form)
Пример #4
0
def create(request):
    if request.method == 'POST':
        form = TodoForm(request.POST)
        if form.is_valid():
            todo = Todo(title=form.cleaned_data['title'],
                        description=form.cleaned_data['description'],
                        is_done=False)
            todo.save()
            return redirect('all_todos')

    else:
        form = TodoForm()
        context = {'form': form}
        return render(request, 'todo_app/create.html', context)
Пример #5
0
def create(request):
    form = TodoForm(request.POST)
    if form.is_valid():
        title = form.cleaned_data['title']
        description = form.cleaned_data['description']
        todo = Todo(
            title=title,
            description=description)
        todo.save()
        return redirect('index')
    context = {
        'form': form,
    }
    return render(request, 'create_template.html', context)
Пример #6
0
def index(req):
    context = {
        'todos': Todo.objects.all(),
        'todo_form': TodoForm(),
    }

    return render(req, 'todo_app/index.html', context=context)
Пример #7
0
def index(request):
    todos = Todo.objects.all().order_by('is_done', 'title')
    form = TodoForm()
    context = {
        'todos': todos,
        'form': form,
    }
    return render(request, 'index.html', context)
Пример #8
0
def create_template(request, form=None, form_action='create', pk=None):
    if not form:
        form = TodoForm()
    context = {
        'form': form,
        'form_action': form_action,
        'pk': pk,
    }
    return render(request, 'create_template.html', context)
Пример #9
0
def index(request, form=None, form_action='create todo', pk=None):
    if not form:
        form = TodoForm()
    context = {
        'todo': Todo.objects.all().order_by('title'),
        'todo_form': form,
        'form_action': form_action,
        'pk': pk,
    }
    return render(request, 'todo_app/index.html', context)
Пример #10
0
def edit(request, pk):
    todo = Todo.objects.get(pk=pk)
    if request.method == 'GET':
        form = TodoForm(initial=todo.__dict__)
        return create_template(request, form, 'edit', pk=pk)
    else:
        form = TodoForm(request.POST)
        if form.is_valid():
            todo.title = form.cleaned_data['title']
            todo.description = form.cleaned_data['description']
            todo.save()
            return redirect(index)

        return create_template(
            request,
            form,
            form_action='edit',
            pk=pk
        )
Пример #11
0
def index(request):
    items_list = TodoModel.objects.order_by('-date')
    if request.method == 'POST':
        form_ = TodoForm(request.POST)
        if form_.is_valid():
            form_.save()
            return redirect('index')
    form_ = TodoForm()
    page = {
        'form_':form_,
        'list':items_list,
        'title':'TODO LIST',
    }
    return render(request,'index.html',page)
Пример #12
0
def create_view(request):
    if request.method == 'POST':
        form = TodoForm(data=request.POST)
        if form.is_valid():

            form.save()
            Blog.objects.filter(author='').update(
                author=request.user.get_username())

            return HttpResponse('Success')
        else:
            print(form.errors)
            return HttpResponse('Failed to create')
    else:
        if request.user.is_authenticated():
            form = TodoForm()

            return render(request, 'todo_app/create_view.html', {
                'form': form,
            })
        else:
            return HttpResponse('No authorize')