Exemple #1
0
def task_details(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    if request.user != task.user:
        return HttpResponse("You don't have permission to view this task.")
    if request.method == "POST":
        if "complete" in request.POST:
            task.completed = True
            task.date_completed = datetime.date.today()
            task.save()
            complete_feed.delay(request.user, task.name)
            # feed = Feed(user=request.user, activity='You completed task: '+ task.name)
            # feed.save()
        elif "incomplete" in request.POST:
            task.completed = False
            task.date_completed = None
            task.save()
            add_feed.delay(request.user, task.name)
            # feed = Feed(user=request.user, activity='You added task: '+ task.name)
            # feed.save()
        elif "delete" in request.POST:
            task.delete()
            delete_feed.delay(request.user, task.name)
            # feed = Feed(user=request.user, activity='You deleted task: '+ task.name)
            # feed.save()
            return HttpResponseRedirect(reverse("tasks"))
    return render(request, "taskmanager/task_details.html", {"task": task})
Exemple #2
0
def add_task(request):
    if request.method == "POST":
        name = request.POST.get("name", "")
        deadline = request.POST.get("deadline", "")
        deadline = datetime.datetime.strptime(deadline, "%Y-%m-%d").date()
        today = datetime.date.today()
        if deadline >= today:
            task = Task(user=request.user, name=name, deadline=deadline)
            task.save()
            add_feed.delay(request.user, task.name)
            # feed = Feed(user=request.user, activity='You added task: '+ task.name)
            # feed.save()
            return HttpResponseRedirect(reverse("tasks"))
        else:
            return HttpResponse("Deadline cannot be before current date.")
    return render(request, "taskmanager/add_task.html")