2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-12-12 03:22:18 +00:00

Fix the order of participants in a logbook entry

This commit is contained in:
Philip Sargent 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)

View File

@ -9,6 +9,10 @@
</head>
<!-- Exported by troggle because one entry has been edited, and we reconstruct the whole thing.
As of 10 Dec.2024 the list of participants in every trip is re-ordered to be in alphabetic
order of name (or nickname, if used) whenever any entry is edited and the logbook.html file
re-written. This is prevent spurious re-orderings and spurious git commit lines which obscure real changes.
Sorry about all the crap that surrounds the image tags which has been imported along with the content
when UK Caving blogs have been parsed.
@ -16,16 +20,14 @@ Exported on {% now 'Y-m-d H:m' %} using either the control panel webpage or when
See troggle/code/views/other.py and core.models/logbooks.py writelogbook(year, filename)
-->
<body>
{%for logbook_entry in logbook_entries%}
<hr />
{%for logbook_entry in logbook_entries%}<hr />
<div class="tripdate" id="{{logbook_entry.slug}}">{{logbook_entry.date|date:'Y-m-d'}}</div>
<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>
<div class="trippeople">{{logbook_entry.get_participants|safe}}</div>
<div class="triptitle">{{logbook_entry.title|safe}}</div>
{{logbook_entry.text|safe}}
<div class="timeug">T/U: {{logbook_entry.time_underground|safe}} hours</div>
<div class="editentry"><br /><a href="/logbookedit/{{logbook_entry.slug}}">Edit this entry</a><br /></div>
{% endfor %}
<hr />
{% endfor %}<hr />
</body>
</html>