Alternative implementation for item ordering

This commit is contained in:
Paul Konstantin Gerke 2022-01-17 15:58:25 +01:00 committed by Christopher Charbonneau Wells
parent 847125b1c6
commit d34814260f
2 changed files with 46 additions and 46 deletions

View File

@ -17,52 +17,48 @@
</h3>
{% if timeline_objects %}
<ul class="timeline m-auto">
{% regroup timeline_objects by time as timeline_moments %}
{% for moment_objects in timeline_moments %}
{% for object in moment_objects.list|dictsort:"type" %}
<li{% cycle "" ' class="timeline-inverted"' %}>
<div class="timeline-badge {% if object.type == "start" %}bg-success{% elif object.type == "end" %}bg-danger{% else %}bg-info{% endif %}">
<i class="icon-{{ object.model_name }}"></i>
{% for object in timeline_objects %}
<li{% cycle "" ' class="timeline-inverted"' %}>
<div class="timeline-badge {% if object.type == "start" %}bg-success{% elif object.type == "end" %}bg-danger{% else %}bg-info{% endif %}">
<i class="icon-{{ object.model_name }}"></i>
</div>
<div class="card text-right">
<div class="card-body">
{{ object.event }}
{% for detail in object.details %}
<div><small>{{ detail }}</small></div>
{% endfor %}
</div>
<div class="card text-right">
<div class="card-body">
{{ object.event }}
{% for detail in object.details %}
<div><small>{{ detail }}</small></div>
{% endfor %}
</div>
<div class="card-footer text-muted">
{% blocktrans trimmed with since=object.time|timesince time=object.time|time %}
{{ since }} ago ({{ time }})
{% endblocktrans %}
{% if object.duration %}
<div>
<small>
{% blocktrans trimmed with duration=object.duration %}
Duration: {{ duration }}
{% endblocktrans %}
</small>
</div>
{% endif %}
{% if object.time_since_prev %}
<div>
<small>
{% blocktrans trimmed with since=object.time_since_prev %}
{{ since }} since previous
{% endblocktrans %}
</small>
</div>
{% endif %}
{% if object.edit_link %}
<div>
<small><a href="{{ object.edit_link }}">{% trans "Edit" %}</a></small>
</div>
{% endif %}
</div>
<div class="card-footer text-muted">
{% blocktrans trimmed with since=object.time|timesince time=object.time|time %}
{{ since }} ago ({{ time }})
{% endblocktrans %}
{% if object.duration %}
<div>
<small>
{% blocktrans trimmed with duration=object.duration %}
Duration: {{ duration }}
{% endblocktrans %}
</small>
</div>
{% endif %}
{% if object.time_since_prev %}
<div>
<small>
{% blocktrans trimmed with since=object.time_since_prev %}
{{ since }} since previous
{% endblocktrans %}
</small>
</div>
{% endif %}
{% if object.edit_link %}
<div>
<small><a href="{{ object.edit_link }}">{% trans "Edit" %}</a></small>
</div>
{% endif %}
</div>
</li>
{% endfor %}
</div>
</li>
{% endfor %}
</ul>
<h3 class="text-center">
@ -82,4 +78,4 @@
</h3>
{% else %}
<div class="text-center">{% trans "No events" %}</div>
{% endif %}
{% endif %}

View File

@ -24,7 +24,11 @@ def get_objects(date, child=None):
_add_tummy_times(min_date, max_date, events, child)
_add_notes(min_date, max_date, events, child)
events.sort(key=lambda x: x['time'], reverse=True)
explicit_type_ordering = {'start': 0, 'end': 1}
events.sort(
key=lambda x: (x['time'], explicit_type_ordering.get(x.get('type'), -1)),
reverse=True,
)
return events