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,10 +17,7 @@
</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" %}
{% 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>
@ -63,7 +60,6 @@
</div>
</li>
{% endfor %}
{% endfor %}
</ul>
<h3 class="text-center">
{% if date_previous %}

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