statistics can load logs from archives
This commit is contained in:
		@ -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:
 | 
			
		||||
 | 
			
		||||
@ -66,6 +66,7 @@
 | 
			
		||||
 | 
			
		||||
<section>
 | 
			
		||||
    <h4 class="title is-4">{% trans "Today" %}</h4>
 | 
			
		||||
    {% with is_thin=True %}
 | 
			
		||||
    {% with hide_schedule=True %}
 | 
			
		||||
    {% with has_headline=False %}
 | 
			
		||||
    <table class="table is-fullwidth has-background-transparent">
 | 
			
		||||
@ -78,6 +79,7 @@
 | 
			
		||||
    </table>
 | 
			
		||||
    {% endwith %}
 | 
			
		||||
    {% endwith %}
 | 
			
		||||
    {% endwith %}
 | 
			
		||||
</section>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
        <td>
 | 
			
		||||
            {% if object|is_diffusion %}
 | 
			
		||||
            <time datetime="{{ object.start }}" title="{{ object.start }}">
 | 
			
		||||
                {{ object.start|date:"H:i" }} - {{ object.end|date:"H:i" }}
 | 
			
		||||
                {{ object.start|date:"H:i" }}
 | 
			
		||||
                {% if not is_thin %} - {{ object.end|date:"H:i" }}{% endif %}
 | 
			
		||||
            </time>
 | 
			
		||||
            {% else %}
 | 
			
		||||
            <time datetime="{{ object.date }}" title="{{ object.date }}">
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _
 | 
			
		||||
from django.views.generic import ListView
 | 
			
		||||
 | 
			
		||||
from .log import LogListView
 | 
			
		||||
from ..models.log import LogArchiver
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__all__ = ['BaseAdminView', 'StatisticsView']
 | 
			
		||||
@ -33,6 +34,8 @@ class StatisticsView(BaseAdminView, LogListView, ListView):
 | 
			
		||||
    date = None
 | 
			
		||||
 | 
			
		||||
    def get_object_list(self, logs, *_):
 | 
			
		||||
        if not logs.exists():
 | 
			
		||||
            logs = LogArchiver().load(self.station, self.date) if self.date else []
 | 
			
		||||
        return super().get_object_list(logs, True)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user