diff options
Diffstat (limited to 'core/forms.py')
-rw-r--r-- | core/forms.py | 120 |
1 files changed, 119 insertions, 1 deletions
diff --git a/core/forms.py b/core/forms.py index f3df10a..8365a63 100644 --- a/core/forms.py +++ b/core/forms.py @@ -6,7 +6,7 @@ from django.forms import ModelForm from django.forms.models import modelformset_factory from django.contrib.admin.widgets import AdminDateWidget -#from tinymce.widgets import TinyMCE +from tinymce.widgets import TinyMCE from troggle.core.models.troggle import Person, PersonExpedition, Expedition from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance @@ -25,6 +25,7 @@ class CaveForm(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( attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"})) @@ -62,6 +63,123 @@ class CaveForm(ModelForm): 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)") + 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 EntranceForm(ModelForm): '''Only those fields for which we want to override defaults are listed here |