Esempio n. 1
0
def delete(request, primary_key):
    task = TaskList.objects.get(id=primary_key)
    task.delete()
    form = TaskForm()
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect('/')
Esempio n. 2
0
def todolist(request):
    if request.method == 'POST':
        form = TaskForm(request.POST or None)
        if form.is_valid():
            form.save()
        return redirect('todolist')
    else:
        all_task = Tasklist.objects.all
        return render(request, 'todolist.html', {'all_task': all_task})
Esempio n. 3
0
def index(request):
    task = TaskList.objects.all()
    form = TaskForm()
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect('/')
    context = {'form': form, 'tasks': task}
    return render(request, 'todolist/index.html', context)
Esempio n. 4
0
def edit_task(request, task_id):
    if request.method == "POST":
        task = TaskList.objects.get(pk=task_id)
        form = TaskForm(request.POST or None, instance=task)
        if form.is_valid():
            form.save()
        messages.success(request, ("Task edited!"))
        return redirect('todolist')
    else:
        task_obj = TaskList.objects.get(pk=task_id)
        return render(request, 'edit.html', {'task_obj': task_obj})
Esempio n. 5
0
def edit_task(request, task_id):
    if request.method == 'POST':
        id = Tasklist.objects.get(pk=task_id)
        form_id = TaskForm(request.POST or None, instance=id)

        if form_id.is_valid():
            form_id.save()

        messages.success(request, ("The task is updated"))
        return redirect('todolist')

    else:
        task_obj = Tasklist.objects.get(pk=task_id)
        return render(request, 'edit.html', {'task_obj': task_obj})
Esempio n. 6
0
def todolist(request):
    if request.method == "POST":
        form = TaskForm(request.POST or None)
        if form.is_valid():
            form.save(commit=False).manage = request.user
            form.save()
        messages.success(request, ("Task Added Successfully!"))
        return redirect('todolist')
    else:
        all_tasks = Tasklist.objects.filter(manage=request.user)
        paginator = Paginator(all_tasks, 5)
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)
        return render(request, 'todolist.html', {'all_tasks': all_tasks})
Esempio n. 7
0
def edit_task(request, task_id):
    if request.method == 'POST':
        # we select a task to edit
        task = TaskList.objects.get(pk=task_id)
        # instance helps the database to recognise which task to edit
        form = TaskForm(request.POST or None, instance=task)
        if form.is_valid:
            form.save()

        messages.success(request, 'Task edited')

        return redirect('landing_page')
    else:
        task_obj = TaskList.objects.get(pk=task_id)

        return render(request, 'edit.html', {'task_obj': task_obj})
Esempio n. 8
0
def landing_page(request):
    if request.method == "POST":
        # connecting to the form
        # form checks if the field is empty or not and passes request.POST or None
        form = TaskForm(request.POST or None)
        # checking if the data we are provided with are valid
        if form.is_valid():
            # save value into instance
            instance = form.save(commit=False)
            # connect to the owner of instance and set it as a user
            instance.owner = request.user
            # then save instance with a user
            instance.save()

        messages.success(request, 'Task added successfully')

        return redirect('landing_page')
    else:
        all_tasks = TaskList.objects.filter(owner=request.user)
        # dzielimy all tasks po 5 na stronę
        paginator = Paginator(all_tasks, 6)
        # w get request parameter pg pojawia się w linku
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)

        return render(request, 'todolist.html', {'all_tasks': all_tasks})
Esempio n. 9
0
def edit_task(request, task_id):

    if request.method == 'POST':  ## If i want add anything in db

        task = TaskList.objects.get(pk=task_id)
        form = TaskForm(
            request.POST or None,
            instance=task)  ##instance=task means which task your are editing
        if form.is_valid():
            form.save()

        messages.success(request, ("Task Edited Successfully"))
        return redirect('todolist')

    else:
        task_obj = TaskList.objects.get(
            pk=task_id)  # it will fetch single data of that particular id

        return render(request, 'edit.html',
                      {'task_obj': task_obj})  ## one obj (particular obj)
Esempio n. 10
0
def create_task(request, pk):
    todo_list = get_object_or_404(ToDoList, pk=pk)
    # todo_list = todo.id
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.todo_list = todo_list
            task.save()
            return redirect('list_view', pk=todo_list.id)
    else:
        form = TaskForm()
    return render(request, 'todolist/create_task.html', {'form': form})
Esempio n. 11
0
def todolist(request):
    if request.method == 'POST':
        form = TaskForm(request.POST or None)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.manage = request.user
            instance.save()
        messages.success(request, ('New Task added'))
        return redirect('todolist')

    else:

        all_tasks = TaskList.objects.filter(manage=request.user)
        paginator = Paginator(all_tasks, 5)
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)

        return render(request, 'todolist.html', {'all_tasks': all_tasks})
Esempio n. 12
0
def todolist(request):

    if request.method == "POST":
        form = TaskForm(request.POST or None)

        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = request.user
            instance.save()

        messages.success(request, ("The new task is added successfully"))

        return redirect('todolist')

    else:

        all_task = Tasklist.objects.filter(user=request.user)
        paginator = Paginator(all_task, 5)
        page = request.GET.get('pg')
        all_task = paginator.get_page(page)
        return render(request, 'task.html', {'all_task': all_task})
Esempio n. 13
0
def todolist(request):

    if request.method == 'POST':  ## If i want add anything in db
        form = TaskForm(request.POST or None)  ## If i want add anything in db
        if form.is_valid():  ## If i want add anything in db
            instance = form.save(
                commit=False)  ## commit=False, to access manager
            instance.manager = request.user
            instance.save()

        messages.success(request, ("Task Added Successfully"))

        return redirect('todolist')

    else:
        # all_tasks = TaskList.objects.all()   # it will fetch all the data inside all_task object(if i want to access anything)
        all_tasks = TaskList.objects.filter(
            manager=request.user)  ## Task of logged in user only
        paginator = Paginator(all_tasks, 7)
        page = request.GET.get('pg')
        all_tasks = paginator.get_page(page)
        return render(request, 'todolist.html',
                      {'all_tasks': all_tasks})  ## all obj