validations complete I hope

This commit is contained in:
2026-05-10 17:17:34 +01:00
parent 93b8093c0a
commit dc48a55d7e
2 changed files with 30 additions and 14 deletions
+25 -10
View File
@@ -11,7 +11,7 @@ class NewHoleForm(forms.Form):
"""
discovery_date = forms.DateField(label="Trip date", widget=forms.DateInput(attrs={'type': 'date'}), required=True)
# Identification
tag_id = forms.CharField(label="New Cave Identifier for internal identifiers. Cannot easily be changed.",
cave_id = forms.CharField(label="New Cave Identifier for internal identifiers. Cannot easily be changed.",
widget=forms.TextInput(attrs={'placeholder':
'e.g. 2035-ZB-03 '}),
max_length=50, required=True)
@@ -110,7 +110,7 @@ class NewHoleForm(forms.Form):
def _add_caver_error(self, field_name, name, year):
"""Standardized HTML error reporter"""
error_html = mark_safe(
f"'{name}' is not a recognized explorer for the year {year}. "
f"'{name}' is not a recognized caver for the year {year}. "
f"See <a href='/aliases/{year}'>aliases list</a>"
)
self.add_error(field_name, error_html)
@@ -124,18 +124,33 @@ class NewHoleForm(forms.Form):
trip_date = cleaned_data.get("discovery_date")
wallet_id = cleaned_data.get("survey_wallet")
cave_id = cleaned_data.get("cave_id")
if cave_id and trip_date:
try:
clean_cave = "".join(cave_id.split()) # removes whitespace
cave_year = int(clean_cave[:4])
trip_year = trip_date.year
if cave_year != trip_year:
self.add_error('cave_id',
f"Year mismatch: Cave identifier year ({cave_year}) does not match Trip date year ({trip_year}).")
except (ValueError, IndexError):
# 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
wallet_year = int(clean_wallet[:4])
# Get the year from the discovery_date (a datetime.date object)
trip_year = trip_date.year
if wallet_year != trip_year:
# Point the error at the wallet field
self.add_error('ug_survey_wallet',
self.add_error('survey_wallet',
f"Year mismatch: Wallet year ({wallet_year}) does not match Trip date year ({trip_year}).")
except (ValueError, IndexError):
@@ -151,10 +166,10 @@ class NewHoleForm(forms.Form):
intrepids = self._validate_caver_list(
'discoverers', year, cleaned_data.get("discoverers"))
cameramen = self._validate_caver_list(
'photo_ent_who', year, cleaned_data.get("photo_ent_who"))
if cleaned_data.get("photo_ent_no") or cleaned_data.get("gps_photo"):
cameramen = self._validate_caver_list(
'photo_ent_who', year, cleaned_data.get("photo_ent_who"))
# Even for a single name, it works fine
gps_user = self._validate_caver_list(
'gps_owner', year, cleaned_data.get("gps_owner"))
@@ -185,8 +200,8 @@ class NewHoleForm(forms.Form):
return cleaned_data
def clean_tag_id(self):
data = self.cleaned_data.get('tag_id')
def clean_cave_id(self):
data = self.cleaned_data.get('cave_id')
# 1. Remove whitespace and force uppercase for consistency
clean_text = "".join(data.split()).upper()
+5 -4
View File
@@ -102,7 +102,7 @@
<div class="field-{{ field.name }}">
{{ field.label_tag }}
{{ field }}<span class="unit-label"> E
{%if areacode %}<font color="blue"> {{areacode}}</font>{% endif %}</span>
{%if areacode %}&nbsp;&nbsp;&nbsp;&nbsp;<font color="blue"> {{areacode}}</font>{% endif %}</span>
{{ field.errors }}
</div>
</div> {# Standard Checkbox rendering #}
@@ -134,12 +134,13 @@
<p>
<ul>
<li>Calculate whether this new cave is in area 1623 or 1626
<li>Create a FIXED POINT record by appending to :loser:/fixedpts/gps/auto.svx
<li>Create a <span style="font-variant: small-caps;">fixed point</span> record by appending to :loser:/fixedpts/gps/auto.svx
<li>Create a new Cave record with associated new Entrance record
<li>Do a git commit (expoweb) of the new Cave and Entrance description files
<li>Do a git commit (loser) of the new GPS position
<li>Do a git commit (loser) of the new GPS position<br />
(git commits use your logged-in identity in the "Who are you ?" field)
<li>Update the database with this new information
<li>Create a new Wallet for this information and this trip
<li>Create a new Wallet for this information and this trip (if it does not exist)
<li>Return you to this form if any important data is missing or invalid
<li>If all is correct, will take you to the (new) Wallet for you to upload the photos
</ul>