From 647e8f56987e7e578f872000b2fd4b42eb2cf301 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Thu, 29 Jan 2026 13:04:56 +0000 Subject: [PATCH] fixed bug/exception --- core/views/logbooks.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/core/views/logbooks.py b/core/views/logbooks.py index a4662c0..e6802d1 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -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.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 and for persons: their individual pages and their perseonexpedition pages. @@ -368,17 +370,21 @@ def logbookentry(request, date, slug): print(msg) return render(request, "errors/generic.html", {"message": msg}) +@login_required_if_public def logbookfile(request, year): """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 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 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 # indovidual entry edits for this year - contents_path = settings.EXPOWEB / "years" / year / exp.logbookfile try: 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() """ - author_link = PersonLogEntry.objects.select_related('personexpedition').get( - logbook_entry=le, - is_logbook_entry_author=True - ) - author = author_link.personexpedition.person - - author_data = model_to_dict(author, fields=['slug']) - author_data["nickname"] = author_link.nickname_used + # This fails if the author is not on the expo + try: + author_link = PersonLogEntry.objects.select_related('personexpedition').get( + logbook_entry=le, + is_logbook_entry_author=True + ) + author = author_link.personexpedition.person + author_data = model_to_dict(author, fields=['slug']) + author_data["nickname"] = author_link.nickname_used + except Exception as e: + author_data = {} author_data["tu"] = le.time_underground participants_links = PersonLogEntry.objects.select_related('personexpedition').filter( logbook_entry=le, 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: particpant_dict = model_to_dict(pl.personexpedition.person, fields=['slug']) particpant_dict["nickname"] = pl.nickname_used