Parcourir la source

Merge remote-tracking branch 'capslock/issue-12' into django

Fix #12
Jocelyn Delande il y a 9 ans
Parent
commit
18975e1b14

+ 3 - 1
.gitignore

@@ -4,4 +4,6 @@ __pycache__/
 *.sqlite3
 wifiwithme/settings/local.py
 var/media/*
-var/static/*
+var/static/*
+venv
+.idea

+ 6 - 0
wifiwithme/apps/contribmap/forms.py

@@ -62,3 +62,9 @@ class PublicContribForm(forms.ModelForm):
                                .replace('public', '')\
                                .replace('publiques', '')
             yield field
+
+    def __init__(self, *args, **kwargs):
+        super(PublicContribForm, self).__init__(*args, **kwargs)
+
+        for f in ['latitude', 'longitude']:
+            self.fields[f].error_messages['required'] = "Veuillez déplacer le curseur à l'endroit où vous voulez partager/accéder au service"

+ 2 - 2
wifiwithme/apps/contribmap/models.py

@@ -22,8 +22,8 @@ class Contrib(models.Model):
             (CONTRIB_CONNECT, 'Me raccorder au réseau expérimental'),
             (CONTRIB_SHARE, 'Partager une partie de ma connexion')
         ), default=None)
-    latitude = models.FloatField(blank=True, null=True)
-    longitude = models.FloatField(blank=True, null=True)
+    latitude = models.FloatField()
+    longitude = models.FloatField()
     phone = models.CharField(
         'Téléphone',
         max_length=30, blank=True, default='')

+ 2 - 2
wifiwithme/apps/contribmap/templates/contribmap/wifi-form.html

@@ -1,3 +1,4 @@
+
 {% extends "base.html" %}
 
 {% load bootstrap %}
@@ -140,9 +141,8 @@ pourraient être intéressantes.
 
         </div>
         {{ form.latitude }}
-        {{ form.latitude.errors }}
         {{ form.longitude }}
-        {{ form.longitude.errors }}
+        {% firstof form.latitude.errors form.latitude.errors %}
         </div>
       </div>
 

+ 5 - 4
wifiwithme/static/form.js

@@ -22,16 +22,17 @@ $( document ).ready(function() {
         maxWidth: 150
     }).addTo(map);
 
-    // Create marker
-    var marker = L.marker([defaults.lat,defaults.lng], {
+    var marker = L.marker([defaults.lat, defaults.lng], {
         draggable: true
     }).addTo(map);
 
     // every time the marker is dragged, update the coordinates container
     marker.on('dragend', mapUpdateCoords);
 
-    // Set the initial marker coordinate on load.
-    mapUpdateCoords();
+    map.on('click', (e) => {
+        marker.setLatLng(e.latlng)
+        mapUpdateCoords()
+    });
 
     function mapUpdateCoords() {
         var m = marker.getLatLng();