From 555cb63be34ba57a7c83beb8f932da0b255ea79d Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Tue, 10 Dec 2024 21:29:05 +0000 Subject: [PATCH] Fix the order of participants in a logbook entry --- core/models/logbooks.py | 32 ++++++++++++++++++++++++++++++++ templates/logbook2005style.html | 12 +++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/core/models/logbooks.py b/core/models/logbooks.py index 5b6c469..d635bf5 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -53,6 +53,38 @@ class LogbookEntry(TroggleModel): def __str__(self): return f"{self.date}: {self.title}" + def get_participants(self): + '''the string that goes into an edited or rewritten logbook entry + which replaces this horrendous Django template code: + +
{% for personlogentry in logbook_entry.personlogentry_set.all %}{% if personlogentry.is_logbook_entry_author %}{% if personlogentry.nickname_used %}{{personlogentry.nickname_used|safe}}{% else %}{{personlogentry.personexpedition.person|safe}}{% endif %},{% endif %}{% endfor %}{% for personlogentry in logbook_entry.personlogentry_set.all %}{% if personlogentry.is_logbook_entry_author %}{% else %}{% if personlogentry.nickname_used %}{{personlogentry.nickname_used|safe}}{% else %}{{personlogentry.personexpedition.person|safe}}{% endif %},{% endif %}{% endfor %}{% if logbook_entry.other_people %}, {{logbook_entry.other_people}}{% endif %}
+ ''' + author = ( + PersonLogEntry.objects.filter(logbook_entry=self, is_logbook_entry_author=True) + .first() + ) + if author.nickname_used: + expoer = author.nickname_used + else: + expoer = author.personexpedition.person.name() + names = f"{expoer}" + + participants = ( + PersonLogEntry.objects.filter(logbook_entry=self, is_logbook_entry_author=False) + .order_by("personexpedition__person__slug") + .all() + ) + for p in participants: + if p.nickname_used: + expoer = p.nickname_used + else: + expoer = p.personexpedition.person.name() + names += f",{expoer}" + + if self.other_people: + names += f",{self.other_people}" + return names + def get_next_by_id(self): LogbookEntry.objects.get(id=self.id + 1) diff --git a/templates/logbook2005style.html b/templates/logbook2005style.html index ce5f5bb..872ee4c 100644 --- a/templates/logbook2005style.html +++ b/templates/logbook2005style.html @@ -9,6 +9,10 @@ -{%for logbook_entry in logbook_entries%} -
+{%for logbook_entry in logbook_entries%}
{{logbook_entry.date|date:'Y-m-d'}}
-
{% for personlogentry in logbook_entry.personlogentry_set.all %}{% if personlogentry.is_logbook_entry_author %}{% if personlogentry.nickname_used %}{{personlogentry.nickname_used|safe}}{% else %}{{personlogentry.personexpedition.person|safe}}{% endif %},{% endif %}{% endfor %}{% for personlogentry in logbook_entry.personlogentry_set.all %}{% if personlogentry.is_logbook_entry_author %}{% else %}{% if personlogentry.nickname_used %}{{personlogentry.nickname_used|safe}}{% else %}{{personlogentry.personexpedition.person|safe}}{% endif %},{% endif %}{% endfor %}{% if logbook_entry.other_people %}, {{logbook_entry.other_people}}{% endif %}
+
{{logbook_entry.get_participants|safe}}
{{logbook_entry.title|safe}}
{{logbook_entry.text|safe}}
T/U: {{logbook_entry.time_underground|safe}} hours

Edit this entry
-{% endfor %} -
+{% endfor %}