mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-05-15 06:57:34 +01:00
142 lines
5.9 KiB
Python
142 lines
5.9 KiB
Python
from django import forms
|
|
|
|
class NewHoleForm(forms.Form):
|
|
# Identification
|
|
tag_id = forms.CharField(label="New Cave Identifier",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2029-XY-03'}),
|
|
max_length=50, required=True)
|
|
tag_text = forms.CharField(label="Exact text on tag if placed",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 29 CUCC 35'}),
|
|
max_length=50, required=False)
|
|
# Naming
|
|
proposed_name = forms.CharField(label="Proposed Cave Name",
|
|
max_length=90, required=True)
|
|
|
|
# Discovery
|
|
discoverers = forms.CharField(label="Discoverers / Investigators today",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. Dour, Animal, Becka'}),
|
|
max_length=255, required=True)
|
|
discovery_date = forms.DateField(label="Trip date", widget=forms.DateInput(attrs={'type': 'date'}), required=True)
|
|
surface_wallet = forms.CharField(label="Wallet used to find the entrance (if any)",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2005 # 63'}),
|
|
max_length=100, required=False)
|
|
|
|
# GPS Data
|
|
gps_owner = forms.CharField(label="GPS: Whose device?",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. Becka'}),
|
|
max_length=100, required=True)
|
|
gps_lat = forms.FloatField(
|
|
label="GPS Latitude",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 47.6964483 N'}), required=True
|
|
)
|
|
gps_long = forms.FloatField(
|
|
label="GPS Longitude",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 13.8160500 E'}), required=True
|
|
)
|
|
gps_time = forms.TimeField(
|
|
label="Time of GPS reading",
|
|
widget=forms.TimeInput(attrs={'type': 'time'})
|
|
)
|
|
gps_screenshot = forms.BooleanField(label="Screenshot taken of GPSTest while GPS device in situ?", required=False)
|
|
gps_photo = forms.BooleanField(label="Photo taken of GPS device in situ with view of entrance?", required=False)
|
|
|
|
# Navigation
|
|
dist_to_ent = forms.FloatField(label="Distance from GPS to entrance (m)",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 11.5'})
|
|
)
|
|
bear_to_ent = forms.FloatField(label="Compass bearing to entrance (degrees)",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 217'})
|
|
)
|
|
|
|
# Status & Surveys
|
|
is_explored = forms.BooleanField(label="Exploration complete?", required=False)
|
|
ug_survey_done = forms.BooleanField(label="Survex data recorded?", required=False)
|
|
ug_survey_wallet = forms.CharField(label="Wallet id for all this data",
|
|
widget=forms.TextInput(attrs={'placeholder': 'e.g. 2029 # 88'}),
|
|
required=True)
|
|
|
|
# Media: Entrance Photo (Replaced dropdown with checkboxes)
|
|
photo_ent_no = forms.BooleanField(label="Entrance photos ?", required=False)
|
|
photo_ent_who = forms.CharField(label="Who has entrance photos ?", required=False)
|
|
|
|
# Media: Tag Photo (Replaced dropdown with checkboxes)
|
|
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
|
|
|
|
def new_hole(request):
|
|
if request.method == 'POST':
|
|
form = NewHoleForm(request.POST, request.FILES)
|
|
if form.is_valid():
|
|
# Data processing to models and filesystem will go here
|
|
messages.success(request, "New cave data successfully received.")
|
|
return redirect('some_success_url')
|
|
else:
|
|
form = NewHoleForm()
|
|
|
|
return render(request, 'new_hole.html', {'form': form}) |