mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-21 23:01:52 +00:00
fixing cave_edit
This commit is contained in:
parent
5fff060487
commit
03fa36576b
@ -405,7 +405,10 @@ def edit_cave(request, path="", slug=None):
|
||||
Warning. This uses Django deep magic in the CaveForm processing.
|
||||
|
||||
It saves the data into into the database and into the html file, which it then commits to git.
|
||||
|
||||
We basically ignore the <path> as the <slug> is of the format 1624-114 and contains the area code
|
||||
"""
|
||||
#print(f"edit_cave(): {path=} {slug=}")
|
||||
message = ""
|
||||
if slug is not None:
|
||||
try:
|
||||
@ -454,8 +457,14 @@ def edit_cave(request, path="", slug=None):
|
||||
else:
|
||||
if slug is not None:
|
||||
# re-read cave data from file.
|
||||
#print(f"edit_cave(): {cave=} {cave.filename=}")
|
||||
#print(f"edit_cave(): {cave.slug()=}")
|
||||
if cave.filename:
|
||||
read_cave(cave.filename, cave=cave)
|
||||
try:
|
||||
read_cave(cave.filename, cave=cave)
|
||||
except Exception as e:
|
||||
print(f"edit_cave(): EXCEPTION attempting to read_cave()\n{e}")
|
||||
raise
|
||||
|
||||
form = CaveForm(instance=cave, initial={'cave_slug': cave.slug()})
|
||||
#ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
||||
|
@ -556,7 +556,7 @@ def read_entrance(filename, ent=None):
|
||||
ent.save()
|
||||
return ent
|
||||
|
||||
def read_cave(filename, mvf, cave=None):
|
||||
def read_cave(filename, mvf=None, cave=None):
|
||||
"""Reads an entrance description from the .html file
|
||||
Convoluted. Sorry. Needs rewriting
|
||||
|
||||
@ -684,10 +684,15 @@ def read_cave(filename, mvf, cave=None):
|
||||
pass
|
||||
|
||||
def check_slug(areacode, kataster_number, unofficial_number, url):
|
||||
"""There is a <caveslug> field in the .html file, but we now ignore it as we use the
|
||||
filename itself to set the slug.
|
||||
However we do check it for sanity, pending its removal eventually."""
|
||||
# context = f"/{cave.areacode}/{slug}_cave_edit/"
|
||||
|
||||
if kataster_number:
|
||||
if slug == f"{areacode}-{kataster_number}":
|
||||
return slug
|
||||
message = f" ! Cave Slug mismatch (kataster): '{slug}' != '{areacode}-{kataster_number}' {url=} in file {filename}. CHANGE caveslug field in the .html file."
|
||||
message = f" ! Cave Slug mismatch (kataster): '{slug}' != '{areacode}-{kataster_number}' {url=} in file {filename}. IGNORING caveslug field in the .html file."
|
||||
correctslug = f"{areacode}-{kataster_number}"
|
||||
|
||||
else:
|
||||
@ -697,14 +702,16 @@ def read_cave(filename, mvf, cave=None):
|
||||
message = f" ! Cave Slug capitalisation incorrect (unofficial): '{slug}' != '{areacode}-{unofficial_number}' {url=} in file {filename}."
|
||||
correctslug = slug.lower()
|
||||
else:
|
||||
message = f" ! Cave Slug mismatch (unofficial): '{slug}' != '{areacode}-{unofficial_number}' {url=} in file {filename} CHANGE caveslug field in the .html file."
|
||||
correctslug = slug # hack to stopit crashing
|
||||
DataIssue.objects.create(parser="caves", message=message, url=f"{slug}_cave_edit/") # url here is for where the file actually is, for editing
|
||||
message = f" ! Cave Slug mismatch (unofficial): '{slug}' != '{areacode}-{unofficial_number}' {url=} in file {filename} IGNORING caveslug field in the .html file."
|
||||
correctslug = f"{areacode}-{unofficial_number}"
|
||||
|
||||
msgurl=f"/{correctslug[0:4]}/{correctslug}_cave_edit/"
|
||||
DataIssue.objects.create(parser="caves", message=message, url=msgurl) # url here is for the href link to edit the bad data in the DataIssues page
|
||||
mvtext = f"mv {filename} {correctslug}.html"
|
||||
#print(mvtext)
|
||||
if filename != f"{correctslug}.html" :
|
||||
message = f" ! Filename is not the same as the cave slug '{slug}' != '{areacode}-{unofficial_number}' {url=} in file {filename} so use troggle/mvscript.sh to fix."
|
||||
DataIssue.objects.create(parser="caves", message=message, url=f"{slug}_cave_edit/") # url here is for where the file actually is, for editing
|
||||
DataIssue.objects.create(parser="caves", message=message, url=msgurl) # url here is for where the file actually is, for editing
|
||||
mvf.write(mvtext + "\n")
|
||||
print(message)
|
||||
return correctslug
|
||||
@ -823,8 +830,7 @@ def read_cave(filename, mvf, cave=None):
|
||||
cave.url = f"{cave.areacode}/{cave.number()}/{cave.number()}.html"
|
||||
check_directory(cave.areacode, cave.number(), cave.url, cave)
|
||||
|
||||
# This next line has no effect because the cave slug is not actually a field on the Cave object so we can't fix it here. to-do!
|
||||
slug = check_slug(cave.areacode, cave.kataster_number, cave.unofficial_number, cave.url)
|
||||
slug = check_slug(cave.areacode, cave.kataster_number, cave.unofficial_number, cave.url) #NB cave.slug is not a field on Cave
|
||||
|
||||
entrances = getXML(cavecontents, "entrance", context=context)
|
||||
do_entrances()
|
||||
|
Loading…
Reference in New Issue
Block a user