diff --git a/core/views/uploads.py b/core/views/uploads.py index d1d4402..0041769 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -60,6 +60,8 @@ def create_new_lbe_slug(date): def store_edited_entry_into_database(date, place, title, text, others, author, tu, slug): """saves a single logbook entry and related personlogentry items + need to select out *guest and foreign friends from others + Rather similar to similarly named function in parsers/logbooks but circular reference prevents us using it directly, and they need refactoring anyway. """ @@ -81,7 +83,8 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t "expedition": expedition, "time_underground": tu, "cave_slug": str(cave), - "title": f"{place} - {title}" + "title": f"{place} - {title}", + # "other_people": others } lookupAttribs = {"slug": slug, "date": date } @@ -91,32 +94,41 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t # These entities have to be PersonExpedition objects team = others.split(",") team.append(author) + + odds = [] for name in team: name = name.strip() - if len(name) > 0 and name[0] != "*": # a name prefix of "*" is special, just a string. - try: - personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower()) - if not personyear: - if known_foreigner(name): - message = f" ! - Known foreigner: '{name}' in entry {slug=}" - print(message) - else: - message = f" ! - No name match for: '{name}' in entry {slug=}" - print(message) - DataIssue.objects.create(parser="logbooks", message=message) - else: - lookupAttribs = {"personexpedition": personyear, "nickname_used": name, "logbook_entry": lbo} # lbo is primary key - nonLookupAttribs = {"time_underground": tu, "is_logbook_entry_author": (name==author)} - pt_list.append(PersonLogEntry(**nonLookupAttribs, **lookupAttribs)) + if len(name) > 0: + if name[0] == "*": # a name prefix of "*" is special, just a string. + odds.append(name) + else: + try: + personyear = GetPersonExpeditionNameLookup(expedition).get(name.lower()) + if not personyear: + odds.append(name) + if known_foreigner(name): + message = f" ! - Known foreigner: '{name}' in entry {slug=}" + print(message) + else: + message = f" ! - No name match for: '{name}' in entry {slug=}" + print(message) + DataIssue.objects.create(parser="logbooks", message=message) + else: + lookupAttribs = {"personexpedition": personyear, "nickname_used": name, "logbook_entry": lbo} # lbo is primary key + nonLookupAttribs = {"time_underground": tu, "is_logbook_entry_author": (name==author)} + pt_list.append(PersonLogEntry(**nonLookupAttribs, **lookupAttribs)) - except: - # This should not happen. We do not raise exceptions in that function - message = f" ! - EXCEPTION: '{name}' in entry {slug=}" - print(message) - DataIssue.objects.create(parser="logbooks", message=message) - raise + except: + # This should not happen. We do not raise exceptions in that function + message = f" ! - EXCEPTION: '{name}' in entry {slug=}" + print(message) + DataIssue.objects.create(parser="logbooks", message=message) + raise PersonLogEntry.objects.bulk_create(pt_list) + + lbo.other_people = ", ".join(odds) + lbo.save() class FilesForm(forms.Form): # not a model-form, just a form-form uploadfiles = forms.FileField() @@ -204,7 +216,7 @@ def logbookedit(request, year=None, slug=None): print(f"- Rewriting the entire {year} logbook to disc ") filename= "logbook.html" try: - writelogbook(year, filename) # uses a template, not the code fragment below + writelogbook(year, filename) # uses a template, not the code fragment below which is just a visible hint to logged on user except: message = f'! - Logbook saving failed - \n!! Permissions failure ?! on attempting to save file "logbook.html"' print(message)