cmsmanage/tasks/views.py

52 lines
1.3 KiB
Python
Raw Normal View History

from datetime import datetime
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(),
}
return render(request, 'tasks/index.djhtml', context)
def toolDetail(request, asset_tag):
tool = get_object_or_404(Tool, asset_tag=asset_tag)
tasks = tool.task_set.all()
context = {
'tool': tool,
'tasks': tasks,
}
return render(request, 'tasks/toolDetail.djhtml', context)
def taskDetail(request, asset_tag, task_slug):
tool = get_object_or_404(Tool, asset_tag=asset_tag)
task = get_object_or_404(tool.task_set, slug=task_slug)
events = task.event_set.all()
if request.method == 'POST':
event = Event(task=task)
form = EventForm(request.POST, instance=event)
if form.is_valid():
form.save()
pass
else:
form = EventForm(initial={
'date': datetime.now(),
'user': request.user,
})
context = {
'tool': tool,
'task': task,
'events': events,
'form': form,
}
return render(request, 'tasks/taskDetail.djhtml', context)