2012-08-30 06:52:50 +00:00
|
|
|
from django.http import Http404
|
2012-08-31 04:55:37 +00:00
|
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
2012-08-30 06:21:48 +00:00
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
2012-08-31 04:55:37 +00:00
|
|
|
from symposion.schedule.forms import SlotEditForm
|
2012-08-31 05:50:00 +00:00
|
|
|
from symposion.schedule.models import Schedule, Day, Slot, Presentation
|
2012-08-30 06:52:50 +00:00
|
|
|
from symposion.schedule.timetable import TimeTable
|
2012-08-30 06:21:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def schedule_detail(request, slug=None):
|
|
|
|
qs = Schedule.objects.all()
|
2012-08-31 05:16:30 +00:00
|
|
|
|
2012-08-30 06:23:49 +00:00
|
|
|
if slug is None:
|
2012-08-30 06:21:48 +00:00
|
|
|
schedule = next(iter(qs), None)
|
|
|
|
if schedule is None:
|
|
|
|
raise Http404()
|
|
|
|
else:
|
|
|
|
schedule = get_object_or_404(qs, slug=slug)
|
2012-08-31 05:16:30 +00:00
|
|
|
|
2012-08-30 06:21:48 +00:00
|
|
|
ctx = {
|
|
|
|
"schedule": schedule,
|
|
|
|
}
|
2012-08-30 06:52:50 +00:00
|
|
|
return render(request, "schedule/schedule_detail.html", ctx)
|
2012-08-30 06:21:48 +00:00
|
|
|
|
|
|
|
|
2012-08-31 05:50:00 +00:00
|
|
|
def schedule_list(request):
|
|
|
|
presentations = Presentation.objects.order_by("id")
|
|
|
|
ctx = {
|
|
|
|
"presentations": presentations,
|
|
|
|
}
|
|
|
|
return render(request, "schedule/schedule_list.html", ctx)
|
|
|
|
|
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
@login_required
|
2012-08-30 06:21:48 +00:00
|
|
|
def schedule_edit(request, slug=None):
|
2012-08-31 05:16:30 +00:00
|
|
|
|
|
|
|
if not request.user.is_staff:
|
|
|
|
raise Http404()
|
|
|
|
|
2012-08-30 06:21:48 +00:00
|
|
|
qs = Schedule.objects.all()
|
2012-08-31 05:16:30 +00:00
|
|
|
|
2012-08-30 06:23:49 +00:00
|
|
|
if slug is None:
|
2012-08-30 06:21:48 +00:00
|
|
|
schedule = next(iter(qs), None)
|
|
|
|
if schedule is None:
|
|
|
|
raise Http404()
|
|
|
|
else:
|
|
|
|
schedule = get_object_or_404(qs, slug=slug)
|
2012-08-31 05:16:30 +00:00
|
|
|
|
2012-08-30 06:51:07 +00:00
|
|
|
days_qs = Day.objects.filter(schedule=schedule)
|
|
|
|
days = [TimeTable(day) for day in days_qs]
|
2012-08-31 04:55:37 +00:00
|
|
|
form = SlotEditForm()
|
2012-08-30 06:21:48 +00:00
|
|
|
ctx = {
|
|
|
|
"schedule": schedule,
|
2012-08-30 06:51:07 +00:00
|
|
|
"days": days,
|
2012-08-31 04:55:37 +00:00
|
|
|
"form": form,
|
2012-08-30 06:21:48 +00:00
|
|
|
}
|
2012-08-30 06:52:50 +00:00
|
|
|
return render(request, "schedule/schedule_edit.html", ctx)
|
2012-08-31 04:55:37 +00:00
|
|
|
|
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
@login_required
|
2012-08-31 04:55:37 +00:00
|
|
|
def schedule_slot_edit(request, slot_pk):
|
2012-08-31 05:16:30 +00:00
|
|
|
|
|
|
|
if not request.user.is_staff:
|
|
|
|
raise Http404()
|
|
|
|
|
2012-08-31 04:55:37 +00:00
|
|
|
slot = get_object_or_404(Slot, pk=slot_pk)
|
|
|
|
form = SlotEditForm(request.POST)
|
|
|
|
|
|
|
|
if form.is_valid():
|
2012-08-31 05:07:30 +00:00
|
|
|
presentation = form.cleaned_data["presentation"]
|
2012-08-31 04:55:37 +00:00
|
|
|
presentation.slot = slot
|
|
|
|
presentation.save()
|
2012-08-31 05:07:38 +00:00
|
|
|
return redirect("schedule_edit_singleton")
|