diff --git a/parsers/caves.py b/parsers/caves.py index f70cdcd..34a2301 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -165,24 +165,29 @@ def do_ARGE_cave(slug, caveid, url, areacode, svxid): print(message) return urltest[0] - numtest = Cave.objects.filter(unofficial_number=caveid.upper()) + numtest = Cave.objects.filter(unofficial_number=caveid.upper(), areacode=areacode) if numtest: - message = f" ! Cave {numtest[0]} already exists with this unofficial_number {caveid.upper()}. Can't create new ARGE cave {slug}" + message = f" ! Cave {numtest[0]} already exists with this areacode {areacode} and unofficial_number {caveid.upper()}. Can't create new ARGE cave {slug}" DataIssue.objects.create(parser="caves", message=message, url=url) print(message) return numtest[0] - cave = Cave( - unofficial_number=caveid.upper(), - kataster_number=caveid.upper(), # should only set this if all digits - underground_description="ARGE cave.", - survex_file= f"{svxid}.svx", - url=url, - notes=default_note, - areacode=areacode, + cave = Cave( + underground_description="ARGE cave.", + survex_file= f"{svxid}.svx", + url=url, + notes=default_note, + areacode=areacode, ) if cave: - cave.save() # must save to have id before foreign keys work. This is also a ManyToMany key. + try: + kn = int(caveid) + cave.kataster_number=kn # should only set this if all digit + except: + # must be unofficial 'number' or name + cave.unofficial_number=caveid.upper() + + cave.save() try: # Now create a cave slug ID CaveSlug.objects.update_or_create(cave=cave, slug=slug, primary=False) @@ -521,7 +526,7 @@ def read_cave(filename, cave=None): # print(f"! Entrance {eslug}") if eslug.endswith('a b'): message = f' - Entrance has weird name slug:"{eslug}" cave:"{cave}" caveslug:"{slug}" filename:"cave_data/{filename}"' - DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.areacode}/{cave.areacode}-{cave.url}_cave_edit/") + DataIssue.objects.create(parser="xEntrances", message=message, url=f"{cave.url}_cave_edit/") # print(message) letter = getXML(e, "letter", maxItems=1, context=context)[0] @@ -532,7 +537,7 @@ def read_cave(filename, cave=None): if letter.lower() not in list(string.ascii_lowercase): letter = "x" message = f"- Warning - Empty 'letter' field for '{eslug}' in multiple-entrance cave '{cave}', setting to {letter}." - DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.areacode}/{cave.areacode}-{cave.url}_cave_edit/") + DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}_cave_edit/") print(message) if len(entrances) == 1 and not eslug: # may be empty: @@ -550,7 +555,7 @@ def read_cave(filename, cave=None): entrances_xslug[eslug] = entrance except: message = f"! Fail entrance loading {eslug} /entrance_data/{eslug} file does not exist or loading it failed." - DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.areacode}/{cave.areacode}-{cave.url}_cave_edit/") + DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}_cave_edit/") print(message) return diff --git a/templates/survexdir.html b/templates/survexdir.html index e6854ef..a0fa1c2 100644 --- a/templates/survexdir.html +++ b/templates/survexdir.html @@ -12,7 +12,7 @@ CaveCave primaryf.primaryf.path {% for f in survexfiles %} -{{f.cave}} {{f.cave.areacode}}{f.cave.subarea}} +{{f.cave}} {{f.cave.areacode}}{% if f.cave.subarea %}-{{f.cave.subarea}}{% endif %} {{f.cave.survex_file}} {{f.primary}}.svx {{f.path}}.svx diff --git a/templates/svxfile.html b/templates/svxfile.html index d3e18ed..8c2d367 100644 --- a/templates/svxfile.html +++ b/templates/svxfile.html @@ -81,7 +81,7 @@ LOGMESSAGES {% endif %} underground survey length: {{svxlength|floatformat:2}} metres
-cave primary survexfile {{survexfile.cave.survex_file}}
+cave primary survexfile {{survexfile.cave.survex_file}}
directory primary survexfile {{survexfile.primary}}
{% for sb in svxblocks %} block {{sb}} has parent block {{sb.parent}} (in file {{sb.parent.survexfile.path}}.svx)