2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 09:22:32 +00:00

recover from missing letter field

This commit is contained in:
Philip Sargent 2023-08-03 11:48:03 +03:00
parent a0f85454f8
commit 0efdfe66d5

View File

@ -506,6 +506,14 @@ def read_cave(filename, cave=None):
print(message) print(message)
letter = getXML(e, "letter", maxItems=1, context=context)[0] letter = getXML(e, "letter", maxItems=1, context=context)[0]
if len(entrances) > 1 and letter =="":
# user error, but we can recover
letter = eslug[-1].lower()
message = f"- Warning - duplicate entrance or empty 'letter' field for '{eslug}' in cave '{cave}', setting to {letter}."
DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/")
print(message)
if len(entrances) == 1 and not eslug: # may be empty: <entranceslug></entranceslug> if len(entrances) == 1 and not eslug: # may be empty: <entranceslug></entranceslug>
msg="DUMMY: no entrance slug read from file, so assume textually same as cave slug" msg="DUMMY: no entrance slug read from file, so assume textually same as cave slug"
set_dummy_entrance(slug[5:], slug, c, msg=msg) set_dummy_entrance(slug[5:], slug, c, msg=msg)
@ -520,8 +528,8 @@ def read_cave(filename, cave=None):
entrance = Entrance.objects.get(slug=eslug) entrance = Entrance.objects.get(slug=eslug)
entrances_xslug[eslug] = entrance entrances_xslug[eslug] = entrance
except: except:
message = f"! eslug {eslug} Abort entrance loading. Failed to find entrance in db" message = f"! Fail entrance loading {eslug} /entrance_data/{eslug} file does not exist or loading it failed."
DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/")
print(message) print(message)
return return
@ -530,6 +538,7 @@ def read_cave(filename, cave=None):
DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/") DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.area}/{cave.area}-{cave.url}_cave_edit/")
print(message) print(message)
try: try:
# this fails if there is not an unambiguous letter set.
CaveAndEntrance.objects.update_or_create( CaveAndEntrance.objects.update_or_create(
cave=cave, entrance_letter=letter, entrance=entrance cave=cave, entrance_letter=letter, entrance=entrance
) )