def get_categorized_talks(self): category_map = OrderedDefaultDict(list) proposals = (self.get_queryset().prefetch_related( Prefetch( 'additionalspeaker_set', queryset=(AdditionalSpeaker.objects.filter( cancelled=False).select_related('user')), to_attr='_additional_speakers', ))) for proposal in proposals: category_map[proposal.get_category_display()].append(proposal) return category_map
def get_day_grouped_events(self): begin_time_event_dict = collections.defaultdict(set) for qs in self.event_querysets: for event in qs.select_related('begin_time', 'end_time'): begin_time_event_dict[event.begin_time].add(event) day_info_dict = collections.OrderedDict( (date, { 'name': name, 'rooms': set(), 'slots': OrderedDefaultDict(dict), }) for date, name in settings.EVENTS_DAY_NAMES.items()) def room_key(room): return room.split('-', 1)[-1] times = list(Time.objects.order_by('value')) end_time_iter = iter(times) try: next(end_time_iter) except StopIteration: # Nothing at all. return day_info_dict for begin, end in zip(times, end_time_iter): try: day_info = day_info_dict[begin.value.date()] except KeyError: logger.warn('Invalid time sot dropped: {}'.format(begin)) continue for event in begin_time_event_dict[begin]: location = event.location if location in EVENT_ROOMS: day_info['rooms'].add(location) day_info['slots'][(begin, end)][location] = event for info in day_info_dict.values(): # Sort rooms. info['rooms'] = sorted(info['rooms'], key=room_key) # Work around Django template unable to iter through defaultdict. # http://stackoverflow.com/questions/4764110 info['slots'] = collections.OrderedDict( (slot_time, sorted(slot_rooms.items(), key=lambda i: room_key(i[0]))) for slot_time, slot_rooms in info['slots'].items()) return day_info_dict
def get_categorized_talks(self): category_map = OrderedDefaultDict(list) for proposal in self.queryset: category_map[proposal.get_category_display()].append(proposal) return category_map