cmsmanage/tasks/views.py

65 lines
1.8 KiB
Python
Raw Normal View History

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from .models import Tool, Task, Event
from .forms import EventForm
def index(request):
context = {
2022-01-24 23:37:04 -05:00
"tools": Tool.objects.all(),
"tasks": Task.objects.all(),
}
2022-01-24 23:37:04 -05:00
return render(request, "tasks/index.dj.html", context)
def toolDetail(request, tool_slug):
tool = get_object_or_404(Tool, slug=tool_slug)
tasks = tool.task_set.all()
2021-05-24 23:12:24 -04:00
events = Event.objects.filter(task__tool=tool)
context = {
2022-01-24 23:37:04 -05:00
"tool": tool,
"tasks": tasks,
"events": events,
}
2022-01-24 23:37:04 -05:00
return render(request, "tasks/toolDetail.dj.html", context)
def taskDetail(request, tool_slug, task_slug):
tool = get_object_or_404(Tool, slug=tool_slug)
task = get_object_or_404(tool.task_set, slug=task_slug)
events = task.event_set.all()
2022-01-24 23:37:04 -05:00
if request.method == "POST":
if request.user.is_authenticated:
event = Event(task=task)
form = EventForm(request.POST, user=request.user, instance=event)
if form.is_valid():
form.save()
2021-05-24 23:12:01 -04:00
form = EventForm(user=request.user)
else:
form = EventForm(request.POST)
form.add_error(None, "Not authenticated: please login")
else:
form = EventForm(user=request.user)
context = {
2022-01-24 23:37:04 -05:00
"tool": tool,
"task": task,
"events": events,
"form": form,
}
if request.user.is_authenticated:
2022-01-24 23:37:04 -05:00
context.update(
{
"task_subs": task.grouptasksubscription_set.filter(
group__user=request.user
),
"tool_subs": tool.grouptoolsubscription_set.filter(
group__user=request.user
),
}
)
return render(request, "tasks/taskDetail.dj.html", context)