2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 11:21:26 +00:00

Fix the order of participants in a logbook entry

This commit is contained in:
2024-12-10 21:29:05 +00:00
parent 8c56a45e7c
commit 555cb63be3
2 changed files with 39 additions and 5 deletions

View File

@@ -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:
<div class="trippeople">{% for personlogentry in logbook_entry.personlogentry_set.all %}{% if personlogentry.is_logbook_entry_author %}<u>{% if personlogentry.nickname_used %}{{personlogentry.nickname_used|safe}}{% else %}{{personlogentry.personexpedition.person|safe}}{% endif %}</u>,{% 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 %}</div>
'''
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"<u>{expoer}</u>"
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)