Files
@ 6b41b5c4773c
Branch filter:
Location: symposion_app/symposion/schedule/timetable.py - annotation
6b41b5c4773c
1.6 KiB
text/x-python
Don't show unpublished schedule info to non-staff.
Add checks to schedule_list, schedule_list_csv, and
schedule_presentation_detail views to verify that either schedule is
published or that current user is staff before displaying information.
See c7592bc33e2626d84ec46fe1e7ba8e05c73ef74c.
Add checks to schedule_list, schedule_list_csv, and
schedule_presentation_detail views to verify that either schedule is
published or that current user is staff before displaying information.
See c7592bc33e2626d84ec46fe1e7ba8e05c73ef74c.
a95825ede8d4 f3e9cc9a5db3 f3e9cc9a5db3 b7e8e7da8cb3 2c954c3a055b 2c954c3a055b 7601791e8cd0 f3e9cc9a5db3 14f43da962a8 36ab6d599ffc f3e9cc9a5db3 f3e9cc9a5db3 36ab6d599ffc f3e9cc9a5db3 2c954c3a055b 2c954c3a055b 2c954c3a055b 36ab6d599ffc f3e9cc9a5db3 2c954c3a055b 2c954c3a055b 36ab6d599ffc 36ab6d599ffc 2c954c3a055b 2c954c3a055b 36ab6d599ffc f3e9cc9a5db3 f3e9cc9a5db3 b7e8e7da8cb3 b7e8e7da8cb3 b7e8e7da8cb3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 14f43da962a8 2c954c3a055b f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 36ab6d599ffc f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 f3e9cc9a5db3 | from __future__ import unicode_literals
import itertools
from django.db.models import Count, Min
from symposion.schedule.models import Room, Slot, SlotRoom
class TimeTable(object):
def __init__(self, day):
self.day = day
def slots_qs(self):
qs = Slot.objects.all()
qs = qs.filter(day=self.day)
return qs
def rooms(self):
qs = Room.objects.all()
qs = qs.filter(schedule=self.day.schedule)
qs = qs.filter(
pk__in=SlotRoom.objects.filter(slot__in=self.slots_qs().values("pk")).values("room"))
qs = qs.order_by("order")
return qs
def __iter__(self):
times = sorted(set(itertools.chain(*self.slots_qs().values_list("start", "end"))))
slots = Slot.objects.filter(pk__in=self.slots_qs().values("pk"))
slots = slots.annotate(room_count=Count("slotroom"), order=Min("slotroom__room__order"))
slots = slots.order_by("start", "order")
row = []
for time, next_time in pairwise(times):
row = {"time": time, "slots": []}
for slot in slots:
if slot.start == time:
slot.rowspan = TimeTable.rowspan(times, slot.start, slot.end)
slot.colspan = slot.room_count
row["slots"].append(slot)
if row["slots"] or next_time is None:
yield row
@staticmethod
def rowspan(times, start, end):
return times.index(end) - times.index(start)
def pairwise(iterable):
a, b = itertools.tee(iterable)
b.next()
return itertools.izip_longest(a, b)
|