Пример #1
0
def update_task(request, id):
    page_title = "Editar Tarefa"
    task = task_service.search_task_id(id)
    if task.user != request.user:
        return HttpResponse(
            "Opa!! parece que você está tentando alterar uma tarefa que não é sua"
        )
    task_form = TaskForm(request.POST or None, instance=task)

    if task_form.is_valid():
        title = task_form.cleaned_data["title"]
        description = task_form.cleaned_data["description"]
        expiration_date = task_form.cleaned_data["expiration_date"]
        priority = task_form.cleaned_data["priority"]
        updated_task = Task(title=title,
                            description=description,
                            expiration_date=expiration_date,
                            priority=priority,
                            user=request.user)

        task_service.update_task(task, updated_task)
        return redirect('index_tasks')
    return render(request, 'tasks/task_form.html', {
        'task_form': task_form,
        'page_title': page_title
    })
Пример #2
0
def add_task(request):
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            return index(request)
        else:
            print form.errors
    else:
        form = TaskForm()
    return render(request, 'app/add_task.html', {'form': form})
Пример #3
0
def edit(request, pk):
    task = Task.objects.get(id=pk)
    form = TaskForm(instance=task)
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            form.save()
            return redirect('index')
    context = {
        'tasks': Task.objects.all(),
        'form': form,
    }
    return render(request, 'edit_task.html', context)
Пример #4
0
def index(request):
    if request.method == 'GET':
        context = {
            'form': TaskForm,
            'tasks': Task.objects.all(),
        }
        return render(request, 'index.html', context)
    else:
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('index')

    context = {
        'tasks': Task.objects.all(),
        'form': form,
    }
    return render(request, 'index.html', context)
Пример #5
0
def edit_task(request, task_id):
    stored_task = task_service.list_task_id(task_id)
    task_form = TaskForm(request.POST or None, instance=stored_task)

    if task_form.is_valid():
        title = task_form.cleaned_data["title"]
        description = task_form.cleaned_data["description"]
        expiration_date = task_form.cleaned_data["expiration_date"]
        priority = task_form.cleaned_data["priority"]

        edited_task = Task(title=title,
                           description=description,
                           expiration_date=expiration_date,
                           priority=priority)
        task_service.edit_task(stored_task, edited_task)

        return redirect('list_tasks')

    return render(request, 'tasks/form_task.html', {'task_form': task_form})
Пример #6
0
def add_task(request):
    if request.method == "POST":

        task_form = TaskForm(request.POST)
        if task_form.is_valid():
            title = task_form.cleaned_data["title"]
            description = task_form.cleaned_data["description"]
            expiration_date = task_form.cleaned_data["expiration_date"]
            priority = task_form.cleaned_data["priority"]

            task_service.store_task(
                Task(title=title,
                     description=description,
                     expiration_date=expiration_date,
                     priority=priority))

            return redirect('list_tasks')

    else:
        task_form = TaskForm(request.POST)
        return render(request, 'tasks/form_task.html',
                      {'task_form': task_form})
Пример #7
0
def create_task(request):
    page_title = "Criar Tarefa"
    if request.method == "POST":
        task_form = TaskForm(request.POST)
        if task_form.is_valid():
            title = task_form.cleaned_data["title"]
            description = task_form.cleaned_data["description"]
            expiration_date = task_form.cleaned_data["expiration_date"]
            priority = task_form.cleaned_data["priority"]
            new_task = Task(title=title,
                            description=description,
                            expiration_date=expiration_date,
                            priority=priority,
                            user=request.user)
            task_service.create_task(new_task)
            return redirect('index_tasks')
    else:
        task_form = TaskForm()
    return render(request, 'tasks/task_form.html', {
        'task_form': task_form,
        'page_title': page_title
    })