Parcourir la source

Add floor_total field.

opi il y a 10 ans
Parent
commit
42f488c253
2 fichiers modifiés avec 21 ajouts et 4 suppressions
  1. 16 2
      backend.py
  2. 5 2
      views/wifi-form.tpl

+ 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'),
@@ -214,6 +226,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'],
                 },
                 },
@@ -246,6 +259,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'],
             }
             }

+ 5 - 2
views/wifi-form.tpl

@@ -187,10 +187,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>