Browse Source

Put back orientations selection in form

Jocelyn Delande 9 years ago
parent
commit
79535b3bfd

+ 6 - 1
wifiwithme/apps/contribmap/fields.py

@@ -21,12 +21,17 @@ class CommaSeparatedCharField(models.CharField):
     def to_python(self, value):
         if isinstance(value, CommaSeparatedList):
             return value
+        elif isinstance(value, collections.Iterable):
+            return CommaSeparatedList(value)
 
-        if value is None:
+        elif value is None:
             return value
 
         return CommaSeparatedList([i.strip() for i in value.split(',')])
 
+    def clean(self, *args, **kwargs):
+        return super().clean(*args, **kwargs)
+
     def get_prep_value(self, value):
         if isinstance(value, collections.Iterable):
             return ','.join(value)

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

@@ -3,6 +3,18 @@ from django import forms
 from .models import Contrib
 
 
+ORIENTATIONS = (
+    ('N', 'Nord'),
+    ('NO', 'Nord-Ouest'),
+    ('O', 'Ouest'),
+    ('SO', 'Sud-Ouest'),
+    ('S', 'Sud'),
+    ('SE', 'Sud-Est'),
+    ('E', 'Est'),
+    ('NE', 'Nord-Est'),
+)
+
+
 class PublicContribForm(forms.ModelForm):
     class Meta:
         model = Contrib
@@ -27,3 +39,5 @@ class PublicContribForm(forms.ModelForm):
             'connect_local': forms.CheckboxInput,
             'connect_internet': forms.CheckboxInput,
         }
+    # Widget rendering is managed by hand in template for orientions.
+    orientations = forms.MultipleChoiceField(choices=ORIENTATIONS)

+ 16 - 0
wifiwithme/apps/contribmap/templates/contribmap/wifi-form.html

@@ -141,6 +141,22 @@ pourraient être intéressantes.
       </div>
     </div>
 
+    <p class="help-block">Les antennes peuvent être positionées soit sur le toit soit aux fenêtres/balcons/velux.</p>
+
+    <div class="form-group">
+      <label for="orientation" />Orientation(s) de mes fenêtres, balcons ou velux</label>
+
+    (<label class="checkbox-inline"><input type="checkbox" name="orientation-all" id="orientation-all" value="" />Vue à 360°</label>)
+      <br>
+{% for val, label in form.orientations.field.choices %}
+    <label class="checkbox-inline">
+      <input type="checkbox" class="orientation" name="orientations" value="{{ val }}"
+             {% if val in form.orientations.value %}checked="yes"{% endif %}/>
+      {{label}}
+    </label>
+{% endfor %}
+    {{ form.orientations.errors }}
+    </label>
     <input type="submit" value="Envoyer" class="btn btn-primary btn-lg"/>
   </form>
   </section>

+ 3 - 3
wifiwithme/static/form.js

@@ -114,13 +114,13 @@ $( document ).ready(function() {
 
     // select/deselect all checkbox
     $('#orientation-all').change(function(e){
-        $('input[name="orientation"]').prop('checked', $(e.target).is(':checked') );
+        $('input[name="orientations"]').prop('checked', $(e.target).is(':checked') );
     });
-    $('.orientation').change(function(e){
+    $('.orientations').change(function(e){
         if (! $(e.target).is(':checked')) {
             $('input[name="orientation-all"]').prop('checked', false);
         }
-        if ($('.orientation').filter(':not(:checked)').length == 0) {
+        if ($('.orientations').filter(':not(:checked)').length == 0) {
             $('input[name="orientation-all"]').prop('checked', true);
         }
     });