diff --git a/core/models/caves.py b/core/models/caves.py
index 949c089..cc5dcac 100644
--- a/core/models/caves.py
+++ b/core/models/caves.py
@@ -113,8 +113,9 @@ class Cave(TroggleModel):
else:
return self.unofficial_number
- def reference(self): # tidy this up, no longer used?
- return f"{self.areacode}-{self.number()}"
+ # def reference(self): # tidy this up, no longer used?
+ # REMOVE because of confusion with cave.references which is different
+ # return f"{self.areacode}-{self.number()}"
def get_absolute_url(self):
if self.kataster_number:
diff --git a/core/views/caves.py b/core/views/caves.py
index 5196bce..8adf0d6 100644
--- a/core/views/caves.py
+++ b/core/views/caves.py
@@ -374,7 +374,9 @@ def edit_cave(request, path="", slug=None):
cave.save()
form.save_m2m()
if slug is None:
- cs = CaveSlug(cave=cave, slug=cave.reference(), primary=True)
+ # it is not visible on the form so it always will be None
+ slug = f"{cave.areacode}-{cave.number()}"
+ cs = CaveSlug(cave=cave, slug=slug, primary=True)
cs.save()
#ceinsts = ceFormSet.save(commit=False)
#for ceinst in ceinsts:
diff --git a/core/views/scans.py b/core/views/scans.py
index a0e0446..428f8cf 100644
--- a/core/views/scans.py
+++ b/core/views/scans.py
@@ -104,7 +104,7 @@ def is_cave(wallet, id):
print(f" - Wallet {wallet} Failed to find cave object from id <{id}>")
if id.lower() != "unknown" and id != "":
print(f" - adding <{id}> to pendingcaves.txt list")
- add_cave_to_pending_list(id, f"Wallet {wallet} - Could not find id <{id}>")
+ add_cave_to_pending_list(id, wallet, f"Wallet {wallet} - Could not find id <{id}>")
return False
def fillblankothers(w):
diff --git a/parsers/caves.py b/parsers/caves.py
index 391501e..5b6d674 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -102,7 +102,12 @@ def set_dummy_entrance(id, slug, cave, msg="DUMMY"):
# DataIssue.objects.create(parser="entrances", message=message, url=f"{cave.url}")
# print(message)
-
+def add_cave_to_pending_list(id, wallet, message):
+ """(id, f"Wallet {wallet} - Could not find id <{id}>")
+ """
+ wurl = f"/walletedit/{wallet.walletname}".replace('#', ':')
+ DataIssue.objects.create(parser="wallets", message=message, url=wurl)
+
def create_new_cave(svxpath, svxid=None, msg=None):
"""This is called only when a new survex file is edited online which has a path on the
:loser: repo which is not recognised as a known cave.
@@ -252,7 +257,7 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
Convoluted. Needs rewriting.
Pointless if this cave is being created because we found a survex file...
- On problem is that the Cave name may have different capitalisation from the survex filename,
+ One problem is that the Cave name may have different capitalisation from the survex filename,
e.g. 2018-NTU-02 has a survex file 2018-ntu-02.svx
"""
if k[0:3] == "162":
@@ -268,7 +273,7 @@ def do_pending_cave(slug, caveid, url, areacode, msg=None):
if Path(settings.SURVEX_DATA, survex_file).is_file():
return survex_file
- # This should find the file even if the capitalisation is different, or if the directory name is totaly different
+ # This should find the file even if the capitalisation is different, or if the directory name is totally different
survex_file = ""
d = Path(settings.SURVEX_DATA, f"caves-{areacode}/{id}")
if d.is_dir():
@@ -539,7 +544,6 @@ def read_entrance(filename, ent=None):
def read_cave(filename, cave=None):
"""Reads an entrance description from the .html file
Convoluted. Sorry. Needs rewriting
- Assumes any area it hasn't seen before is a subarea of 1623
If not called as part of initial import, then the global lists will not be correct
but this is OK, a search will find them in the db.
@@ -644,6 +648,20 @@ def read_cave(filename, cave=None):
print(message)
primary = False
+ def check_slug(areacode, kataster_number, unofficial_number):
+ if kataster_number:
+ if slug == f"{areacode}-{kataster_number}":
+ return
+ message = f" ! Cave Slug incorrect (kataster): '{slug}' != '{areacode}-{kataster_number}' in file {filename}"
+ else:
+ if slug == f"{areacode}-{unofficial_number}":
+ return
+ message = f" ! Cave Slug incorrect (unofficial): '{slug}' != '{areacode}-{unofficial_number}' in file {filename}"
+ if slug.lower() == f"{areacode}-{unofficial_number.lower()}":
+ message = f" ! Cave Slug capitalisation incorrect (unofficial): {slug} != {areacode}-{unofficial_number} in file {filename}"
+ DataIssue.objects.create(parser="caves", message=message, url=f"{cave.url}_cave_edit/")
+ print(message)
+
global entrances_xslug
global caves_xslug
global areas_xslug
@@ -652,7 +670,7 @@ def read_cave(filename, cave=None):
# Note: these are HTML files in the EXPOWEB repo, not from the loser repo.
fn = settings.CAVEDESCRIPTIONS / filename
- context = f"/cave_data/{filename}_edit"
+ context = f"/cave_data/{filename}_edit" # the expo html editor, not the specialist cave data editor. oops.
# print(f" - Reading Cave from cave descriptions file {fn}")
if not fn.exists():
@@ -678,7 +696,6 @@ def read_cave(filename, cave=None):
DataIssue.objects.create(parser="caves", message=message, url=context)
print(message)
slug = slugs[0]
- context = url=f"/{slug[0:4]}/{slug}_cave_edit/"
non_public = getXMLmax1("non_public")
official_name = getXMLmax1("official_name")
@@ -700,8 +717,11 @@ def read_cave(filename, cave=None):
description_file = getXMLmax1("description_file")
url = getXMLmax1("url")
+ contextguess = f"/{slug[0:4]}/{slug}_cave_edit/" # guess as we havent read areacode yet
+
manual_edit = True
if not cave:
+ # we are parsing using databaseReset.py not an online edit
manual_edit = False
try:
cave, state = Cave.objects.update_or_create(filename=filename) # replace with slug when CaveSlug tidied up
@@ -710,7 +730,7 @@ def read_cave(filename, cave=None):
kaves = Cave.objects.all().filter(filename=filename) # replace with slug when CaveSlug tidied up
for k in kaves:
message = " ! - DUPLICATES in db. kataster:" + str(k.kataster_number) + ", slug:" + str(k.slug())
- DataIssue.objects.create(parser="caves", message=message, url=context)
+ DataIssue.objects.create(parser="caves", message=message, url=contextguess)
print(message)
for k in kaves:
if k.slug() is not None:
@@ -720,8 +740,19 @@ def read_cave(filename, cave=None):
# From here on the code applies to both edited and newly-imported caves (mostly!)
do_caveslugstuff() # needs cave!=None
-
-
+
+ areas = getXML(cavecontents, "area", context=contextguess) # can be multiple tags
+ for area_slug in areas:
+ if area_slug in AREACODES: # ignore sub areas which are in another tag
+ cave.areacode = area_slug
+ else:
+ cave.subarea = area_slug
+ if not cave.areacode:
+ if slug[0:4] in AREACODES:
+ cave.areacode = slug[0:4]
+ context = f"/{cave.areacode}/{slug}_cave_edit/"
+
+
cave.non_public=boolify(non_public)
cave.official_name=official_name[0]
cave.kataster_code=kataster_code[0]
@@ -741,17 +772,9 @@ def read_cave(filename, cave=None):
cave.survex_file=survex_file[0]
cave.description_file=description_file[0]
cave.url=url[0]
-
- areas = getXML(cavecontents, "area", context=context) # can be multiple tags
- for area_slug in areas:
- if area_slug in AREACODES: # ignore sub areas which are in another tag
- cave.areacode = area_slug
- else:
- cave.subarea = area_slug
- if not cave.areacode:
- if slug[0:4] in AREACODES:
- cave.areacode = slug[0:4]
-
+
+ check_slug(cave.areacode,cave.kataster_number, cave.unofficial_number)
+
entrances = getXML(cavecontents, "entrance", context=context)
do_entrances()
# print(f"- {entrances_xslug=}")
@@ -768,6 +791,7 @@ def read_cave(filename, cave=None):
message = f' ! {slug:12} survex filename does not exist :LOSER:"{survex_file[0]}" in "{filename}"'
DataIssue.objects.create(parser="caves", message=message, url=f"/{slug[0:4]}/{slug}_cave_edit/")
print(message)
+
if description_file[0]: # if not an empty string
message = f' - {slug:12} Note (not an error): complex description filename "{description_file[0]}" inside "cave_data/{filename}"'
@@ -778,22 +802,8 @@ def read_cave(filename, cave=None):
message = f' ! {slug:12} description filename "{EXPOWEB}/{description_file[0]}" does not refer to a real file'
DataIssue.objects.create(parser="caves", message=message, url=f"/{slug}_cave_edit/")
print(message)
-
cave.save()
return cave
-
-def add_cave_to_pending_list(id, msg=None):
- message = f"On dev machine, adding to PENDING. - {msg}"
- print(message)
- fpending = Path(CAVEDESCRIPTIONS, "pendingcaves.txt")
- try:
- if settings.DBSWITCH == "sqlite": # dev machine only
- if fpending.is_file():
- with open(fpending, "a") as pend:
- pend.write(f"{id}\n")
- # now need to do the git commit thing if running on server.
- except:
- pass
def readcaves():
"""Called from databaseReset mass importer.
@@ -863,7 +873,7 @@ def readcaves():
if k[0:3] == "162":
areacode = k[0:4]
number = k[5:]
- url = f"{areacode}/{k[5:]}.html" # Note we are appending the .htm to allow for offline websites
+ url = f"{areacode}/{k[5:]}.html" # Note we are appending the .html to allow for offline websites
else:
areacode = "1623"
number = k
diff --git a/templates/cave.html b/templates/cave.html
index c1a1c01..06d83d2 100644
--- a/templates/cave.html
+++ b/templates/cave.html
@@ -53,7 +53,11 @@
({{ cave.unofficial_number|safe }})
{% endif %}
{% else %}
-
{{ cave_id|safe }}
+ {% if cave.unofficial_number %}
+ {{ cave.unofficial_number|safe }}
+ {% else %}
+ {{ cave_id|safe }}
+ {% endif %}
{% endif %}