2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-05-12 20:20:25 +01:00

working, saved ent html file & linked.

This commit is contained in:
2026-05-12 01:43:42 +01:00
parent f6770187ef
commit 7a80c3d9f6
+67 -21
View File
@@ -9,6 +9,7 @@ from django.conf import settings
from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLookup
from troggle.parsers.people import who_is_this
# from troggle.core.views.editor_helpers import HTMLarea
from troggle.core.utils import (
get_cookie_max_age,
WriteAndCommitError,
@@ -88,6 +89,25 @@ class NewHoleForm(forms.Form):
photo_ent_no = forms.BooleanField(label="Entrance photos ?", required=False)
photo_ent_who = forms.CharField(label="Who has photos of entrance, tag and GPS?", required=False)
# Entrance description and approach
entrance_description = forms.CharField(
label="Entrance description",
required=True,
widget=forms.Textarea(attrs={
"height": "80%", "rows": 2,
"placeholder": "horizontal slot at foot level in 3m high NE-facing cliff"}),
)
approach = forms.CharField(
label="Approach",
max_length=100,
required=True,
widget=forms.Textarea(attrs={
"height": "80%", "rows": 2,
"placeholder": "from top camp, go NE round the side of Augst Eck, in some trees"}),
)
identified_login = forms.BooleanField(required=False,widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # makes it readonly
who_are_you = forms.CharField(strip=True,
@@ -430,15 +450,19 @@ def process_new_hole(form, area):
editor = git_string(form.cleaned_data["who_are_you"])
fix_id = f"{area}.g{form.cleaned_data.get("cave_id").lower()}"
_newfix(form, area, editor)
_newent(form, area, editor) # yes, make the Entrance first
_newcave(form, area, editor)
_newfix(form, area, editor, fix_id)
cave = _makecave(form, area)
_newent(form, area, editor, fix_id, cave) # yes, make the Entrance first
_savecave(form, area, editor, cave)
_newwallet(form, area, editor)
return
def _newfix(form, area, editor):
def _newfix(form, area, editor, fix_id):
auto_gps_file, content = get_auto_file()
fix_id = f"{area}.g{form.cleaned_data.get("cave_id").lower()}"
fix_line = f"*fix {fix_id} reference {form.cleaned_data.get("gps_lat")} {form.cleaned_data.get("gps_long")} 0\n"
content += f"\n; {form.cleaned_data.get("discovery_date")} wallet: {form.cleaned_data.get("survey_wallet")} \n"
@@ -463,7 +487,7 @@ def _newfix(form, area, editor):
raise
return
def _newent(form, areacode, editor):
def _newent(form, areacode, editor, fix_id, cave):
"""All a bit over-complicated by the existance of teh combined Entrance & Letter Form and the
CaveAndEntrance class
@@ -477,25 +501,41 @@ def _newent(form, areacode, editor):
slug = f"{areacode}-{form.cleaned_data.get("cave_id")}" # no letter suffix a,b, or c..
imgpath = Path(areacode) / form.cleaned_data.get("cave_id")
ent = Entrance.objects.create( # creates object and saves into db
ent = Entrance.objects.create( # creates object
slug=slug,
filename = slug + ".html",
entrance_description="Created when registering a new cave. "
+ "Click on 'Edit' to enter the updated data, then 'Submit'.",
marking="?",
findability="S", # Coordinates
marking="U", # Unmarked
approach= form.cleaned_data.get("approach"),
entrance_description=form.cleaned_data.get("entrance_description"),
# location_description=location_description[0],
lastvisit=form.cleaned_data.get("discovery_date"),
other_station=fix_id,
)
#ce = CaveAndEntrance(cave=cave, entrance=Entrance()) # creates a new Entrance object as well as a new CE object
#
# Add in default text for various fields here, and links to the two Wallets.
#
# link ent to cave
ce =CaveAndEntrance.objects.create(
cave=cave, entranceletter="", entrance=ent
)
#
# Add in saving Entrance to database and then .html file to filesystem and git
#
ent.save() # saves into db
try:
ent_file = ent.file_output()
write_and_commit([ent_file], f"Creating new Entrance {ent}", editor)
# leave other exceptions unhandled so that they bubble up to user interface
except PermissionError:
message = f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {ent.filename}. Ask a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except WriteAndCommitError as e:
message = f"CANNOT git on server for this file {ent.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": e.message})
except subprocess.SubprocessError as e:
message = f"CANNOT update server for this file {ent.filename}.\n{e}\nEdits may not be committed.\nAsk a nerd to fix this."
return render(request, "errors/generic.html", {"message": message})
except:
raise
return
def _guess_survex_file(areacode, id):
@@ -508,7 +548,7 @@ def _guess_survex_file(areacode, id):
return survex_file
return ""
def _newcave(form, areacode, editor):
def _makecave(form, areacode):
cave_id = form.cleaned_data.get("cave_id")
slug = f"{areacode}-{cave_id}"
cave = make_cave(slug)
@@ -521,8 +561,8 @@ def _newcave(form, areacode, editor):
default_note = "Created from New Cave Datasheet. "
wallet = form.cleaned_data.get("survey_wallet")
wallet_url = "/walletedit/{wallet.replace("#",":")}"
references = f"Wallet <a href='wallet_url'>{wallet}"
wallet_url = f"/walletedit/{wallet.replace('#',':')}"
references = f"Wallet <a href='{wallet_url}'>{wallet}</a>"
# TO-DO Need to detect if the existence of the survex was ticked but the file was not found,
# but that is probably normal: people will mostly record the Cave first and then do the survex data.
@@ -540,6 +580,10 @@ def _newcave(form, areacode, editor):
references=references,
)
cave.save()
return cave
def _savecave(form, areacode, editor, cave):
cave.save()
# need a CaveForm f we do it this way, which is a ModelForm.
# form.save_m2m() # this does the many-to-many relationship saving between caves and entrances
# can we do this manually?
@@ -561,3 +605,5 @@ def _newcave(form, areacode, editor):
return
def _newwallet(form, areacode, editor):
return