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
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
from tinymce.widgets import TinyMCE
|
|
|
|
|
2020-05-30 01:11:02 +01:00
|
|
|
from troggle.core.models import Person, PersonExpedition, Expedition
|
|
|
|
from troggle.core.models_caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance
|
2020-05-28 04:54:53 +01:00
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
class CaveForm(ModelForm):
|
2012-08-06 11:19:48 +01:00
|
|
|
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())
|
2012-08-12 18:10:23 +01:00
|
|
|
url = forms.CharField(required = True)
|
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."])
|
|
|
|
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."])
|
2017-10-25 03:49:03 +01:00
|
|
|
if self.cleaned_data.get("url") and self.cleaned_data.get("url").startswith("/"):
|
2015-09-16 01:52:45 +01:00
|
|
|
self._errors["url"] = self.error_class(["This field can not start with a /."])
|
2012-08-14 21:51:15 +01:00
|
|
|
return self.cleaned_data
|
|
|
|
|
2012-06-10 14:59:21 +01:00
|
|
|
class VersionControlCommentForm(forms.Form):
|
|
|
|
description_of_change = forms.CharField(required = True, widget=forms.Textarea())
|
2012-05-23 09:23:40 +01:00
|
|
|
|
|
|
|
|
2012-06-10 14:59:21 +01:00
|
|
|
class EntranceForm(ModelForm):
|
|
|
|
#underground_description = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
#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}))
|
2019-03-30 17:02:07 +00:00
|
|
|
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
|
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("/"):
|
|
|
|
self._errors["url"] = self.error_class(["This field can not start with a /."])
|
|
|
|
return self.cleaned_data
|
2012-06-10 14:59:21 +01:00
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
|
2012-08-12 18:10:23 +01:00
|
|
|
|
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):
|
|
|
|
class Meta:
|
|
|
|
model = CaveAndEntrance
|
|
|
|
exclude = ('cave', 'entrance')
|
|
|
|
|
2011-07-11 02:10:22 +01:00
|
|
|
#class PersonForm(ModelForm):
|
|
|
|
# class Meta:
|
|
|
|
# model = Person
|
|
|
|
|
|
|
|
#class LogbookEntryForm(ModelForm):
|
|
|
|
# class Meta:
|
|
|
|
# model = LogbookEntry#
|
|
|
|
|
|
|
|
# def wikiLinkHints(LogbookEntry=None):
|
|
|
|
# """
|
|
|
|
# This function returns html-formatted paragraphs for each of the
|
|
|
|
# wikilink types that are related to this logbookentry. Each paragraph
|
|
|
|
# contains a list of all of the related wikilinks.
|
|
|
|
#
|
|
|
|
# Perhaps an admin javascript solution would be better.
|
|
|
|
# """
|
|
|
|
# res = ["Please use the following wikilinks, which are related to this logbook entry:"]
|
|
|
|
#
|
|
|
|
# res.append(r'</p><p style="float: left;"><b>QMs found:</b>')
|
|
|
|
# for QM in LogbookEntry.instance.QMs_found.all():
|
|
|
|
# res.append(QM.wiki_link())
|
|
|
|
|
|
|
|
# res.append(r'</p><p style="float: left;"><b>QMs ticked off:</b>')
|
|
|
|
# for QM in LogbookEntry.instance.QMs_ticked_off.all():
|
|
|
|
# res.append(QM.wiki_link())
|
|
|
|
|
|
|
|
# res.append(r'</p><p style="float: left; "><b>People</b>')
|
|
|
|
# for persontrip in LogbookEntry.instance.persontrip_set.all():
|
|
|
|
# res.append(persontrip.wiki_link())
|
|
|
|
# res.append(r'</p>')
|
|
|
|
|
|
|
|
# return string.join(res, r'<br />')
|
|
|
|
|
|
|
|
# def __init__(self, *args, **kwargs):
|
|
|
|
# super(LogbookEntryForm, self).__init__(*args, **kwargs)
|
|
|
|
# self.fields['text'].help_text=self.wikiLinkHints()#
|
|
|
|
|
2012-01-07 19:05:25 +00:00
|
|
|
#class CaveForm(forms.Form):
|
|
|
|
# html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
def getTripForm(expedition):
|
|
|
|
|
|
|
|
class TripForm(forms.Form):
|
|
|
|
date = forms.DateField()
|
|
|
|
title = forms.CharField(max_length=200)
|
2020-05-24 01:57:06 +01:00
|
|
|
caves = sorted([cave.reference() for cave in Cave.objects.all()])
|
2011-07-11 02:10:22 +01:00
|
|
|
caves = ["-----"] + caves
|
|
|
|
cave = forms.ChoiceField([(c, c) for c in caves], required=False)
|
|
|
|
location = forms.CharField(max_length=200, required=False)
|
|
|
|
caveOrLocation = forms.ChoiceField([("cave", "Cave"), ("location", "Location")], widget = forms.widgets.RadioSelect())
|
|
|
|
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
|
|
|
|
def clean(self):
|
2020-05-24 01:57:06 +01:00
|
|
|
print((dir(self)))
|
2011-07-11 02:10:22 +01:00
|
|
|
if self.cleaned_data.get("caveOrLocation") == "cave" and not self.cleaned_data.get("cave"):
|
|
|
|
self._errors["cave"] = self.error_class(["This field is required"])
|
|
|
|
if self.cleaned_data.get("caveOrLocation") == "location" and not self.cleaned_data.get("location"):
|
|
|
|
self._errors["location"] = self.error_class(["This field is required"])
|
|
|
|
return self.cleaned_data
|
|
|
|
|
|
|
|
class PersonTripForm(forms.Form):
|
2020-05-24 01:57:06 +01:00
|
|
|
names = sorted([get_name(pe) for pe in PersonExpedition.objects.filter(expedition = expedition)])
|
2011-07-11 02:10:22 +01:00
|
|
|
names = ["-----"] + names
|
|
|
|
name = forms.ChoiceField([(n, n) for n in names])
|
|
|
|
TU = forms.FloatField(required=False)
|
2018-04-17 21:51:39 +01:00
|
|
|
author = forms.BooleanField(required=False, default=False)
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
PersonTripFormSet = formset_factory(PersonTripForm, extra=1)
|
|
|
|
|
|
|
|
return PersonTripFormSet, TripForm
|
|
|
|
|
|
|
|
def get_name(pe):
|
|
|
|
if pe.nickname:
|
|
|
|
return pe.nickname
|
|
|
|
else:
|
|
|
|
return pe.person.first_name
|
|
|
|
|
2020-06-04 23:00:58 +01:00
|
|
|
class UploadFileForm(forms.Form):
|
2020-06-08 00:11:09 +01:00
|
|
|
# Because this has EXECUTABLE statements in its signature (the fields) they get
|
|
|
|
# executed when this module is LOADED. Which barfs horribly.
|
|
|
|
# so all replaced by an __init__ method instead.
|
|
|
|
def __init__(self):
|
|
|
|
title = forms.CharField(max_length=50)
|
|
|
|
file = forms.FileField()
|
|
|
|
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
|
|
|
lon_utm = forms.FloatField(required=False)
|
|
|
|
lat_utm = forms.FloatField(required=False)
|
|
|
|
slug = forms.CharField(max_length=50)
|
|
|
|
date = forms.DateField(required=False)
|
|
|
|
|
|
|
|
#This next line is the one that causes django.setup() to BARF LOUDLY
|
|
|
|
caves = [cave.slug for cave in Cave.objects.all()]
|
|
|
|
#caves.sort() # sort needs rewriting for python3
|
|
|
|
caves = ["-----"] + caves
|
|
|
|
cave = forms.ChoiceField([(c, c) for c in caves], required=False)
|
2020-06-04 23:00:58 +01:00
|
|
|
|
2020-06-08 00:11:09 +01:00
|
|
|
entrance = forms.ChoiceField([("-----", "Please select a cave"), ], required=False)
|
|
|
|
qm = forms.ChoiceField([("-----", "Please select a cave"), ], required=False)
|
2020-06-04 23:00:58 +01:00
|
|
|
|
2020-06-08 00:11:09 +01:00
|
|
|
expeditions = [e.year for e in Expedition.objects.all()]
|
|
|
|
expeditions.sort()
|
|
|
|
expeditions = ["-----"] + expeditions
|
|
|
|
expedition = forms.ChoiceField([(e, e) for e in expeditions], required=False)
|
2020-06-04 23:00:58 +01:00
|
|
|
|
2020-06-08 00:11:09 +01:00
|
|
|
logbookentry = forms.ChoiceField([("-----", "Please select an expedition"), ], required=False)
|
2020-06-04 23:00:58 +01:00
|
|
|
|
2020-06-08 00:11:09 +01:00
|
|
|
person = forms.ChoiceField([("-----", "Please select an expedition"), ], required=False)
|
2020-06-04 23:00:58 +01:00
|
|
|
|
2020-06-08 00:11:09 +01:00
|
|
|
survey_point = forms.CharField()
|
2011-07-11 02:10:22 +01:00
|
|
|
|
|
|
|
|