2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00

Bug fixes to allow adding of a new cave. No longer ask users about filenames or urls.

This commit is contained in:
Martin Green 2023-07-05 17:43:57 +01:00
parent 067fcd9892
commit 410a285085
4 changed files with 32 additions and 17 deletions

View File

@ -61,12 +61,12 @@ class CaveForm(ModelForm):
survex_file = forms.CharField(
required=False, label="Survex file eg. caves-1623/000/000.svx", widget=forms.TextInput(attrs={"size": "45"})
)
url = forms.CharField(required=True, label="URL eg. 1623/000/000 (no .html)", widget=forms.TextInput(attrs={"size": "45"}))
#url = forms.CharField(required=True, label="URL eg. 1623/000/000 (no .html)", widget=forms.TextInput(attrs={"size": "45"}))
length = forms.CharField(required=False, label="Length (m)")
depth = forms.CharField(required=False, label="Depth (m)")
extent = forms.CharField(required=False, label="Extent (m)")
cave_slug = forms.CharField(widget = forms.HiddenInput(), required = False)
#cave_slug = forms.CharField()
class Meta:
model = Cave
@ -74,8 +74,12 @@ class CaveForm(ModelForm):
field_order = ['area', 'unofficial_number', 'kataster_number', 'official_name', 'underground_description', 'explorers', 'equipment', 'survey', 'kataster_status', 'underground_centre_line', 'notes', 'references', 'description_file', 'survex_file', 'url', 'length', 'depth', 'extent']
def get_area(self):
for a in self.cleaned_data["area"]:
if a.kat_area():
return a.kat_area()
def clean_cave_slug(self):
print(self.cleaned_data["cave_slug"] == "")
if self.cleaned_data["cave_slug"] == "":
myArea = ""
for a in self.cleaned_data["area"]:
@ -91,11 +95,11 @@ class CaveForm(ModelForm):
print("EEE", cave_slug.replace("-PENDING-", "-"))
return cave_slug.replace("-PENDING-", "-")
def clean_url(self):
data = self.cleaned_data["url"]
if not re.match("\d\d\d\d/.", data):
raise ValidationError("URL must start with a four digit Kataster area.")
return data
# def clean_url(self):
# data = self.cleaned_data["url"]
# if not re.match("\d\d\d\d/.", data):
# raise ValidationError("URL must start with a four digit Kataster area.")
# return data
def clean(self):

View File

@ -144,12 +144,15 @@ class Cave(TroggleModel):
def ours(self):
return bool(re.search(r"CUCC", self.explorers))
def number(self):
if self.kataster_number:
return self.kataster_number
else:
return self.unofficial_number
def reference(self):
if self.kataster_number:
return f"{self.kat_area()}-{self.kataster_number}"
else:
return f"{self.kat_area()}-{self.unofficial_number}"
return f"{self.kat_area()}-{self.number()}"
def get_absolute_url(self):
if self.kataster_number:

View File

@ -2,6 +2,7 @@ import logging
import random
import resource
import subprocess
import os
from decimal import getcontext
from pathlib import Path
@ -108,7 +109,7 @@ def write_and_commit(files, message):
filename = filepath.name
# GIT see also core/views/uploads.py dwgupload()
# GIT see also core/views/expo.py editexpopage()
os.makedirs(os.path.dirname(filepath), exist_ok = True)
if encoding:
mode = "w"
kwargs = {"encoding": encoding}
@ -144,10 +145,11 @@ def write_and_commit(files, message):
)
else:
print(f"No change {filepath}")
subprocess.run([git, "commit", filename, "-m", message], cwd=cwd, capture_output=True, text=True)
cp_status = subprocess.run([git, "status", filename], cwd=cwd, capture_output=True, text=True)
filenames = [filepath.name for filepath, content, encoding in files]
subprocess.run([git, "commit"] + filenames + ["-m", message], cwd=cwd, capture_output=True, text=True)
cp_status = subprocess.run([git, "status"] + filenames, cwd=cwd, capture_output=True, text=True)
#This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb
if cp_status.stdout.split("\n")[-2] != "nothing to commit, working tree clean":
if not cp_status.stdout or len(cp_status.stdout) < 2 or cp_status.stdout.split("\n")[-2] != "nothing to commit, working tree clean":
msgdata = (
"Ask a nerd to fix this.\n\n"
+ cp_status.stderr

View File

@ -268,6 +268,8 @@ def rendercave(request, cave, slug, cave_id=""):
svxstem = Path(settings.SURVEX_DATA) / Path(cave.survex_file)
# print(f" ! rendercave: slug:'{slug}' '' ++ '{svxstem}'")
except:
svx3d = ""
svxstem = ""
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.
@ -374,10 +376,14 @@ def edit_cave(request, path="", slug=None):
if form.is_valid() and ceFormSet.is_valid():
# print(f'! POST is valid. {cave}')
cave = form.save(commit=False)
if not cave.filename:
cave.filename = form.get_area() + "-" + cave.number() + ".html"
if not cave.url:
cave.url = form.get_area() + "/" + cave.number() + ".html"
cave.save()
form.save_m2m()
if slug is None:
cs = CaveSlug(cave=cave, slug=form.cleaned_data["cave_slug"], primary=True)
cs = CaveSlug(cave=cave, slug=cave.reference(), primary=True)
cs.save()
ceinsts = ceFormSet.save(commit=False)
for ceinst in ceinsts: