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

validity check Area and not previously known Cave

This commit is contained in:
2026-05-11 21:41:15 +01:00
parent f4367d0fcf
commit 9887bf6696
+44 -5
View File
@@ -160,8 +160,6 @@ class NewHoleForm(forms.Form):
# Individual field cleaners (regex) will handle malformed wallet strings
pass
if wallet_id and trip_date:
try:
clean_wallet = "".join(wallet_id.split()) # should already be cleaned
@@ -197,6 +195,15 @@ class NewHoleForm(forms.Form):
# cleaned_data['intrepid_ids'] = intrepids
# cleaned_data['cameramen_ids'] = cameramen
gps_lat = cleaned_data.get("gps_lat")
gps_lang = cleaned_data.get("gps_long")
valid_area, area = which_area(lat, long)
if not valid_area:
self.add_error('gps_lat', "Not in Area 1626 or 1623")
self.add_error('gps_long', "Not in Area 1626 or 1623")
else:
if Cave.objects.filter(unofficial_number=cave_id, areacode=areacode).exists():
self.add_error('cave_id', "This Cave already exists, pick another identifier.")
# Entrance Photo Logic
photo_ent_on_camera = cleaned_data.get("photo_ent_on_camera")
@@ -314,6 +321,7 @@ from textwrap import dedent
from django.shortcuts import render, redirect
from django.contrib import messages
from .auth import login_required_if_public
from troggle.parsers.caves import make_cave
@login_required_if_public
def new_hole(request):
@@ -325,7 +333,7 @@ def new_hole(request):
form = NewHoleForm(request.POST, request.FILES)
lat = float(form.data['gps_lat'])
long = float(form.data['gps_long'])
valid, area = which_area(lat, long)
valid_area, area = which_area(lat, long)
if valid:
areatext = f"in {area}"
else:
@@ -334,14 +342,27 @@ def new_hole(request):
if form.is_valid():
editor = form.cleaned_data["who_are_you"]
editor = git_string(editor)
if valid_area:
process_new_hole(form, area)
messages.success(request, "New prospect save data successfully saved.")
success_url = "/walletedit/" + form.cleaned_data.get('survey_wallet').replace("#",":")
return redirect(success_url)
else:
# not in 1623 or 1626
messages.failure(request, "Not in 1623 or 1626. Fix this.")
return render(request, 'new_hole.html', {'form': form,
"identified_login": identified_login,
"areatext": areatext})
# GET
else:
form = NewHoleForm(initial={"identified_login": identified_login, "who_are_you":editor})
if identified_login:
# disable editing the git id string as we get it from the logged-on user data
form.fields["who_are_you"].widget.attrs["readonly"]="readonly"
return render(request, 'new_hole.html', {'form': form,
"identified_login": identified_login,
@@ -397,16 +418,25 @@ def process_new_hole(form, area):
we do not put "reference" in the *fix because we know it is used in the Entrance we are creating
❌BUT we DO put reference in now because we haven't written the Entrance bit of the code yet!
"""
editor = git_string(form.cleaned_data["who_are_you"])
_newfix(form, area, editor)
_newcave(form, area, editor)
_newent(form, area, editor)
return
def _newfix(form, area, editor):
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"
print(fix_line)
content += f"\n; {form.cleaned_data.get("discovery_date")} wallet: {form.cleaned_data.get("survey_wallet")} \n"
content += fix_line
content += f"*entrance {fix_id}\n"
content +=f"\n*end\n"
editor = git_string(form.cleaned_data["who_are_you"])
files = [(auto_gps_file, content, "utf8")]
try:
@@ -423,3 +453,12 @@ def process_new_hole(form, area):
except:
raise
return
def _newcave(form, area, editor):
# unofficial_number
slug = f"{area}-{form.cleaned_data.get("cave_id")}"
#cave = make_cave(slug)
return
def _newent(form, area, editor):
return