diff --git a/core/models/caves.py b/core/models/caves.py index 81c1789..bf495bc 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -114,6 +114,9 @@ class Cave(TroggleModel): slugs = self.caveslug_set.filter() if slugs: return slugs[0].slug + + def newslug(self): + return f"{self.areacode}-{self.number()}" def ours(self): return bool(re.search(r"CUCC", self.explorers)) @@ -522,7 +525,7 @@ def GetCaveLookup(): checkcaveid(cave, slug) # These might alse create more duplicate entries - # Yes, this should be set in, and imported from, settings.py + # Yes, this should be set in, and imported from, an easily editable file # On reset, these aliases only work if the cave already properly exists with an entry in :expoweb:/cave_data/ # but as the aliases are recomputed repeatedly, eventually they work on PENDING caves too aliases = [ @@ -646,6 +649,8 @@ def GetCaveLookup(): ("2002-x12", "2005-07"), ("2002-x13", "1623-2005-06"), ("2002-x14", "2005-05"), + + # various funnies to cope with cave names used in logbooks ("kh", "1623-161"), ("161-kh", "1623-161"), ("204-steinBH", "1623-204"), @@ -659,10 +664,12 @@ def GetCaveLookup(): ("fgh", "1623-290"), ("fishface", "1623-290"), ("gsh", "1623-291"), + ("1623-2023-lc-01", "1623-318"), ("tempest", "1623-2023-lc-01"), ("1623-2023-kt-02", "2023-kt-02"), - + +# from the git output after Becka's changes, used to construct this list.. # rename caves-1623/{2023-ASH-15/2023-ASH-15.svx => 303/303.svx} (94%) # rename caves-1623/{2023-mg-02/2023-mg-02.svx => 304/304.svx} (90%) # rename caves-1623/{2023-mg-01/2023-mg-01.svx => 305/305.svx} (94%) @@ -694,7 +701,7 @@ def GetCaveLookup(): ("2023-jss-01", "1623-315"), ("2023-kt-01", "1623-316"), - # 1626 aliases2023-mg-01/2023-mg-01.svx => 305 + # 1626 ("langgustl", "1626-354"), ("2018-dm-07", "1626-359"), ("1626-2018-dm-07", "1626-359"), diff --git a/core/views/caves.py b/core/views/caves.py index 8d44b5c..5a28101 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -93,7 +93,7 @@ def pad5(x): def padnumber(x): - return re.sub("\d+", pad5, x) + return re.sub("\d+", pad5, x) # SyntaxWarning: invalid escape sequence '\d' def numericalcmp(x, y): @@ -102,7 +102,7 @@ def numericalcmp(x, y): def caveKey(c): """This function goes into a lexicographic sort function, and the values are strings, - but we want to sort numberically on kataster number before sorting on unofficial number. + but we want to sort numerically on kataster number before sorting on unofficial number. """ if not c.kataster_number: return "9999." + c.unofficial_number @@ -284,7 +284,7 @@ def rendercave(request, cave, slug, cave_id=""): print(f" ! rendercave: slug:'{slug}' FAIL TO MANAGE survex file:'{cave.survex_file}'") # NOTE the template itself loads the 3d file using javascript before it loads anything else. # Django cannot see what this javascript is doing, so we need to ensure that the 3d file exists first. - # So only do this render if a valid .3d file exists. TO BE DONE -Not yet as CaveView is currently disabled + # So only do this render if a valid .3d file exists. TO BE DONE # see design docum in troggle/templates/cave.html # see rendercave() in troggle/core/views/caves.py templatefile = "cave.html" @@ -507,10 +507,11 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): """ slugname = f"{slug}{letter}" nents = Entrance.objects.filter(slug=slugname).count() - print(f"NUM ents {slugname=} => {nents}") + print(f"check_new_slugname_ok() {slugname=} {letter=} => {nents}") if nents == 0: # looks good, but we need to check the CaveaAndEntrance object too e = entrance #Entrance.objects.get(slug=slugname) # does not exist yet! + e.save() gcl = GetCaveLookup() c = gcl[slug] nce = CaveAndEntrance.objects.filter(cave=c, entrance=e).count() @@ -593,12 +594,16 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): entrance = entform.save(commit=False) # entrance = ce.entrance # the one we created earlier? - if entranceletter: - slugname, letter = check_new_slugname_ok(cave.slug(), entranceletter) - else: - slugname, letter = check_new_slugname_ok(cave.slug(), "") - ce.entranceletter = letter - + try: + if entranceletter: + slugname, letter = check_new_slugname_ok(cave.slug(), entranceletter) + else: + slugname, letter = check_new_slugname_ok(cave.slug(), "") + ce.entranceletter = letter + + except Exception as e: + print(f"- EXCEPTION entranceletter {caveslug=} {entslug=} {entranceletter=} {path=}\n{e}") + raise entrance.slug = slugname entrance.cached_primary_slug = slugname entrance.filename = slugname + ".html" diff --git a/parsers/caves.py b/parsers/caves.py index 53ea9e1..7a4d737 100644 --- a/parsers/caves.py +++ b/parsers/caves.py @@ -749,11 +749,14 @@ def read_cave(filename, mvf=None, cave=None): # New 2024 June 28th. slugs = getXML(cavecontents, "caveslug", maxItems=1, context=context) if len(slugs) > 1: - message = f" ! - More than one slug for a cave: {cave}, slugs: {slugs}. Ignoring all except first." + message = f" ! - More than one slug for a cave: {cave}, slugs: {slugs}." DataIssue.objects.create(parser="caves", message=message, url=context) print(message) # slug = slugs[0] + + # but ignore read from the file slug = filename[:-5] # strip off the ".html" at the end of the filename + slugs = [slug] #print(f"{filename=} {slug=}") @@ -926,7 +929,7 @@ def readcaves(): with transaction.atomic(): print(" - Reading Caves from cave descriptions xml files") - mvscript = "mvscript.sh" + mvscript = "mvscript.sh" # in .gitignore so no problem creating it on server in /troggle/ with open(mvscript, "w") as mvf: # overwrite mvf.write(f"cd {CAVEDESCRIPTIONS}\n") for filename in next(os.walk(CAVEDESCRIPTIONS))[2]: # Should be a better way of getting a list of files diff --git a/templates/controlPanel.html b/templates/controlPanel.html index b50821c..c840b35 100644 --- a/templates/controlPanel.html +++ b/templates/controlPanel.html @@ -24,7 +24,7 @@
  • Folder paths used -folders settings used by this troggle installation
  • Expoer name aliases -short names recognised by troggle
  • Data Issues on Imports - warnings and errors from the recent data import -
  • Wild survex files - survex files contianing blocks with no related wallet +
  • Wild survex files - survex files containing blocks with no related wallet
  • Survex Directories - Every Cave has an associated directory and a Primary survex file
  • Survex import record - indented *include and begin/end tree
  • Survex debug report - warnings and details
  • Therion Import issues - warnings from the recent data import

    diff --git a/templates/dataformat/cave.xml b/templates/dataformat/cave.xml index 2a4e466..e8c6b5f 100644 --- a/templates/dataformat/cave.xml +++ b/templates/dataformat/cave.xml @@ -17,7 +17,7 @@ the form documented at {{ cave.non_public }}{% for slug in cave.caveslug_set.all %} -{{ slug.slug|default_if_none:"1623-000"|safe }}{% endfor %} +{{ slug.slug|default_if_none:"1623-000"|safe }}{% endfor %} {{ cave.official_name|default_if_none:""|safe }} {{cave.areacode |safe }} {{ cave.kataster_code|default_if_none:"-"|safe }} - {{ ce.entranceletter|default_if_none:""|safe }} + {{ ce.entranceletter|default_if_none:""|safe }} {% endfor %} {{ cave.explorers|default_if_none:""|safe }} diff --git a/templates/menu.html b/templates/menu.html index 6728abe..654cd97 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -51,7 +51,8 @@
  • {% if editable %}
  • Edit this page
  • {% endif %} {% if cave_editable %}
  • Edit this cave
  • {% endif %} -
  • {% if settings.DEVSERVER %}RUNNING ON LOCALSERVER{% endif %} +
  • {% if settings.DEVSERVER %}RUNNING ON LOCALSERVER
    slug:{{ cave.slug }}
    newslug:{{ cave.newslug }}
    url:{{ cave.url }}{% endif %} {% endif %} +