Parcourir la source

Merge branch 'master' into refactor_tpl

Jocelyn Delande il y a 10 ans
Parent
commit
7f9e86d86c
3 fichiers modifiés avec 31 ajouts et 7 suppressions
  1. 7 2
      assets/form.js
  2. 16 2
      backend.py
  3. 8 3
      views/wifi-form.tpl

+ 7 - 2
assets/form.js

@@ -8,7 +8,7 @@ $( document ).ready(function() {
     }
     }
 
 
     // Create map
     // Create map
-    var map = L.map('map').setView([defaults.lat,defaults.lng], defaults.zoom);
+    var map = L.map('map', {scrollWheelZoom: false}).setView([defaults.lat,defaults.lng], defaults.zoom);
     L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
     L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
         attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
         attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
         maxZoom: 18
         maxZoom: 18
@@ -89,4 +89,9 @@ $( document ).ready(function() {
         else { $('#contrib-type-share').slideUp(); }
         else { $('#contrib-type-share').slideUp(); }
     });
     });
 
 
-});
+    // select/deselect all checkbox
+    $('#orientation-all').change(function(e){
+        $('input[name="orientation"]').prop('checked', $(e.target).is(':checked') );
+    });
+
+});

+ 16 - 2
backend.py

@@ -39,6 +39,7 @@ DB_COLS = (
 ('bandwidth', 'REAL'),
 ('bandwidth', 'REAL'),
 ('share_part', 'REAL'),
 ('share_part', 'REAL'),
 ('floor', 'INTEGER'),
 ('floor', 'INTEGER'),
+('floor_total', 'INTEGER'),
 ('orientations', 'TEXT'),
 ('orientations', 'TEXT'),
 ('roof', 'INTEGER'),
 ('roof', 'INTEGER'),
 ('comment', 'TEXT'),
 ('comment', 'TEXT'),
@@ -68,9 +69,9 @@ def save_to_db(db, dic):
     tosave['date'] = utils.formatdate()
     tosave['date'] = utils.formatdate()
     return db.execute("""
     return db.execute("""
 INSERT INTO {}
 INSERT INTO {}
-(name, contrib_type, latitude, longitude, phone, email, access_type, bandwidth, share_part, floor, orientations, roof, comment,
+(name, contrib_type, latitude, longitude, phone, email, access_type, bandwidth, share_part, floor, floor_total, orientations, roof, comment,
 privacy_name, privacy_email, privacy_place_details, privacy_coordinates, privacy_comment, date)
 privacy_name, privacy_email, privacy_place_details, privacy_coordinates, privacy_comment, date)
-VALUES (:name, :contrib_type, :latitude, :longitude, :phone, :email, :access_type, :bandwidth, :share_part, :floor, :orientations, :roof, :comment,
+VALUES (:name, :contrib_type, :latitude, :longitude, :phone, :email, :access_type, :bandwidth, :share_part, :floor, :floor_total, :orientations, :roof, :comment,
         :privacy_name, :privacy_email, :privacy_place_details, :privacy_coordinates, :privacy_comment, :date)
         :privacy_name, :privacy_email, :privacy_place_details, :privacy_coordinates, :privacy_comment, :date)
 """.format(TABLE_NAME), tosave)
 """.format(TABLE_NAME), tosave)
 
 
@@ -94,6 +95,8 @@ def submit_wifi_form():
         'access-type' : 'Type de connexion',
         'access-type' : 'Type de connexion',
         'bandwidth'   : 'Bande passante',
         'bandwidth'   : 'Bande passante',
         'share-part'  : 'Débit partagé',
         'share-part'  : 'Débit partagé',
+        'floor' : 'Étage',
+        'floor_total' : 'Nombre d\'étages total'
     }
     }
 
 
     errors = []
     errors = []
@@ -114,6 +117,14 @@ def submit_wifi_form():
                 if not request.forms.get(name):
                 if not request.forms.get(name):
                     errors.append(
                     errors.append(
                         (field_names[name], 'ce champ est requis'))
                         (field_names[name], 'ce champ est requis'))
+
+    if request.forms.get('floor') and not request.forms.get('floor_total'):
+        errors.append((field_names['floor_total'], "ce champ est requis"))
+    elif not request.forms.get('floor') and request.forms.get('floor_total'):
+        errors.append((field_names['floor'], "ce champ est requis"))
+    elif request.forms.get('floor') and request.forms.get('floor_total') and (request.forms.get('floor') > request.forms.get('floor_total')):
+        errors.append((field_names['floor'], "Étage supérieur au nombre total"))
+
     if errors:
     if errors:
         return template('wifi-form', errors=errors, data=request.forms,
         return template('wifi-form', errors=errors, data=request.forms,
                         orientations=ORIENTATIONS)
                         orientations=ORIENTATIONS)
@@ -131,6 +142,7 @@ def submit_wifi_form():
                 'bandwidth'            : d.get('bandwidth'),
                 'bandwidth'            : d.get('bandwidth'),
                 'share_part'           : d.get('share-part'),
                 'share_part'           : d.get('share-part'),
                 'floor'                : d.get('floor'),
                 'floor'                : d.get('floor'),
+                'floor_total'                : d.get('floor_total'),
                 'orientations'         : ','.join(d.getall('orientation')),
                 'orientations'         : ','.join(d.getall('orientation')),
                 'roof'         : d.get('roof'),
                 'roof'         : d.get('roof'),
                 'comment'              : d.get('comment'),
                 'comment'              : d.get('comment'),
@@ -217,6 +229,7 @@ def build_geojson():
                 "name" : row['name'],
                 "name" : row['name'],
                 "place" : {
                 "place" : {
                     'floor' : row['floor'],
                     'floor' : row['floor'],
+                    'floor_total' : row['floor_total'],
                     'orientations' : row['orientations'].split(','),
                     'orientations' : row['orientations'].split(','),
                     'roof' : row['roof'],
                     'roof' : row['roof'],
                 },
                 },
@@ -249,6 +262,7 @@ def build_geojson():
         if not row['privacy_place_details']:
         if not row['privacy_place_details']:
             public_feature['properties']['place'] = {
             public_feature['properties']['place'] = {
                 'floor' : row['floor'],
                 'floor' : row['floor'],
+                'floor_total' : row['floor_total'],
                 'orientations' : row['orientations'].split(','),
                 'orientations' : row['orientations'].split(','),
                 'roof' : row['roof'],
                 'roof' : row['roof'],
             }
             }

+ 8 - 3
views/wifi-form.tpl

@@ -149,7 +149,9 @@ Un moyen de contact au moins est nécessaire
     <p class="help-block">Les antennes peuvent être positionées soit sur le toit soit aux fenêtres</p>
     <p class="help-block">Les antennes peuvent être positionées soit sur le toit soit aux fenêtres</p>
 
 
     <div class="form-group">
     <div class="form-group">
-    <label for="orientation" />Orientation(s) de mes fenêtres</label><br />
+    <label for="orientation" />Orientation(s) de mes fenêtres</label>
+    (<label class="ceckbox-inline"><input type="checkbox" name="orientation-all" id="orientation-all" value="" />Vue à 360°</label>)
+    <br>
 %for val, label in orientations:
 %for val, label in orientations:
     <label class="checkbox-inline">
     <label class="checkbox-inline">
       <input type="checkbox" name="orientation" value="{{val}}"
       <input type="checkbox" name="orientation" value="{{val}}"
@@ -166,10 +168,13 @@ Un moyen de contact au moins est nécessaire
         </label>
         </label>
     </div>
     </div>
 
 
-    <p>
+    <p class="form-inline">
       <label for="floor">Étage</label>
       <label for="floor">Étage</label>
       <input name="floor" value="{{data.get('floor', '')}}"
       <input name="floor" value="{{data.get('floor', '')}}"
-             id="floor" type="number" class="form-control" placeholder="Indiquer  « 0 » pour le Rez-de-chaussée"/>
+             id="floor" type="number" class="form-control" placeholder="«0» pour le RDC"/>
+      <span>/</span>
+      <input name="floor_total" value="{{data.get('floor_total', '')}}"
+             id="floor_total" type="number" class="form-control" placeholder="Nombre d'étages"/>
     </p>
     </p>
 
 
     <h2>Remarque/commentaire</h2>
     <h2>Remarque/commentaire</h2>