diff --git a/estusshots/util.py b/estusshots/util.py index 6e2662b..94dcb37 100644 --- a/estusshots/util.py +++ b/estusshots/util.py @@ -37,6 +37,19 @@ def timedelta_to_str(data: timedelta) -> str: ) +def by_time(e): + """ + Custom sort key for sorting by time codes in the format HH:MM + This version sorts codes with hour '00' after '23' + """ + if not hasattr(e, "time") or isinstance(e.time, time): + return id(e) + + if e.time.hour == 0: + return f"24{e.time.minute}" + return f"{e.time.hour}{e.time.minute}" + + def compute_timedelta(start: time, end: time) -> float: if not start or not end: return 0 diff --git a/estusshots/views/episodes.py b/estusshots/views/episodes.py index 0dc044c..add49cc 100644 --- a/estusshots/views/episodes.py +++ b/estusshots/views/episodes.py @@ -2,7 +2,7 @@ from flask import render_template, request, redirect, url_for from estusshots import app from estusshots import forms, orm -from estusshots.util import authorize +from estusshots.util import authorize, by_time from estusshots.orm import Season, Episode, Player @@ -18,8 +18,8 @@ def episode_detail(season_id: int, episode_id: int): "episode": episode, "season": episode.season, "players": episode.players, - "deaths": sorted(deaths, key=lambda x: x.time), - "victories": sorted(victories, key=lambda x: x.time) + "deaths": sorted(deaths, key=by_time), + "victories": sorted(victories, key=by_time) } return render_template("episode_details.html", model=model)