2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-02-08 07:28:45 +00:00

fixed bug/exception

This commit is contained in:
2026-01-29 13:04:56 +00:00
parent c2818b4c97
commit 647e8f5698

View File

@@ -20,6 +20,8 @@ from troggle.core.utils import TROG, current_expo, add_commit, git_commit, git_a
from troggle.parsers.imports import import_logbook from troggle.parsers.imports import import_logbook
from troggle.parsers.people import ensure_users_are_persons from troggle.parsers.people import ensure_users_are_persons
from .auth import login_required_if_public
"""These views are for logbook items when they appear in an 'expedition' page """These views are for logbook items when they appear in an 'expedition' page
and for persons: their individual pages and their perseonexpedition pages. and for persons: their individual pages and their perseonexpedition pages.
@@ -368,17 +370,21 @@ def logbookentry(request, date, slug):
print(msg) print(msg)
return render(request, "errors/generic.html", {"message": msg}) return render(request, "errors/generic.html", {"message": msg})
@login_required_if_public
def logbookfile(request, year): def logbookfile(request, year):
"""This was just a link to logbook.html, an ordinary HTML file handbook-style, but in Nov.2025 we """This was just a link to logbook.html, an ordinary HTML file handbook-style, but in Nov.2025 we
changed to have individual JSON files per entry. So this "whole logbook" is now only changed to have individual JSON files per entry. So this "whole logbook" is now only
re-generated when anyone want to see it. re-generated when anyone want to see it.
Since this creates a bit of work on the server, and spambots tend to hit it,
it has been put behind a logon requirement.
""" """
json_entries_dir = settings.EXPOWEB / "years" / year / settings.JSON_LOG_ENTRIES json_entries_dir = settings.EXPOWEB / "years" / year / settings.JSON_LOG_ENTRIES
exp = Expedition.objects.get(year=year) exp = Expedition.objects.get(year=year)
if json_entries_dir.is_dir(): # only 2025 currently, or the current expo if json_entries_dir.is_dir(): # only 2024-6 currently, or the current expo
# Re-generate the logbook.html because it won't have been done by # Re-generate the logbook.html because it won't have been done by
# indovidual entry edits for this year # indovidual entry edits for this year
contents_path = settings.EXPOWEB / "years" / year / exp.logbookfile contents_path = settings.EXPOWEB / "years" / year / exp.logbookfile
try: try:
print(f" - Logbook for {year} to be exported and written out.") print(f" - Logbook for {year} to be exported and written out.")
@@ -441,21 +447,24 @@ def write_entries_json(entries, year, editor):
we need to use a custom serializer instead of just "json.dump() we need to use a custom serializer instead of just "json.dump()
""" """
# This fails if the author is not on the expo
try:
author_link = PersonLogEntry.objects.select_related('personexpedition').get( author_link = PersonLogEntry.objects.select_related('personexpedition').get(
logbook_entry=le, logbook_entry=le,
is_logbook_entry_author=True is_logbook_entry_author=True
) )
author = author_link.personexpedition.person author = author_link.personexpedition.person
author_data = model_to_dict(author, fields=['slug']) author_data = model_to_dict(author, fields=['slug'])
author_data["nickname"] = author_link.nickname_used author_data["nickname"] = author_link.nickname_used
except Exception as e:
author_data = {}
author_data["tu"] = le.time_underground author_data["tu"] = le.time_underground
participants_links = PersonLogEntry.objects.select_related('personexpedition').filter( participants_links = PersonLogEntry.objects.select_related('personexpedition').filter(
logbook_entry=le, logbook_entry=le,
is_logbook_entry_author=False is_logbook_entry_author=False
) )
participants = [author_data] # the author also appears in teh participants list participants = [author_data] # the author also appears in the participants list
for pl in participants_links: for pl in participants_links:
particpant_dict = model_to_dict(pl.personexpedition.person, fields=['slug']) particpant_dict = model_to_dict(pl.personexpedition.person, fields=['slug'])
particpant_dict["nickname"] = pl.nickname_used particpant_dict["nickname"] = pl.nickname_used