mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11: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:
parent
067fcd9892
commit
410a285085
@ -61,12 +61,12 @@ class CaveForm(ModelForm):
|
|||||||
survex_file = forms.CharField(
|
survex_file = forms.CharField(
|
||||||
required=False, label="Survex file eg. caves-1623/000/000.svx", widget=forms.TextInput(attrs={"size": "45"})
|
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)")
|
length = forms.CharField(required=False, label="Length (m)")
|
||||||
depth = forms.CharField(required=False, label="Depth (m)")
|
depth = forms.CharField(required=False, label="Depth (m)")
|
||||||
extent = forms.CharField(required=False, label="Extent (m)")
|
extent = forms.CharField(required=False, label="Extent (m)")
|
||||||
|
|
||||||
cave_slug = forms.CharField(widget = forms.HiddenInput(), required = False)
|
#cave_slug = forms.CharField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Cave
|
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']
|
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):
|
def clean_cave_slug(self):
|
||||||
print(self.cleaned_data["cave_slug"] == "")
|
|
||||||
if self.cleaned_data["cave_slug"] == "":
|
if self.cleaned_data["cave_slug"] == "":
|
||||||
myArea = ""
|
myArea = ""
|
||||||
for a in self.cleaned_data["area"]:
|
for a in self.cleaned_data["area"]:
|
||||||
@ -91,11 +95,11 @@ class CaveForm(ModelForm):
|
|||||||
print("EEE", cave_slug.replace("-PENDING-", "-"))
|
print("EEE", cave_slug.replace("-PENDING-", "-"))
|
||||||
return cave_slug.replace("-PENDING-", "-")
|
return cave_slug.replace("-PENDING-", "-")
|
||||||
|
|
||||||
def clean_url(self):
|
# def clean_url(self):
|
||||||
data = self.cleaned_data["url"]
|
# data = self.cleaned_data["url"]
|
||||||
if not re.match("\d\d\d\d/.", data):
|
# if not re.match("\d\d\d\d/.", data):
|
||||||
raise ValidationError("URL must start with a four digit Kataster area.")
|
# raise ValidationError("URL must start with a four digit Kataster area.")
|
||||||
return data
|
# return data
|
||||||
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
@ -144,12 +144,15 @@ class Cave(TroggleModel):
|
|||||||
|
|
||||||
def ours(self):
|
def ours(self):
|
||||||
return bool(re.search(r"CUCC", self.explorers))
|
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):
|
def reference(self):
|
||||||
if self.kataster_number:
|
return f"{self.kat_area()}-{self.number()}"
|
||||||
return f"{self.kat_area()}-{self.kataster_number}"
|
|
||||||
else:
|
|
||||||
return f"{self.kat_area()}-{self.unofficial_number}"
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
if self.kataster_number:
|
if self.kataster_number:
|
||||||
|
@ -2,6 +2,7 @@ import logging
|
|||||||
import random
|
import random
|
||||||
import resource
|
import resource
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import os
|
||||||
from decimal import getcontext
|
from decimal import getcontext
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -108,7 +109,7 @@ def write_and_commit(files, message):
|
|||||||
filename = filepath.name
|
filename = filepath.name
|
||||||
# GIT see also core/views/uploads.py dwgupload()
|
# GIT see also core/views/uploads.py dwgupload()
|
||||||
# GIT see also core/views/expo.py editexpopage()
|
# GIT see also core/views/expo.py editexpopage()
|
||||||
|
os.makedirs(os.path.dirname(filepath), exist_ok = True)
|
||||||
if encoding:
|
if encoding:
|
||||||
mode = "w"
|
mode = "w"
|
||||||
kwargs = {"encoding": encoding}
|
kwargs = {"encoding": encoding}
|
||||||
@ -144,10 +145,11 @@ def write_and_commit(files, message):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(f"No change {filepath}")
|
print(f"No change {filepath}")
|
||||||
subprocess.run([git, "commit", filename, "-m", message], cwd=cwd, capture_output=True, text=True)
|
filenames = [filepath.name for filepath, content, encoding in files]
|
||||||
cp_status = subprocess.run([git, "status", filename], cwd=cwd, capture_output=True, text=True)
|
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
|
#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 = (
|
msgdata = (
|
||||||
"Ask a nerd to fix this.\n\n"
|
"Ask a nerd to fix this.\n\n"
|
||||||
+ cp_status.stderr
|
+ cp_status.stderr
|
||||||
|
@ -268,6 +268,8 @@ def rendercave(request, cave, slug, cave_id=""):
|
|||||||
svxstem = Path(settings.SURVEX_DATA) / Path(cave.survex_file)
|
svxstem = Path(settings.SURVEX_DATA) / Path(cave.survex_file)
|
||||||
# print(f" ! rendercave: slug:'{slug}' '' ++ '{svxstem}'")
|
# print(f" ! rendercave: slug:'{slug}' '' ++ '{svxstem}'")
|
||||||
except:
|
except:
|
||||||
|
svx3d = ""
|
||||||
|
svxstem = ""
|
||||||
print(f" ! rendercave: slug:'{slug}' FAIL TO MANAGE survex file:'{cave.survex_file}'")
|
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.
|
# 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.
|
# 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():
|
if form.is_valid() and ceFormSet.is_valid():
|
||||||
# print(f'! POST is valid. {cave}')
|
# print(f'! POST is valid. {cave}')
|
||||||
cave = form.save(commit=False)
|
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()
|
cave.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
if slug is None:
|
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()
|
cs.save()
|
||||||
ceinsts = ceFormSet.save(commit=False)
|
ceinsts = ceFormSet.save(commit=False)
|
||||||
for ceinst in ceinsts:
|
for ceinst in ceinsts:
|
||||||
|
Loading…
Reference in New Issue
Block a user