summaryrefslogtreecommitdiffstats
path: root/core/forms.py
blob: 8365a638d324dbbe4a9f2b9773f389ec59b071a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import string
from datetime import date

import django.forms as forms
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 troggle.core.models.troggle import Person, PersonExpedition, Expedition
from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndEntrance

from troggle.core.views.editor_helpers import HTMLarea

'''These are all the class-based Forms used by troggle.
There are other, simpler, upload forms in view/uploads.py
Some are not used and need renovating or destroying.
'''

todo = '''Re-enable TinyMCE
'''

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)"}))
    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)"}))
    #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(
                                           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)"}))
    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 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
    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=HTMLarea(
                                           attrs={"height":"80%", "rows":20, 'placeholder': "Enter page content (using HTML)"}))
    explorers = forms.CharField(required = False, widget=forms.TextInput(attrs={'size': '45'}))
    #explorers = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
    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)"}))
    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)
    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)")
    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 cannot start with a /."])
        return self.cleaned_data


# This next line is called from the templates/edit_cave2.html template.
# This is sufficient to create an entire entry for for the cave fields automatically
# http://localhost:8000/cave/new/
# 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
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',))

class EntranceLetterForm(ModelForm):
    '''Can't see what this does at all. called twice from views.caves
    '''
    class Meta:
        model = CaveAndEntrance
        exclude = ('cave', 'entrance')