2020-12-03 12:31:39 -05:00
|
|
|
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 = {
|
|
|
|
'tools': Tool.objects.all(),
|
|
|
|
'tasks': Task.objects.all(),
|
|
|
|
}
|
2022-01-23 23:01:47 -05:00
|
|
|
return render(request, 'tasks/index.dj.html', context)
|
2020-12-03 12:31:39 -05:00
|
|
|
|
|
|
|
|
2021-05-19 17:01:28 -04:00
|
|
|
def toolDetail(request, tool_slug):
|
|
|
|
tool = get_object_or_404(Tool, slug=tool_slug)
|
2020-12-03 12:31:39 -05:00
|
|
|
tasks = tool.task_set.all()
|
2021-05-24 23:12:24 -04:00
|
|
|
events = Event.objects.filter(task__tool=tool)
|
2020-12-03 12:31:39 -05:00
|
|
|
context = {
|
|
|
|
'tool': tool,
|
|
|
|
'tasks': tasks,
|
2021-05-24 23:12:24 -04:00
|
|
|
'events': events,
|
2020-12-03 12:31:39 -05:00
|
|
|
}
|
2022-01-23 23:01:47 -05:00
|
|
|
return render(request, 'tasks/toolDetail.dj.html', context)
|
2020-12-03 12:31:39 -05:00
|
|
|
|
|
|
|
|
2021-05-19 17:01:28 -04:00
|
|
|
def taskDetail(request, tool_slug, task_slug):
|
|
|
|
tool = get_object_or_404(Tool, slug=tool_slug)
|
2020-12-03 12:31:39 -05:00
|
|
|
task = get_object_or_404(tool.task_set, slug=task_slug)
|
|
|
|
events = task.event_set.all()
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
2020-12-22 15:32:58 -05:00
|
|
|
if request.user.is_authenticated:
|
|
|
|
event = Event(task=task)
|
2020-12-24 15:30:45 -05:00
|
|
|
form = EventForm(request.POST, user=request.user, instance=event)
|
2020-12-22 15:32:58 -05:00
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2021-05-24 23:12:01 -04:00
|
|
|
form = EventForm(user=request.user)
|
2020-12-22 15:32:58 -05:00
|
|
|
else:
|
|
|
|
form = EventForm(request.POST)
|
|
|
|
form.add_error(None, "Not authenticated: please login")
|
2020-12-03 12:31:39 -05:00
|
|
|
else:
|
2020-12-24 15:30:45 -05:00
|
|
|
form = EventForm(user=request.user)
|
2020-12-03 12:31:39 -05:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'tool': tool,
|
|
|
|
'task': task,
|
|
|
|
'events': events,
|
|
|
|
'form': form,
|
|
|
|
}
|
2021-05-22 11:51:05 -04:00
|
|
|
|
|
|
|
if request.user.is_authenticated:
|
|
|
|
context.update({
|
|
|
|
'task_subs': task.grouptasksubscription_set.filter(group__user=request.user),
|
|
|
|
'tool_subs': tool.grouptoolsubscription_set.filter(group__user=request.user),
|
|
|
|
})
|
2022-01-23 23:01:47 -05:00
|
|
|
return render(request, 'tasks/taskDetail.dj.html', context)
|