From 09d0cab206a659decb4c482f0bdb98bc84b11c71 Mon Sep 17 00:00:00 2001 From: bkfox Date: Sun, 31 May 2020 20:07:37 +0200 Subject: [PATCH] statistics can load logs from archives --- aircox/models/log.py | 9 +++++++-- aircox/templates/aircox/home.html | 2 ++ aircox/templates/aircox/widgets/log_list.html | 4 +++- aircox/views/admin.py | 3 +++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/aircox/models/log.py b/aircox/models/log.py index 7f4f5a0..e5ff73c 100644 --- a/aircox/models/log.py +++ b/aircox/models/log.py @@ -154,9 +154,14 @@ class Log(models.Model): @classmethod def merge_diffusions(cls, logs, diffs, count=None): + """ + Merge logs and diffusions together. `logs` can either be a queryset + or a list ordered by `Log.date`. + """ # TODO: limit count # FIXME: log may be iterable (in stats view) - logs = list(logs.order_by('-date')) + if isinstance(logs, models.QuerySet): + logs = list(logs.order_by('-date')) diffs = deque(diffs.on_air().before().order_by('-start')) object_list = [] @@ -171,7 +176,7 @@ class Log(models.Model): diff = diffs.popleft() - # - takes all logs after diff + # - takes all logs after diff start index = next((i for i, v in enumerate(logs) if v.date <= diff.end), len(logs)) if index is not None and index > 0: diff --git a/aircox/templates/aircox/home.html b/aircox/templates/aircox/home.html index 4d50e44..46fb3e3 100644 --- a/aircox/templates/aircox/home.html +++ b/aircox/templates/aircox/home.html @@ -66,6 +66,7 @@

{% trans "Today" %}

+ {% with is_thin=True %} {% with hide_schedule=True %} {% with has_headline=False %} @@ -78,6 +79,7 @@
{% endwith %} {% endwith %} + {% endwith %}
{% endblock %} diff --git a/aircox/templates/aircox/widgets/log_list.html b/aircox/templates/aircox/widgets/log_list.html index f7aeb25..60d57db 100644 --- a/aircox/templates/aircox/widgets/log_list.html +++ b/aircox/templates/aircox/widgets/log_list.html @@ -3,6 +3,7 @@ Render list of logs (as widget). Context: - object_list: list of logs to display +- is_thin: if True, hide some information in order to fit in a thin container {% endcomment %} {% load aircox %} @@ -13,7 +14,8 @@ Context: {% if object|is_diffusion %} {% else %}