2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

deal with absent uneeded items

This commit is contained in:
Philip Sargent 2024-07-02 10:55:11 +03:00
parent c51f76ed83
commit a6730b1b3a
2 changed files with 38 additions and 21 deletions

View File

@ -712,14 +712,14 @@ def GetCaveLookup():
("loveshack", "1626-2018-ad-03"),
("crushed-garlic", "1626-2018-ad-03"),
# Renaming cave ids which end in a letter
("2002-XX", "1623-2002-FB-01"),
("2002-X09B", "1623-2002-XB09"),
("2007-neu", "1623-2007-NEU-01"),
("BuzzardHole", "1626-2023-BZ-01"),
("2023-BuzzardHole", "1626-2023-BZ-01"),
("1626-2023-BuzzardHole", "1626-2023-BZ-01"),
("1626-2023-buzzardhole","1626-2023-BZ-01"),
# Renaming cave ids which end in a letter NB targets must be LOWER CASE
("2002-XX", "1623-2002-fb-01"),
("2002-X09B", "1623-2002-xb09"),
("2007-neu", "1623-2007-neu-01"),
("BuzzardHole", "1626-2023-Bbz-01"),
("2023-BuzzardHole", "1626-2023-bz-01"),
("1626-2023-BuzzardHole", "1626-2023-bz-01"),
("1626-2023-buzzardhole","1626-2023-bz-01"),
]
@ -737,9 +737,15 @@ def GetCaveLookup():
# Gcave_count[key] += 1
Gcavelookup[key] = Gcavelookup[alias]
else:
message = f" * Coding or cave existence mistake, cave for id '{alias}' does not exist. Expecting to set alias '{key}' to it"
print(message)
DataIssue.objects.update_or_create(parser="aliases", message=message)
if alias.lower() in Gcavelookup:
Gcavelookup[key] = Gcavelookup[alias.lower()]
message = f" - Warning, capitalisation error in alias list. cave for id '{alias}' does not exist but {alias.lower()} does."
print(message)
DataIssue.objects.update_or_create(parser="aliases", message=message)
else:
message = f" * Coding or cave existence mistake, cave for id '{alias}' does not exist. Expecting to set alias '{key}' to it"
print(message)
DataIssue.objects.update_or_create(parser="aliases", message=message)
addmore = {}
for id in Gcavelookup:

View File

@ -464,6 +464,9 @@ def read_entrance(filename, ent=None):
Returns:
The entrance object, or a new entrance object if `ent` is None.
"""
def getXMLmin0(field):
return getXML(entrancecontents, field, minItems=0, maxItems=1, context=context)
def getXMLmax1(field):
return getXML(entrancecontents, field, maxItems=1, context=context)
@ -508,7 +511,7 @@ def read_entrance(filename, ent=None):
return None
entrancecontents = entrancecontentslist[0]
slugs = getXML(entrancecontents, "slug", context=context)
slugs = getXMLmin0("slug")
# we ignore all these, because we now just use the filename. But if they are there, we validate them.
if len(slugs) > 0 :
slug = slugs[0]
@ -519,8 +522,8 @@ def read_entrance(filename, ent=None):
DataIssue.objects.create(parser="entrances", message=message, url=cave_edit_url)
print(message)
if slug != entslug_fn:
message = f" ! - Warning, mismatch between entrance slug and filename: {slug=} {filename=}. Ignoring slug field, using filename."
if slug and slug != entslug_fn:
message = f" ! - Warning, mismatch between entrance slug (or unofficial name) and filename: {slug=} {filename=}. Ignoring slug field, using filename."
DataIssue.objects.create(parser="xEntrances", message=message, url=cave_edit_url)
print(message)
slug = entslug_fn # force
@ -604,8 +607,11 @@ def read_cave(filename, mvf=None, cave=None):
elements = xml_root.findall(t)
"""
def getXMLmin0(field):
return getXML(cavecontents, field, minItems=0, maxItems=1, context=context)
def getXMLmax1(field):
return getXML(cavecontents, field, maxItems=1, context=context)
return getXML(cavecontents, field, minItems=0, maxItems=1, context=context)
def do_entrances():
"""For both bulk import and individual re-reading of cave_data file,
@ -813,11 +819,13 @@ def read_cave(filename, mvf=None, cave=None):
#kataster_status = getXMLmax1("kataster_status")
#underground_centre_line = getXMLmax1("underground_centre_line")
notes = getXMLmax1("notes")
length = getXMLmax1("length")
depth = getXMLmax1("depth")
extent = getXMLmax1("extent")
survex_file = getXMLmax1("survex_file")
description_file = getXMLmax1("description_file")
length = getXMLmin0("length")
depth = getXMLmin0("depth")
extent = getXMLmin0("extent")
areacode = slug[:4]
contextguess = f"/{slug[0:4]}/{slug}_cave_edit/"
@ -870,9 +878,12 @@ def read_cave(filename, mvf=None, cave=None):
#cave.kataster_status=kataster_status[0]
#cave.underground_centre_line=underground_centre_line[0]
cave.notes=notes[0]
cave.length=length[0]
cave.depth=depth[0]
cave.extent=extent[0]
if length:
cave.length=length[0]
if depth:
cave.depth=depth[0]
if extent:
cave.extent=extent[0]
cave.survex_file=survex_file[0]
cave.description_file=description_file[0]
# cave.url=url[0] # set algorithically: