Skip to content

Commit

Permalink
Fix question without category is duplicated (#178)
Browse files Browse the repository at this point in the history
The code is taken from #168, the test is based
on fixture from #177.
  • Loading branch information
maximloginov authored Oct 30, 2022
1 parent 5099715 commit 781a924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion survey/templates/survey/question.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</thead> -->
<tbody>
{% for form in response_form %}
{% if form.field.widget.attrs.category == category.name or not form.field.widget.attrs.category %}
{% if form.field.widget.attrs.category == category.name or category.name == 'No category' and not form.field.widget.attrs.category %}
<tr class="{% if form.errors%} danger {% endif %}">
<td>
{{ form.label|safe }}
Expand Down
9 changes: 9 additions & 0 deletions survey/tests/views/test_survey_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ def test_category_description_none_not_shown(self):
"""
response = self.client.get(reverse("survey-detail", args=(13,)))
self.assertNotContains(response, "None")

def test_without_category_not_duplicated(self):
"""
Checks that question without category is not duplicated when there is
a question with category in the same survey.
"""
response = self.client.get(reverse("survey-detail", args=(13,)))
self.assertContains(response, "Question without category", count=1)

0 comments on commit 781a924

Please sign in to comment.