2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-05-10 15:37:21 +01:00

Validations begun

This commit is contained in:
2026-05-10 12:53:42 +01:00
parent 3ff8eeaf24
commit 873034b8b8
+62 -1
View File
@@ -63,8 +63,69 @@ class NewHoleForm(forms.Form):
photo_tag_no = forms.BooleanField(label="Photos of tag ?", required=False)
photo_tag_who = forms.CharField(label="Who has tag photos ?", required=False)
def clean_gps_lat(self):
data = self.cleaned_data['gps_lat']
min_val = 47.5
max_val = 47.9
if data < min_val or data > max_val:
raise ValidationError(
f"A valid latitude is between {min_val} and {max_val}")
return data
def clean_gps_long(self):
data = self.cleaned_data['gps_long']
placeholder_val = 13.8160500
min_val = 13.6
max_val = 14.0
if data < min_val or data > max_val:
raise ValidationError(
f"A valid longitude is between {min_val} and {max_val}")
return data
def clean_dist_to_ent(self):
dist = self.cleaned_data.get('dist_to_ent')
if dist is None:
raise forms.ValidationError("Distance cannot empty. Please enter a value between 0 and 20.")
else:
if dist < 0 or dist > 20:
raise forms.ValidationError("Distance must be between 0 and 20 meters.")
return dist
def clean_bear_to_ent(self):
bearing = self.cleaned_data.get('bear_to_ent')
if bearing is None:
raise forms.ValidationError("Bearing cannot empty. Please enter a value between 0 and 360.")
else:
if bearing < 0 or bearing > 360:
raise forms.ValidationError("Bearing must be between 0 and 360 degrees.")
return bearing
def clean_ug_survey_wallet(self):
data = self.cleaned_data.get('ug_survey_wallet')
if not data:
return data # Skip if empty (assumes required=False)
# 1. Remove all whitespace
clean_text = "".join(data.split())
# 2. Check general format using Regex (4 digits, #, 2 digits)
# ^\d{4}#\d{2}$ ensures the entire string matches exactly
if not re.match(r'^\d{4}#\d{2}$', clean_text):
raise forms.ValidationError(
"Survey Wallet must be in the format 'YYYY#NN' (e.g., 2019#99)."
)
# 3. Validate the year range (1976 to 2099)
year = int(clean_text[:4])
if year < 1976 or year > 2099:
raise forms.ValidationError(
f"The year {year} must be between 1976 and 2099."
)
# Return the whitespace-stripped version to be saved
return clean_text
from django.shortcuts import render, redirect
from django.contrib import messages