2010-09-26 21:32:53 +00:00
|
|
|
def organize_media_by_event(eventmedia_queryset):
|
|
|
|
"""Organizes event media by event.
|
|
|
|
|
|
|
|
Given a queryset of event media, it returns a list of 'objects'
|
|
|
|
with the following properties:
|
|
|
|
|
|
|
|
* event (event object)
|
|
|
|
* date (date object for most recently posted media from event)
|
|
|
|
* media_list (a string of the available media types)
|
|
|
|
"""
|
|
|
|
|
|
|
|
media_by_event = {}
|
|
|
|
for media in eventmedia_queryset:
|
|
|
|
media_by_event.setdefault(media.event.id, []).append(media)
|
|
|
|
mbe = [{'event': x[0].event,
|
|
|
|
'date': max(y.date_created for y in x),
|
2023-09-07 13:15:48 +00:00
|
|
|
'media_list': ', '.join({y.get_format_display() for y in x})}
|
2021-11-29 20:55:45 +00:00
|
|
|
for x in list(media_by_event.values())]
|
2010-09-26 21:32:53 +00:00
|
|
|
mbe.sort(key=(lambda x: x['date']), reverse=True) # sort by date
|
|
|
|
return mbe
|