Cave and Entrance forms tuned to user needs

This commit is contained in:
Philip Sargent
2021-04-14 16:28:30 +01:00
parent 54d98f58f3
commit d8b1d59b12
5 changed files with 104 additions and 58 deletions

View File

@@ -16,20 +16,29 @@ Some are not used and need renovating or destroying.
'''
class CaveForm(ModelForm):
underground_description = forms.CharField(required = False, widget=forms.Textarea())
explorers = forms.CharField(required = False, widget=forms.Textarea())
equipment = forms.CharField(required = False, widget=forms.Textarea())
survey = forms.CharField(required = False, widget=forms.Textarea())
kataster_status = forms.CharField(required = False, widget=forms.Textarea())
underground_centre_line = forms.CharField(required = False, widget=forms.Textarea())
notes = forms.CharField(required = False, widget=forms.Textarea())
references = forms.CharField(required = False, widget=forms.Textarea())
url = forms.CharField(required = True)
'''Only those fields for which we want to override defaults are listed here
the other fields are present on the form, but use the default presentaiton style
'''
official_name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
underground_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
explorers = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
equipment = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
survey = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
#survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
kataster_status = forms.CharField(required = False)
underground_centre_line = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
notes = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
references = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':1}))
description_file = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
survex_file = forms.CharField(required = False, label="Survex file [caves-1623/000/000.svx]", widget=forms.TextInput(attrs={'size': '45'}))
url = forms.CharField(required = True, label="URL [1623/000/000]", widget=forms.TextInput(attrs={'size': '45'}))
length = forms.CharField(required = False, label="Length (m)")
depth = forms.CharField(required = False, label="Depth (m)")
extent = forms.CharField(required = False, label="Extent (m)")
class Meta:
model = Cave
exclude = ("filename",)
def clean(self):
if self.cleaned_data.get("kataster_number") == "" and self.cleaned_data.get("unofficial_number") == "":
self._errors["unofficial_number"] = self.error_class(["Either the kataster or unoffical number is required."])
@@ -38,44 +47,57 @@ class CaveForm(ModelForm):
if self.cleaned_data.get("area") == []:
self._errors["area"] = self.error_class(["This field is required."])
if self.cleaned_data.get("url") and self.cleaned_data.get("url").startswith("/"):
self._errors["url"] = self.error_class(["This field can not start with a /."])
self._errors["url"] = self.error_class(["This field cannot start with a /."])
return self.cleaned_data
class VersionControlCommentForm(forms.Form):
description_of_change = forms.CharField(required = True, widget=forms.Textarea())
'''Was appended to all forms. Not used currently
'''
description_of_change = forms.CharField(required = True, widget=forms.Textarea(attrs={'rows':2}))
class EntranceForm(ModelForm):
#underground_description = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
'''Only those fields for which we want to override defaults are listed here
the other fields are present on the form, but use the default presentaiton style
'''
name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
entrance_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
explorers = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
#explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#equipment = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#kataster_status = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
#references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
other_station = forms.CharField(required=False) # Trying to change this to a single line entry
tag_station = forms.CharField(required=False) # Trying to change this to a single line entry
exact_station = forms.CharField(required=False) # Trying to change this to a single line entry
northing = forms.CharField(required=False) # Trying to change this to a single line entry
easting = forms.CharField(required=False) # Trying to change this to a single line entry
alt = forms.CharField(required=False) # Trying to change this to a single line entry
map_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':3}))
location_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':3}))
approach = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':3}))
underground_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':3}))
photo = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
marking_comment = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
findability_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
other_description = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
bearings = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':2}))
other_station = forms.CharField(required=False)
tag_station = forms.CharField(required=False)
exact_station = forms.CharField(required=False)
northing = forms.CharField(required=False)
easting = forms.CharField(required=False)
alt = forms.CharField(required=False, label="Altitude (m)")
url = forms.CharField(required = False, label="URL [usually blank]", widget=forms.TextInput(attrs={'size': '45'}))
class Meta:
model = Entrance
exclude = ("cached_primary_slug", "filename",)
def clean(self):
if self.cleaned_data.get("url").startswith("/"):
self._errors["url"] = self.error_class(["This field can not start with a /."])
self._errors["url"] = self.error_class(["This field cannot start with a /."])
return self.cleaned_data
# This next is called from the templates/edit_cave2.html template.
# This is sufficeint to create an entire entry for for the cave fields automatically
# http://localhost:8000/cave/new/
# using django built-in stuff:
# using django built-in Deep magic. https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',))
class EntranceLetterForm(ModelForm):
'''Can't see what this does at all
'''
class Meta:
model = CaveAndEntrance
exclude = ('cave', 'entrance')
@@ -120,7 +142,7 @@ def get_name(pe):
return pe.person.first_name
class UploadFileForm(forms.Form):
"""Only called by views.others.newFile() whhich seems to be only about logbook files.
"""Only called by views.others.newFile() which seems to be only about logbook files.
"""
# Because this has EXECUTABLE statements in its signature (the fields) they get
# executed when this module is LOADED. Which barfs horribly.