Ben Sturmfels
531a97a3c9
The directory nesting is unnecessary here and confusing to navigate. I've moved all apps to the project subdirectory, currently called "www", but soon to be renamed "conservancy". I've also moved manage.py to the top-level directory.
20 lines
778 B
Python
20 lines
778 B
Python
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),
|
|
'media_list': ', '.join({y.get_format_display() for y in x})}
|
|
for x in list(media_by_event.values())]
|
|
mbe.sort(key=(lambda x: x['date']), reverse=True) # sort by date
|
|
return mbe
|