Skip to content

Commit 36c55e1

Browse files
committed
fix(timeline): sort media items in reverse order by end date
1 parent 389c885 commit 36c55e1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/app/statistics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def get_timeline(user_media):
354354
month_year = f"{month_name} {year}"
355355

356356
timeline[month_year].append(media)
357+
357358
# Convert to sorted dictionary with media sorted by start date
358359
# Create a list sorted by year and month in reverse order
359360
sorted_items = []
@@ -370,15 +371,15 @@ def get_timeline(user_media):
370371
result = {}
371372
for month_year, media_list, _, _ in sorted_items:
372373
# Sort the media list using our custom sort key
373-
result[month_year] = sorted(media_list, key=time_line_sort_key)
374+
result[month_year] = sorted(media_list, key=time_line_sort_key, reverse=True)
374375
return result
375376

376377

377378
def time_line_sort_key(media):
378379
"""Sort media items in the timeline."""
379-
if media.start_date is not None:
380-
return timezone.localdate(media.start_date)
381-
return timezone.localdate(media.end_date)
380+
if media.end_date is not None:
381+
return timezone.localdate(media.end_date)
382+
return timezone.localdate(media.start_date)
382383

383384

384385
def get_activity_data(user, start_date, end_date):

0 commit comments

Comments
 (0)