mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
Fixing cave edit form and cave creation parser
This commit is contained in:
parent
20c42b14bf
commit
a656ada67a
@ -46,8 +46,8 @@ class CaveForm(ModelForm):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
if self.cleaned_data.get("kataster_number") == "" and self.cleaned_data.get("unofficial_number") == "":
|
if self.cleaned_data.get("kataster_number") == "" and self.cleaned_data.get("unofficial_number") == "":
|
||||||
self._errors["unofficial_number"] = self.error_class(["Either the kataster or unoffical number is required."])
|
self._errors["unofficial_number"] = self.error_class(["Either the kataster or unoffical number is required."])
|
||||||
if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
# if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
||||||
self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
# self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
||||||
if self.cleaned_data.get("area") == []:
|
if self.cleaned_data.get("area") == []:
|
||||||
self._errors["area"] = self.error_class(["This field is required."])
|
self._errors["area"] = self.error_class(["This field is required."])
|
||||||
if self.cleaned_data.get("url") and self.cleaned_data.get("url").startswith("/"):
|
if self.cleaned_data.get("url") and self.cleaned_data.get("url").startswith("/"):
|
||||||
|
@ -227,6 +227,8 @@ def rendercave(request, cave, slug, cave_id=''):
|
|||||||
else:
|
else:
|
||||||
editable = False
|
editable = False
|
||||||
#print(f" ! rendercave:'{cave}' svxstem:{svxstem} caveid:'{cave_id}' svx3d:'{svx3d}'")
|
#print(f" ! rendercave:'{cave}' svxstem:{svxstem} caveid:'{cave_id}' svx3d:'{svx3d}'")
|
||||||
|
if not cave_id:
|
||||||
|
cave_id = slug # cave.unofficial_number
|
||||||
try:
|
try:
|
||||||
r = render(request,'cave.html', {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True,
|
r = render(request,'cave.html', {'cave_editable': editable, 'settings': settings, 'cave': cave, 'cavepage': True,
|
||||||
'cave_id': cave_id, 'svxstem': svxstem, 'svx3d':svx3d})
|
'cave_id': cave_id, 'svxstem': svxstem, 'svx3d':svx3d})
|
||||||
@ -335,6 +337,8 @@ def edit_cave(request, slug=None):
|
|||||||
myslug = "%s-%s" % (myArea, form.cleaned_data["unofficial_number"])
|
myslug = "%s-%s" % (myArea, form.cleaned_data["unofficial_number"])
|
||||||
else:
|
else:
|
||||||
myslug = slug
|
myslug = slug
|
||||||
|
# Converting a PENDING cave to a real cave by saving this form
|
||||||
|
myslug = myslug.replace('-PENDING-', '-')
|
||||||
cave.filename = myslug + ".html"
|
cave.filename = myslug + ".html"
|
||||||
cave.save()
|
cave.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
@ -389,7 +393,12 @@ def edit_entrance(request, caveslug=None, slug=None):
|
|||||||
if form.is_valid() and (slug is not None or entletter.is_valid()):
|
if form.is_valid() and (slug is not None or entletter.is_valid()):
|
||||||
entrance = form.save(commit = False)
|
entrance = form.save(commit = False)
|
||||||
if slug is None:
|
if slug is None:
|
||||||
|
if entletter.cleaned_data["entrance_letter"]:
|
||||||
slugname = cave.slug() + entletter.cleaned_data["entrance_letter"]
|
slugname = cave.slug() + entletter.cleaned_data["entrance_letter"]
|
||||||
|
else:
|
||||||
|
slugname = cave.slug()
|
||||||
|
# Converting a PENDING cave to a real cave by saving this form
|
||||||
|
slugname = slugname.replace('-PENDING-', '-')
|
||||||
entrance.cached_primary_slug = slugname
|
entrance.cached_primary_slug = slugname
|
||||||
entrance.filename = slugname + ".html"
|
entrance.filename = slugname + ".html"
|
||||||
entrance.save()
|
entrance.save()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -44,24 +45,28 @@ def readcaves():
|
|||||||
# Do this first, so that these empty entries are overwritten as they get properly created.
|
# Do this first, so that these empty entries are overwritten as they get properly created.
|
||||||
|
|
||||||
# For those caves which do not have cave_data/1623-xxx.html XML files even though they exist and have surveys
|
# For those caves which do not have cave_data/1623-xxx.html XML files even though they exist and have surveys
|
||||||
# also needs to be done *before* entrances so that the entrance-cave links work properly.
|
pending = ["2007-06", "2009-01", "2009-02",
|
||||||
pending = ["2007-05", "2007-06", "2007-12", "2009-01", "2009-02",
|
|
||||||
"2010-06", "2010-07", "2012-ns-01", "2012-ns-02", "2010-04", "2012-ns-05", "2012-ns-06",
|
"2010-06", "2010-07", "2012-ns-01", "2012-ns-02", "2010-04", "2012-ns-05", "2012-ns-06",
|
||||||
"2012-ns-07", "2012-ns-08", "2012-ns-12", "2012-ns-14", "2012-ns-15", "2014-bl888",
|
"2012-ns-07", "2012-ns-08", "2012-ns-12", "2012-ns-14", "2012-ns-15", "2014-bl888",
|
||||||
"2018-pf-01", "2018-pf-02", "haldenloch"]
|
"2018-pf-01", "2018-pf-02", "haldenloch"]
|
||||||
|
|
||||||
for k in pending:
|
for k in pending:
|
||||||
url = "1623/" + k
|
url = "1623/" + k
|
||||||
try:
|
try:
|
||||||
|
# default for a PENDING cave, ooverwritten if a real cave exists
|
||||||
cave = Cave(
|
cave = Cave(
|
||||||
unofficial_number = k,
|
unofficial_number = k,
|
||||||
# official_name = "",
|
# official_name = "",
|
||||||
underground_description = "Pending cave write-up - creating as empty object. No XML file available yet.",
|
underground_description = "Pending cave write-up - creating as empty object. No XML file available yet.",
|
||||||
survex_file = "caves-1623/" + k + "/" + k +".svx",
|
survex_file = "caves-1623/" + k + "/" + k +".svx",
|
||||||
url = url,
|
url = url,
|
||||||
notes="_Survex file found in loser repo but no description in expoweb <br>\n"+
|
notes=f"_Survex file found in loser repo but no description in expoweb <br><br><br>\n"+
|
||||||
"INSTRUCTIONS: First open 'This survex file' (link above the CaveView panel) to find the date and info. Then <br>\n" +
|
f"INSTRUCTIONS: First open 'This survex file' (link above the CaveView panel) to find the date and info. Then " +
|
||||||
"search in the Expo for that year e.g. <a href='/expedition/2007'>2007</a> to find a relevant logbook entry, then <br>\n" +
|
f"<br>\n - search in the Expo for that year e.g. <a href='/expedition/{k[0:4]}'>{k[0:4]}</a> to find a relevant logbook entry, then \n - " +
|
||||||
"click on 'New Entrance' at the bottom of this page as we need to create the entrance *first*.")
|
f"click on 'Edit this cave' and copy the information you find in the survex file and the logbook"+
|
||||||
|
f"<br>\n - " +
|
||||||
|
f"When you Submit it will create a file file in expoweb/cave_data/ " +
|
||||||
|
f"<br>\n - but you have not finished yet. You MUST go and create the entrance: click on New Entrance. Then this will no longer be 'Pending' once the flag has been removed from the code")
|
||||||
if cave:
|
if cave:
|
||||||
cave.save() # must save to have id before foreign keys work. This is also a ManyToMany key.
|
cave.save() # must save to have id before foreign keys work. This is also a ManyToMany key.
|
||||||
#print(f' ! - READ CAVES: cave {k} {cave}')
|
#print(f' ! - READ CAVES: cave {k} {cave}')
|
||||||
@ -73,7 +78,7 @@ def readcaves():
|
|||||||
|
|
||||||
try: # Now create a cave slug ID
|
try: # Now create a cave slug ID
|
||||||
cs = CaveSlug.objects.update_or_create(cave = cave,
|
cs = CaveSlug.objects.update_or_create(cave = cave,
|
||||||
slug = "1623-PENDING-" + k,
|
slug = "1623-" + k,
|
||||||
primary = False)
|
primary = False)
|
||||||
except:
|
except:
|
||||||
message = " ! {:11s} {} PENDING cave slug create failure".format(k)
|
message = " ! {:11s} {} PENDING cave slug create failure".format(k)
|
||||||
@ -289,13 +294,13 @@ def readcave(filename):
|
|||||||
if slug in caves_xslug:
|
if slug in caves_xslug:
|
||||||
cs = caves_xslug[slug]
|
cs = caves_xslug[slug]
|
||||||
else:
|
else:
|
||||||
try:
|
try: # we want to overwrite a PENDING cave if we are now importing the 1623-xxx.html file for it
|
||||||
cs = CaveSlug.objects.update_or_create(cave = c,
|
cs = CaveSlug.objects.update_or_create(cave = c,
|
||||||
slug = slug,
|
slug = slug,
|
||||||
primary = primary)
|
primary = primary)
|
||||||
caves_xslug[slug] = cs
|
caves_xslug[slug] = cs
|
||||||
except:
|
except Exception as ex:
|
||||||
message = " ! Cave update/create failure: %s, skipping file %s" % (slug, context)
|
message = " ! Cave update/create failure : %s, skipping file %s\nException: %s" % (slug, context, ex.__class__)
|
||||||
DataIssue.objects.create(parser='caves', message=message)
|
DataIssue.objects.create(parser='caves', message=message)
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
@ -331,7 +336,7 @@ def readcave(filename):
|
|||||||
#c.save()
|
#c.save()
|
||||||
else: # more than one item in long list
|
else: # more than one item in long list
|
||||||
message = f' ! ABORT loading this cave. in "{filename}"'
|
message = f' ! ABORT loading this cave. in "{filename}"'
|
||||||
DataIssue.objects.create(parser='caves', message=message, url=f'/cave/{slug}/edit/')
|
DataIssue.objects.create(parser='caves', message=message, url=f'/cave/{slugs}/edit/')
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
def getXML(text, itemname, minItems = 1, maxItems = None, printwarnings = True, context = ""):
|
def getXML(text, itemname, minItems = 1, maxItems = None, printwarnings = True, context = ""):
|
||||||
|
@ -442,7 +442,7 @@ div#scene {
|
|||||||
{% block contentheader %}
|
{% block contentheader %}
|
||||||
<table id="cavepage">
|
<table id="cavepage">
|
||||||
<tr>
|
<tr>
|
||||||
<th id="kat_no">
|
<th id="kat_no"><!-- why is this not showing unofficial_number??-->
|
||||||
{% if cave.kataster_number %}
|
{% if cave.kataster_number %}
|
||||||
{{ cave.kataster_number|safe }}
|
{{ cave.kataster_number|safe }}
|
||||||
{% if cave.entrancelist %}
|
{% if cave.entrancelist %}
|
||||||
@ -451,6 +451,8 @@ div#scene {
|
|||||||
{% if cave.unofficial_number %}
|
{% if cave.unofficial_number %}
|
||||||
<br />({{ cave.unofficial_number|safe }})
|
<br />({{ cave.unofficial_number|safe }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<br />{{ cave_id|safe }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</th>
|
</th>
|
||||||
<th id="name">
|
<th id="name">
|
||||||
|
Loading…
Reference in New Issue
Block a user