2020-05-28 04:54:53 +01:00
|
|
|
import string
|
|
|
|
from datetime import date
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
import django.forms as forms
|
2020-05-28 04:54:53 +01:00
|
|
|
from django.forms import ModelForm
|
2012-06-10 14:59:21 +01:00
|
|
|
from django.forms.models import modelformset_factory
|
2011-07-11 02:10:22 +01:00
|
|
|
from django.contrib.admin.widgets import AdminDateWidget
|
2020-05-28 04:54:53 +01:00
|
|
|
|
2022-06-28 00:18:24 +01:00
|
|
|
from tinymce.widgets import TinyMCE
|
2011-07-11 02:10:22 +01:00
|
|
|
|
2021-04-30 18:02:05 +01:00
|
|
|
from troggle.core.models.troggle import Person, PersonExpedition, Expedition
|
2021-04-13 00:47:17 +01:00
|
|
|
from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance
|
2020-05-28 04:54:53 +01:00
|
|
|
|
2022-06-26 21:29:46 +01:00
|
|
|
from troggle.core.views.editor_helpers import HTMLarea
|
|
|
|
|
2022-03-22 02:22:15 +00:00
|
|
|
'''These are all the class-based Forms used by troggle.
|
|
|
|
There are other, simpler, upload forms in view/uploads.py
|
2021-04-13 01:37:42 +01:00
|
|
|
Some are not used and need renovating or destroying.
|
|
|
|
'''
|
|
|
|
|
2021-04-30 23:21:38 +01:00
|
|
|
todo = '''Re-enable TinyMCE
|
2021-04-21 19:08:42 +01:00
|
|
|
'''
|
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
class CaveForm(ModelForm):
|
2021-04-14 16:28:30 +01:00
|
|
|
'''Only those fields for which we want to override defaults are listed here
|
2021-04-21 19:08:42 +01:00
|
|
|
the other fields are present on the form, but use the default presentation style
|
2021-04-14 16:28:30 +01:00
|
|
|
'''
|
2022-06-28 00:18:24 +01:00
|
|
|
|
2021-04-14 16:28:30 +01:00
|
|
|
official_name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
|
2022-06-26 21:29:46 +01:00
|
|
|
underground_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
explorers = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
equipment = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
survey = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
2021-04-14 16:28:30 +01:00
|
|
|
#survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
|
|
|
kataster_status = forms.CharField(required = False)
|
2022-06-26 21:29:46 +01:00
|
|
|
underground_centre_line = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
notes = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
references = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
2021-04-14 16:28:30 +01:00
|
|
|
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)")
|
2022-06-28 00:18:24 +01:00
|
|
|
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."])
|
|
|
|
# if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
|
|
|
# self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
|
|
|
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 cannot start with a /."])
|
|
|
|
return self.cleaned_data
|
|
|
|
|
|
|
|
|
|
|
|
class CaveFormTextArea(ModelForm):
|
|
|
|
'''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 presentation 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':9}))
|
|
|
|
equipment = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
|
|
|
|
survey = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
|
|
|
|
#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':9}))
|
|
|
|
notes = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
|
|
|
|
references = forms.CharField(required = False, widget=forms.Textarea(attrs={'rows':9}))
|
|
|
|
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."])
|
|
|
|
# if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
|
|
|
# self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
|
|
|
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 cannot start with a /."])
|
|
|
|
return self.cleaned_data
|
|
|
|
|
|
|
|
|
|
|
|
class CaveFormCodeMirrorPreview(ModelForm):
|
|
|
|
'''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 presentation style
|
|
|
|
'''
|
|
|
|
|
|
|
|
official_name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
|
|
|
|
underground_description = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
explorers = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
equipment = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
survey = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
#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=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
notes = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
references = forms.CharField(required = False, widget=HTMLarea(preview = True,
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
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."])
|
|
|
|
# if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
|
|
|
# self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
|
|
|
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 cannot start with a /."])
|
|
|
|
return self.cleaned_data
|
|
|
|
|
|
|
|
class CaveFormTinyMCE(ModelForm):
|
|
|
|
'''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 presentation style
|
|
|
|
'''
|
|
|
|
|
|
|
|
official_name = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
|
|
|
|
underground_description = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
equipment = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
survey = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
#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=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
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)")
|
2021-04-14 16:28:30 +01:00
|
|
|
extent = forms.CharField(required = False, label="Extent (m)")
|
2012-01-07 19:05:25 +00:00
|
|
|
class Meta:
|
|
|
|
model = Cave
|
2012-08-12 18:10:23 +01:00
|
|
|
exclude = ("filename",)
|
2012-01-07 19:05:25 +00:00
|
|
|
|
2012-08-14 21:51:15 +01:00
|
|
|
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."])
|
2021-04-25 04:04:53 +01:00
|
|
|
# if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "":
|
|
|
|
# self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."])
|
2012-08-14 21:51:15 +01:00
|
|
|
if self.cleaned_data.get("area") == []:
|
|
|
|
self._errors["area"] = self.error_class(["This field is required."])
|
2017-10-25 03:49:03 +01:00
|
|
|
if self.cleaned_data.get("url") and self.cleaned_data.get("url").startswith("/"):
|
2021-04-14 16:28:30 +01:00
|
|
|
self._errors["url"] = self.error_class(["This field cannot start with a /."])
|
2012-08-14 21:51:15 +01:00
|
|
|
return self.cleaned_data
|
|
|
|
|
2012-06-10 14:59:21 +01:00
|
|
|
class EntranceForm(ModelForm):
|
2021-04-14 16:28:30 +01:00
|
|
|
'''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'}))
|
2022-06-27 00:34:08 +01:00
|
|
|
entrance_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
2021-04-14 16:28:30 +01:00
|
|
|
explorers = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
|
2012-06-10 14:59:21 +01:00
|
|
|
#explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
2022-06-27 00:34:08 +01:00
|
|
|
map_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
location_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
approach = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
underground_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
photo = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
marking_comment = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
findability_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
other_description = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
|
|
|
bearings = forms.CharField(required = False, widget=HTMLarea(
|
|
|
|
attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
|
2021-04-14 16:28:30 +01:00
|
|
|
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)
|
2021-05-07 23:21:57 +01:00
|
|
|
lat_wgs84 = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': '10'}), label="Latitude (WSG84)")
|
|
|
|
long_wgs84 = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': '10'}), label="Longitude (WSG84)")
|
2021-04-14 16:28:30 +01:00
|
|
|
alt = forms.CharField(required=False, label="Altitude (m)")
|
|
|
|
url = forms.CharField(required = False, label="URL [usually blank]", widget=forms.TextInput(attrs={'size': '45'}))
|
2012-06-10 14:59:21 +01:00
|
|
|
class Meta:
|
|
|
|
model = Entrance
|
2012-08-12 18:10:23 +01:00
|
|
|
exclude = ("cached_primary_slug", "filename",)
|
2015-09-16 01:52:45 +01:00
|
|
|
def clean(self):
|
|
|
|
if self.cleaned_data.get("url").startswith("/"):
|
2021-04-14 16:28:30 +01:00
|
|
|
self._errors["url"] = self.error_class(["This field cannot start with a /."])
|
2015-09-16 01:52:45 +01:00
|
|
|
return self.cleaned_data
|
2012-06-10 14:59:21 +01:00
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
|
2021-04-21 22:09:20 +01:00
|
|
|
# This next line is called from the templates/edit_cave2.html template.
|
2022-03-17 00:41:29 +00:00
|
|
|
# This is sufficient to create an entire entry for for the cave fields automatically
|
2020-08-02 23:53:35 +01:00
|
|
|
# http://localhost:8000/cave/new/
|
2022-03-17 00:41:29 +00:00
|
|
|
# using django built-in Deep Magic. https://docs.djangoproject.com/en/3.2/topics/forms/modelforms/
|
|
|
|
# for forms which map directly onto a Django Model
|
2018-04-15 12:00:59 +01:00
|
|
|
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',))
|
2012-01-07 19:05:25 +00:00
|
|
|
|
2012-08-14 21:51:15 +01:00
|
|
|
class EntranceLetterForm(ModelForm):
|
2021-04-21 22:09:20 +01:00
|
|
|
'''Can't see what this does at all. called twice from views.caves
|
2021-04-14 16:28:30 +01:00
|
|
|
'''
|
2012-08-14 21:51:15 +01:00
|
|
|
class Meta:
|
|
|
|
model = CaveAndEntrance
|
|
|
|
exclude = ('cave', 'entrance')
|
|
|
|
|
2021-04-22 02:45:28 +01:00
|
|
|
|
|
|
|
|