From 136f9bf935fe49c8e2ffd37e58f19c20a54a48a4 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 28 Dec 2025 01:16:14 +0000 Subject: [PATCH] with more styling --- core/forms.py | 59 +++++++++++++++++++++++++++++++------ templates/new_prospect.html | 53 +++++++++++++++++++++------------ 2 files changed, 84 insertions(+), 28 deletions(-) diff --git a/core/forms.py b/core/forms.py index 8ad718e..83a7a4f 100644 --- a/core/forms.py +++ b/core/forms.py @@ -288,29 +288,70 @@ class EntranceLetterForm(ModelForm): class NewProspectForm(forms.Form): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # If the form is bound (POSTed), update the field's value to uppercase + if self.is_bound: + data = self.data.copy() + ident = data.get('identifier') + if ident: + data['identifier'] = ident.upper() + self.data = data + # If initial data is present, ensure it's uppercase too + if 'identifier' in self.initial: + self.initial['identifier'] = self.initial['identifier'].upper() + def clean_identifier(self): + identifier = self.cleaned_data['identifier'] + if identifier: + return identifier.upper() + return identifier + def clean_date_found(self): + date = self.cleaned_data['date_found'] + if date.year <= 1990: + raise forms.ValidationError('Year must be after 1990.') + return date + date_found = forms.DateField( - label="Date Found", - widget=forms.DateInput(attrs={"type": "date"}) + label="Date Found (YYYY-MM-DD)", + input_formats=["%Y-%m-%d"], + widget=forms.DateInput(attrs={ + "type": "text", + "placeholder": "2025-08-23", + "pattern": "\\d{4}-\\d{2}-\\d{2}", + "title": "Enter date as YYYY-MM-DD (e.g. 2025-08-23)", + "size": 10, + "style": "width: 10ch; min-width: 0;" + }) ) - area_code = forms.CharField( + area_code = forms.ChoiceField( label="Area Code", - max_length=10 + choices=[('1623', '1623'), ('1626', '1626')], + initial='1623', + widget=forms.Select(attrs={"style": "width: 6em; min-width: 0;"}) ) identifier = forms.CharField( - label="Identifier (e.g. 2025-AB-01)", - max_length=20 + label="New cave identifier", + max_length=20, + widget=forms.TextInput(attrs={ + "placeholder": "2025-AB-01", + "size": 10, + "style": "width: 10ch; min-width: 0;" + }) ) discovery_name = forms.CharField( label="Discovery Name", - max_length=100 + max_length=100, + widget=forms.TextInput(attrs={"placeholder": "Dreibierbittehohle"}) ) gps_lat = forms.DecimalField( label="GPS Latitude", max_digits=10, - decimal_places=7 + decimal_places=7, + widget=forms.NumberInput(attrs={"placeholder": "47.687180"}) ) gps_long = forms.DecimalField( label="GPS Longitude", max_digits=10, - decimal_places=7 + decimal_places=7, + widget=forms.NumberInput(attrs={"placeholder": "13.825211"}) ) diff --git a/templates/new_prospect.html b/templates/new_prospect.html index 115efeb..0060883 100644 --- a/templates/new_prospect.html +++ b/templates/new_prospect.html @@ -12,45 +12,60 @@ New Prospect

New Prospect

Please fill in the details for a new prospect: a hole which might be a cave. Fields are documented in the cave entry fields guide.

-{% if success %} -
Prospect submitted successfully. You can edit the details below or enter another.
-{% endif %} + -
- {% csrf_token %} -
+
+ + {% csrf_token %} {% for field in form %} -
+
{{ field }} {% if field.help_text %}{{ field.help_text }}{% endif %} - {% for error in field.errors %}
{{ error }}
{% endfor %} + {% for error in field.errors %}{{ error }}{% endfor %}
{% endfor %} -
-

- +
+ + +
+{% if success %} +
Prospect submitted successfully. You can edit the details below or enter another.
+{% endif %} {% endblock %}