From 60c183129356bdbf8623cf7bc9d091bcd0a7f30f Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Mon, 23 Aug 2021 17:17:41 +0000 Subject: [PATCH] (WIP) Insist new-space creators move the map location pin Mini attempt at disuading bots --- main/forms.py | 17 +++++++++++++++-- main/templates/main/new_space.html | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/main/forms.py b/main/forms.py index ccd5647..31e674e 100644 --- a/main/forms.py +++ b/main/forms.py @@ -135,5 +135,18 @@ class NewSpaceForm(forms.Form): address = forms.CharField(widget=forms.Textarea, required=True) have_premises = forms.BooleanField(required=False) notes = forms.CharField(widget=forms.Textarea, required=False) - lat = forms.DecimalField(max_digits=10, decimal_places=7, initial=54.1) - lng = forms.DecimalField(max_digits=10, decimal_places=7, initial=-2.1) + lat = forms.DecimalField(min_value=1.92, max_value=62.95, max_digits=10, decimal_places=7, initial=51.28) + lng = forms.DecimalField(min_value=-10.87, max_value=49.74, max_digits=10, decimal_places=7, initial=-3.19) + + def clean(self): + cleaned_data = super().clean() + print(cleaned_data) + lat = cleaned_data.get('lat') + lng = cleaned_data.get('lng') + + if float(lat) == 51.28 and float(lng) == -3.19: + print('They match') + raise forms.ValidationError( + "You have not picked your location on the map, please do so" + ) + return cleaned_data diff --git a/main/templates/main/new_space.html b/main/templates/main/new_space.html index af59791..ca5ba2f 100644 --- a/main/templates/main/new_space.html +++ b/main/templates/main/new_space.html @@ -121,7 +121,7 @@

New Space Info

function initMap() { - map = L.map('map').setView([lat, lng], 16); + map = L.map('map').setView([lat, lng], 10); L.tileLayer( 'https://api.mapbox.com/styles/v1/axford/cj1c0rdnm00cc2smk5tz8e9yg/tiles/256/{z}/{x}/{y}?access_token={{ MAPBOX_ACCESS_TOKEN }}', {