diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-12-10 21:29:05 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-12-10 21:29:05 +0000 |
commit | 555cb63be34ba57a7c83beb8f932da0b255ea79d (patch) | |
tree | 569277f2265f761c0a744057a71ade826e897a25 /core | |
parent | 8c56a45e7c89f580afc59f670443bc1eb9812e36 (diff) | |
download | troggle-555cb63be34ba57a7c83beb8f932da0b255ea79d.tar.gz troggle-555cb63be34ba57a7c83beb8f932da0b255ea79d.tar.bz2 troggle-555cb63be34ba57a7c83beb8f932da0b255ea79d.zip |
Fix the order of participants in a logbook entry
Diffstat (limited to 'core')
-rw-r--r-- | core/models/logbooks.py | 32 |
1 files changed, 32 insertions, 0 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: + + <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) |