summaryrefslogtreecommitdiffstats
path: root/core/models/logbooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/models/logbooks.py')
-rw-r--r--core/models/logbooks.py32
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)