2012-10-09 19:07:55 +00:00
|
|
|
from django.http import Http404, HttpResponse
|
2012-08-31 04:55:37 +00:00
|
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
2012-10-09 19:07:55 +00:00
|
|
|
from django.template import loader, Context
|
2012-08-30 06:21:48 +00:00
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2014-02-28 15:55:54 +00:00
|
|
|
from django.contrib import messages
|
2012-08-31 05:16:30 +00:00
|
|
|
|
2014-02-28 15:55:54 +00:00
|
|
|
from symposion.schedule.forms import SlotEditForm, ScheduleSectionForm
|
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
|
|
|
|
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
def fetch_schedule(slug):
|
2012-08-30 06:21:48 +00:00
|
|
|
qs = Schedule.objects.all()
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-08-30 06:23:49 +00:00
|
|
|
if slug is None:
|
2012-09-21 02:38:24 +00:00
|
|
|
if qs.count() > 1:
|
|
|
|
raise Http404()
|
2012-08-30 06:21:48 +00:00
|
|
|
schedule = next(iter(qs), None)
|
|
|
|
if schedule is None:
|
|
|
|
raise Http404()
|
|
|
|
else:
|
2012-09-20 02:03:30 +00:00
|
|
|
schedule = get_object_or_404(qs, section__slug=slug)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
return schedule
|
|
|
|
|
|
|
|
|
2012-12-20 06:49:32 +00:00
|
|
|
def schedule_conference(request):
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2013-01-29 08:13:41 +00:00
|
|
|
schedules = Schedule.objects.filter(published=True, hidden=False)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-12-20 06:49:32 +00:00
|
|
|
sections = []
|
|
|
|
for schedule in schedules:
|
|
|
|
days_qs = Day.objects.filter(schedule=schedule)
|
|
|
|
days = [TimeTable(day) for day in days_qs]
|
|
|
|
sections.append({
|
|
|
|
"schedule": schedule,
|
|
|
|
"days": days,
|
|
|
|
})
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-12-20 06:49:32 +00:00
|
|
|
ctx = {
|
|
|
|
"sections": sections,
|
|
|
|
}
|
|
|
|
return render(request, "schedule/schedule_conference.html", ctx)
|
|
|
|
|
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
def schedule_detail(request, slug=None):
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
schedule = fetch_schedule(slug)
|
2013-01-29 08:13:41 +00:00
|
|
|
if not schedule.published and not request.user.is_staff:
|
|
|
|
raise Http404()
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-21 01:42:03 +00:00
|
|
|
days_qs = Day.objects.filter(schedule=schedule)
|
|
|
|
days = [TimeTable(day) for day in days_qs]
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-08-30 06:21:48 +00:00
|
|
|
ctx = {
|
|
|
|
"schedule": schedule,
|
2012-09-21 01:42:03 +00:00
|
|
|
"days": days,
|
2012-08-30 06:21:48 +00:00
|
|
|
}
|
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-09-20 02:03:30 +00:00
|
|
|
def schedule_list(request, slug=None):
|
|
|
|
schedule = fetch_schedule(slug)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
presentations = Presentation.objects.filter(section=schedule.section)
|
2012-12-20 06:53:22 +00:00
|
|
|
presentations = presentations.exclude(cancelled=True)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-08-31 05:50:00 +00:00
|
|
|
ctx = {
|
2012-09-20 02:06:15 +00:00
|
|
|
"schedule": schedule,
|
2012-08-31 05:50:00 +00:00
|
|
|
"presentations": presentations,
|
|
|
|
}
|
|
|
|
return render(request, "schedule/schedule_list.html", ctx)
|
|
|
|
|
|
|
|
|
2012-10-09 19:07:55 +00:00
|
|
|
def schedule_list_csv(request, slug=None):
|
|
|
|
schedule = fetch_schedule(slug)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-10-09 19:07:55 +00:00
|
|
|
presentations = Presentation.objects.filter(section=schedule.section)
|
|
|
|
presentations = presentations.exclude(cancelled=True).order_by("id")
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2014-01-15 14:05:08 +00:00
|
|
|
response = HttpResponse(content_type="text/csv")
|
2012-10-09 19:07:55 +00:00
|
|
|
if slug:
|
|
|
|
file_slug = slug
|
|
|
|
else:
|
|
|
|
file_slug = "presentations"
|
|
|
|
response["Content-Disposition"] = 'attachment; filename="%s.csv"' % file_slug
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-10-09 19:07:55 +00:00
|
|
|
response.write(loader.get_template("schedule/schedule_list.csv").render(Context({
|
|
|
|
"presentations": presentations,
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-10-09 19:07:55 +00:00
|
|
|
})))
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
@login_required
|
2012-08-30 06:21:48 +00:00
|
|
|
def schedule_edit(request, slug=None):
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
if not request.user.is_staff:
|
|
|
|
raise Http404()
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
schedule = fetch_schedule(slug)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2014-02-28 15:55:54 +00:00
|
|
|
if request.method == "POST":
|
|
|
|
form = ScheduleSectionForm(
|
|
|
|
request.POST, request.FILES, schedule=schedule
|
|
|
|
)
|
|
|
|
if form.is_valid():
|
|
|
|
if 'submit' in form.data:
|
|
|
|
msg = form.build_schedule()
|
|
|
|
elif 'delete' in form.data:
|
|
|
|
msg = form.delete_schedule()
|
|
|
|
messages.add_message(request, msg[0], msg[1])
|
|
|
|
else:
|
|
|
|
form = ScheduleSectionForm(schedule=schedule)
|
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-30 06:21:48 +00:00
|
|
|
ctx = {
|
|
|
|
"schedule": schedule,
|
2012-08-30 06:51:07 +00:00
|
|
|
"days": days,
|
2014-02-28 15:55:54 +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-09-20 02:03:30 +00:00
|
|
|
def schedule_slot_edit(request, slug, slot_pk):
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-08-31 05:16:30 +00:00
|
|
|
if not request.user.is_staff:
|
|
|
|
raise Http404()
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-20 02:03:30 +00:00
|
|
|
slot = get_object_or_404(Slot, day__schedule__section__slug=slug, pk=slot_pk)
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-14 05:17:32 +00:00
|
|
|
if request.method == "POST":
|
2012-10-26 21:32:03 +00:00
|
|
|
form = SlotEditForm(request.POST, slot=slot)
|
2012-09-14 05:17:32 +00:00
|
|
|
if form.is_valid():
|
2012-10-26 21:32:03 +00:00
|
|
|
save = False
|
|
|
|
if "content_override" in form.cleaned_data:
|
|
|
|
slot.content_override = form.cleaned_data["content_override"]
|
|
|
|
save = True
|
|
|
|
if "presentation" in form.cleaned_data:
|
|
|
|
presentation = form.cleaned_data["presentation"]
|
|
|
|
if presentation is None:
|
|
|
|
slot.unassign()
|
|
|
|
else:
|
|
|
|
slot.assign(presentation)
|
|
|
|
if save:
|
|
|
|
slot.save()
|
2012-12-20 06:54:38 +00:00
|
|
|
return redirect("schedule_edit", slug)
|
2012-09-14 05:17:32 +00:00
|
|
|
else:
|
2012-10-26 21:32:03 +00:00
|
|
|
form = SlotEditForm(slot=slot)
|
2012-09-14 05:17:32 +00:00
|
|
|
ctx = {
|
2012-09-20 02:03:30 +00:00
|
|
|
"slug": slug,
|
2012-09-14 05:17:32 +00:00
|
|
|
"form": form,
|
|
|
|
"slot": slot,
|
|
|
|
}
|
|
|
|
return render(request, "schedule/_slot_edit.html", ctx)
|
2012-09-21 02:38:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def schedule_presentation_detail(request, pk):
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-21 02:38:24 +00:00
|
|
|
presentation = get_object_or_404(Presentation, pk=pk)
|
2013-01-03 08:44:49 +00:00
|
|
|
if presentation.slot:
|
|
|
|
schedule = presentation.slot.day.schedule
|
|
|
|
else:
|
|
|
|
schedule = None
|
2014-01-13 21:49:40 +00:00
|
|
|
|
2012-09-21 02:38:24 +00:00
|
|
|
ctx = {
|
|
|
|
"presentation": presentation,
|
2013-01-03 08:44:49 +00:00
|
|
|
"schedule": schedule,
|
2012-09-21 02:38:24 +00:00
|
|
|
}
|
|
|
|
return render(request, "schedule/presentation_detail.html", ctx)
|