Repository: ciudadanointeligente/votainteligente-portal-electoral

Issue:
Comentarios sobre tu propuesta arreglar el orden del formulario
El formulario actualmente se ve así:

![uploads/38adcd34-544f-40ff-8252-546c99510843/Captura de pantalla 2016-07-26 a las 12.19.13 p.m..png](https://s3-us-west-2.amazonaws.com/prod.huboard.com/uploads%2F38adcd34-544f-40ff-8252-546c99510843%2FCaptura+de+pantalla+2016-07-26+a+las+12.19.13+p.m..png)

Y debería verse al menos con los campos en orden y con los títulos de los campos.
Si pudiese también tener un preview sería bacán.
Por otro lado, este fomrularion no necesita llevar el T&C.

<!---
@huboard:{"order":0.21857507872375723,"milestone_order":0.21857507872375723,"custom_state":""}
-->



Discussion:

Resolving patch:
diff --git a/popular_proposal/forms/form_texts.py b/popular_proposal/forms/form_texts.py
--- a/popular_proposal/forms/form_texts.py
+++ b/popular_proposal/forms/form_texts.py
@@ -25,12 +25,12 @@
                  )
 
 TEXTS = OrderedDict({
-    'problem': {'label': u' ',
+    'problem': {'label': u'¿Cuál es el problema?',
                 'preview_question': u'¿Cuál es el problema?',
                 'help_text': u'',
                 'placeholder': u'Describe el problema que afecta a la comuna (o barrio) del que el alcalde debe hacerse cargo',
                 'long_text': "paso1.html"},
-    'causes': {'label': u' ',
+    'causes': {'label': u'¿Cuáles son las causas?',
                'preview_question': u'¿Cuáles son las causas?',
                'help_text': u'',
                'placeholder': u'Utiliza el ejercicio que te mostramos arriba para encontrar las causas del problema',
@@ -40,7 +40,7 @@
                  'help_text': u'',
                  'placeholder': u'Siguiendo el ejemplo, propongan la(s) medida(s) que el alcalde debe tomar para solucionar la causa del problema y poder alcanzar la situación ideal.',
                  'long_text': "paso3.html"},
-    'solution_at_the_end': {'label': u' ',
+    'solution_at_the_end': {'label': u'¿Cuál sería la solución?',
                             'preview_question': u'¿Cuál sería la solución?',
                             'help_text': u'',
                             'placeholder': u'Define la o las acciones que debe realizar el alcalde para que la propuesta se de por cumplida.',
diff --git a/popular_proposal/forms/forms.py b/popular_proposal/forms/forms.py
--- a/popular_proposal/forms/forms.py
+++ b/popular_proposal/forms/forms.py
@@ -52,6 +52,7 @@ def get_user_organizations_choicefield(user=None):
         'fields': OrderedDict([
             ('problem', forms.CharField(max_length=512,
                                         widget=forms.Textarea(),
+                                        label=u'¿Cuál es el problema?'
                                         ))
         ])
     },
@@ -61,6 +62,7 @@ def get_user_organizations_choicefield(user=None):
         'fields': OrderedDict([(
             'causes', forms.CharField(max_length=256,
                                       widget=forms.Textarea(),
+                                      label=u'¿Cuáles son las causas?'
                                       )
 
         )])
@@ -138,6 +140,7 @@ def __init__(self, *args, **kwargs):
 
 class ProposalFormBase(forms.Form, TextsFormMixin):
     def set_fields(self):
+        fields = OrderedDict()
         for steps in wizard_forms_fields:
             for field_name in steps['fields']:
                 field = steps['fields'][field_name]
@@ -146,12 +149,13 @@ def set_fields(self):
                     field = field.__call__(**kwargs)
                     if field is None:
                         continue
-                self.fields[field_name] = field
+                fields[field_name] = field
+        return fields
 
     def __init__(self, *args, **kwargs):
         self.proposer = kwargs.pop('proposer', None)
         super(ProposalFormBase, self).__init__(*args, **kwargs)
-        self.set_fields()
+        self.fields.update(self.set_fields())
         self.add_texts_to_fields()
 
 
@@ -232,19 +236,52 @@ def reject(self):
         self.temporary_data.reject(self.cleaned_data['reason'])
 
 
+FIELDS_TO_BE_AVOIDED = ['terms_and_conditions', ]
+
 class ProposalTemporaryDataUpdateForm(ProposalFormBase):
-    overall_comments = forms.CharField(required=False, label=_(u'Comentarios sobre tu revisón'))
+    overall_comments = forms.CharField(required=False,
+                                       label=_(u'Comentarios sobre tu revisón'),
+                                       widget=forms.Textarea())
+
 
     def __init__(self, *args, **kwargs):
         self.proposer = kwargs.pop('proposer')
         self.temporary_data = kwargs.pop('temporary_data')
+        field_order = self.get_fields_order(self.temporary_data)
         super(ProposalTemporaryDataUpdateForm, self).__init__(*args, **kwargs)
+        self.order_fields(field_order)
+        for field_to_be_avoided in FIELDS_TO_BE_AVOIDED:
+            self.fields.pop(field_to_be_avoided)
         self.initial = self.temporary_data.data
+        commented_fields = []
         for comment_key in self.temporary_data.comments.keys():
             comment = self.temporary_data.comments[comment_key]
             if comment:
+                commented_fields.append(comment_key)
                 self.fields[comment_key].help_text += _(' <b>Commentarios: %s </b>') % (comment)
 
+    def get_fields_order(self, temporary_data):
+        commented_fields = []
+        fields_at_the_end = ProposalTemporaryDataUpdateForm.base_fields
+        fields = self.set_fields()
+
+        for comment_key in temporary_data.comments.keys():
+            comment = temporary_data.comments[comment_key]
+            if comment:
+                commented_fields.append(comment_key)
+        keyOrder = commented_fields
+        for field in fields:
+            if field not in commented_fields and field not in fields_at_the_end:
+                keyOrder.append(field)
+        for field in fields_at_the_end:
+            keyOrder.append(field)
+        return keyOrder
+
+    def order_fields(self, field_order):
+        if hasattr(self, 'keyOrder'):
+            field_order = self.keyOrder
+        super(ProposalTemporaryDataUpdateForm, self).order_fields(field_order)
+
     def save(self):
         self.overall_comments = self.cleaned_data.pop('overall_comments')
         self.temporary_data.data = self.cleaned_data


Test patch:
diff --git a/popular_proposal/tests/form_tests.py b/popular_proposal/tests/form_tests.py
--- a/popular_proposal/tests/form_tests.py
+++ b/popular_proposal/tests/form_tests.py
@@ -4,6 +4,7 @@
                                     CommentsForm,
                                     RejectionForm,
                                     ProposalTemporaryDataUpdateForm,
+                                    FIELDS_TO_BE_AVOIDED,
                                     UpdateProposalForm,
                                     AreaForm)
 from django.contrib.auth.models import User
@@ -168,11 +169,34 @@ def test_update_temporary_popular_proposal(self):
         t_data = ProposalTemporaryData.objects.get(id=t_data.id)
         overall_comments = data.pop('overall_comments')
         for key in data.keys():
+            if key in FIELDS_TO_BE_AVOIDED:
+                continue
             self.assertEquals(t_data.data[key], data[key])
         self.assertEquals(t_data.status,
                           ProposalTemporaryData.Statuses.InOurSide)
         self.assertEquals(t_data.overall_comments, overall_comments)
 
+    def test_form_fields(self):
+        theirside_status = ProposalTemporaryData.Statuses.InTheirSide
+        t_data = ProposalTemporaryData.objects.create(proposer=self.fiera,
+                                                      area=self.arica,
+                                                      data=self.data,
+                                                      comments=self.comments,
+                                                      status=theirside_status)
+        data = self.data
+        data['solution'] = u'Viajar a ver al equipo una vez al mes'
+        data['overall_comments'] = u"Quizás sea una buena idea que revises si \
+        conviene el plazo de un año"
+        form = ProposalTemporaryDataUpdateForm(data=data,
+                                               temporary_data=t_data,
+                                               proposer=self.fiera)
+        self.assertNotIn('terms_and_conditions', form.fields)
+        first_field = form.fields.popitem(last=False)
+        # Because the field when has comments this should be the firstone
+        self.assertEquals(first_field[0], 'when')
+        last_field = form.fields.popitem()
+        self.assertEquals(last_field[0], 'overall_comments')
+
     def test_when_template_tag(self):
         choice = WHEN_CHOICES[1]
         template = Template(
@@ -250,4 +274,4 @@ def test_post_update_view(self):
         self.client.login(username=self.fiera.username, password='feroz')
         response = self.client.post(url, **kwargs)
         detail_url = reverse('popular_proposals:detail', kwargs={'slug': self.popular_proposal.slug})
-        self.assertRedirects(response, detail_url)
+        self.assertRedirects(response, detail_url)
\ No newline at end of file