Repository: dotkom/onlineweb4

Issue:
[Feedback] - Display to the users what questions the company will see.
Illustrate in someway the questions that will be visible to the company.



Discussion:

Resolving patch:
diff --git a/apps/feedback/forms.py b/apps/feedback/forms.py
--- a/apps/feedback/forms.py
+++ b/apps/feedback/forms.py
@@ -19,11 +19,14 @@ def __init__(self, *args, **kwargs):
         self.helper.html5_required = False
         super(AnswerForm, self).__init__(*args, **kwargs)
         self.fields['answer'].label = self.instance.question.label
+        self.display = self.instance.question.display
 
 
 class RatingAnswerForm(AnswerForm):
-    answer = forms.ChoiceField(widget=forms.Select(attrs={"class": "rating", "name": "rating"}),
-                               choices=RATING_CHOICES)
+    answer = forms.ChoiceField(
+        widget=forms.Select(attrs={"class": "rating", "name": "rating"}),
+        choices=RATING_CHOICES
+    )
 
     class Meta(object):
         model = RatingAnswer
@@ -43,7 +46,7 @@ class Meta(object):
 
 class TextAnswerForm(AnswerForm):
     answer = forms.CharField(
-        widget=forms.Textarea(attrs={'class': 'form-control', 'type': 'text', "rows": "3"}))
+        widget=forms.Textarea(attrs={'class': 'form-control', 'type': 'text'}))
 
     class Meta(object):
         model = TextAnswer
@@ -67,7 +70,7 @@ class Meta(object):
         exclude = ("feedback_relation", "question", "choice")
 
 
-def create_answer_forms(fbr, post_data=None):
+def create_forms(fbr, post_data=None):
     """
     Prefix magic to identify forms from post_data.
     """
@@ -81,8 +84,7 @@ def answer_form_factory(question, feedback_relation, prefix, post_data=None):
     data = {"question": question, "feedback_relation": feedback_relation}
     instance = question.answer.model(**data)
     if question.answer.model == FieldOfStudyAnswer:
-        return FieldOfStudyAnswerForm(post_data, instance=instance,
-                                      prefix=prefix)
+        return FieldOfStudyAnswerForm(post_data, instance=instance, prefix=prefix)
 
     elif question.answer.model == RatingAnswer:
         return RatingAnswerForm(post_data, instance=instance, prefix=prefix)
diff --git a/apps/feedback/views.py b/apps/feedback/views.py
--- a/apps/feedback/views.py
+++ b/apps/feedback/views.py
@@ -19,7 +19,7 @@
     TextAnswer,
     RegisterToken
 )
-from apps.feedback.forms import create_answer_forms
+from apps.feedback.forms import create_forms
 from apps.feedback.utils import has_permission, can_delete, get_group_restricted_feedback_relations
 
 
@@ -32,10 +32,10 @@ def feedback(request, applabel, appmodel, object_id, feedback_id):
         return redirect("home")
 
     if request.method == "POST":
-        answers = create_answer_forms(feedback_relation, post_data=request.POST)
-        if all([a.is_valid() for a in answers]):
-            for a in answers:
-                a.save()
+        questions = create_forms(feedback_relation, post_data=request.POST)
+        if all([answer.is_valid() for answer in questions]):
+            for answer in questions:
+                answer.save()
 
             # mark that the user has answered
             feedback_relation.answered.add(request.user)
@@ -50,14 +50,14 @@ def feedback(request, applabel, appmodel, object_id, feedback_id):
         else:
             messages.error(request, _(u"Du må svare på alle påkrevde felt."))
     else:
-        answers = create_answer_forms(feedback_relation)
+        questions = create_forms(feedback_relation)
 
     description = feedback_relation.description
 
     return render(
         request,
         'feedback/answer.html',
-        {'answers': answers, 'description': description}
+        {'questions': questions, 'description': description}
     )
 
 


Test patch:
diff --git a/apps/feedback/tests.py b/apps/feedback/tests.py
--- a/apps/feedback/tests.py
+++ b/apps/feedback/tests.py
@@ -215,10 +215,10 @@ def test_post_incorrect(self):
         client.login(username="user1", password="Herpaderp123")
         feedback_relation = self.create_feedback_relation()
         response = client.post(feedback_relation.get_absolute_url())
-        for i in range(len(response.context['answers'])):
+        for i in range(len(response.context['questions'])):
             self.assertIn(
                 unicode(_(u'This field is required.')),
-                response.context['answers'][i].errors['answer']
+                response.context['questions'][i].errors['answer']
             )
 
     """