diff options
Diffstat (limited to 'core/forms.py')
-rw-r--r-- | core/forms.py | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/core/forms.py b/core/forms.py index 0bcd6ef..ccdd307 100644 --- a/core/forms.py +++ b/core/forms.py @@ -103,7 +103,7 @@ class CaveForm(ModelForm): length = forms.CharField(required=False, label="Length (m)", widget=forms.TextInput(attrs={"placeholder": "usually blank"})) depth = forms.CharField(required=False, label="Depth (m)", widget=forms.TextInput(attrs={"placeholder": "usually blank"})) extent = forms.CharField(required=False, label="Extent (m)", widget=forms.TextInput(attrs={"placeholder": "usually blank"})) - areacode = forms.CharField(required=False, label="Area code", widget=forms.TextInput(attrs={"placeholder": "e.g. 1623"})) + areacode = forms.CharField(required=False, label="Area code", widget=forms.TextInput(attrs={"placeholder": "e.g. 1623"})) # should be required=True? subarea = forms.CharField(required=False, label="Subarea (do not use for new caves)", widget=forms.TextInput(attrs={"placeholder": "usually blank, archaic"})) #cave_slug = forms.CharField() @@ -143,12 +143,11 @@ class CaveForm(ModelForm): 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 cleaned_data.get("url") == []: - # self._errors["url"] = self.error_class(["This field is required."]) - # if cleaned_data.get("url") and cleaned_data.get("url").startswith("/"): - # self._errors["url"] = self.error_class(["This field cannot start with a /."]) + if self.data.get("areacode") not in ["1623", "1626", "1627", "1624"]: + self._errors["areacode"] = self.error_class( + ["An Austrian kataster areacode, i.e. 1623, 1626, 1627, or 1624 is required."] + ) + return cleaned_data @@ -257,10 +256,14 @@ class EntranceForm(ModelForm): ) def clean(self): - # if self.cleaned_data.get("url"): # can remove this as the form does not have a url field any more, which was never used anyway - # if self.cleaned_data.get("url").startswith("/"): - # self._errors["url"] = self.error_class(["This field cannot start with a /."]) - return self.cleaned_data + cleaned_data = super(EntranceForm, self).clean() # where is this code hidden? How does this work?? + for station in ["tag_station", "other_station"]: + print(f"{station} -- {self.data.get(station)[:4]}") + if self.data.get(station)[:5] not in ["1623.", "1626.", "1627.", "1624.", ""]: + self._errors[station] = self.error_class( + ["An Austrian kataster areacode, i.e. 1623, 1626, 1627, or 1624 prefix is required."] + ) + return self.cleaned_data # # This next line is sufficient to create an entire entry for for the cave fields automatically |