Skip to content

Commit f1eca4b

Browse files
authored
Fix None displayed when category description was empty (Pierre-Sassoulas#177)
1 parent 09a7c27 commit f1eca4b

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

survey/templates/survey/survey.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h1> {{survey.name}} </h1>
3333
{% csrf_token %}
3434
{% for category in categories %}
3535
<h3> {{category}} </h3>
36-
<p> {{category.description}} </p>
36+
<p> {{category.description|default_if_none:""}} </p>
3737
<div class="panel-group" id="accordion">
3838
<div class="panel panel-default">
3939
<div class="panel-heading">

survey/tests/testdump.json

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@
222222
"redirect_url": "https://www.google.com"
223223
}
224224
},
225+
{
226+
"model": "survey.survey",
227+
"pk": 13,
228+
"fields": {
229+
"name": "Category without description",
230+
"description": "Test survey with category without description",
231+
"is_published": true,
232+
"need_logged_user": false,
233+
"editable_answers": true,
234+
"display_method": 0,
235+
"template": null,
236+
"publish_date": "2022-10-29",
237+
"expire_date": "2050-03-15",
238+
"redirect_url": ""
239+
}
240+
},
225241
{
226242
"model": "survey.category",
227243
"pk": 1,
@@ -272,6 +288,26 @@
272288
"description": "A second multipage category"
273289
}
274290
},
291+
{
292+
"model": "survey.category",
293+
"pk": 6,
294+
"fields": {
295+
"name": "Category with description",
296+
"survey": 13,
297+
"order": 1,
298+
"description": "Description of category"
299+
}
300+
},
301+
{
302+
"model": "survey.category",
303+
"pk": 7,
304+
"fields": {
305+
"name": "Category without description",
306+
"survey": 13,
307+
"order": 2,
308+
"description": null
309+
}
310+
},
275311
{
276312
"model": "survey.question",
277313
"pk": 1,
@@ -478,7 +514,46 @@
478514
"survey": 12,
479515
"type": "text",
480516
"choices": ""
481-
}
517+
}
518+
},
519+
{
520+
"model": "survey.question",
521+
"pk": 17,
522+
"fields": {
523+
"text": "Question for category with description",
524+
"order": 1,
525+
"required": false,
526+
"category": 6,
527+
"survey": 13,
528+
"type": "text",
529+
"choices": ""
530+
}
531+
},
532+
{
533+
"model": "survey.question",
534+
"pk": 18,
535+
"fields": {
536+
"text": "Question for category without description",
537+
"order": 2,
538+
"required": false,
539+
"category": 7,
540+
"survey": 13,
541+
"type": "text",
542+
"choices": ""
543+
}
544+
},
545+
{
546+
"model": "survey.question",
547+
"pk": 19,
548+
"fields": {
549+
"text": "Question without category",
550+
"order": 3,
551+
"required": false,
552+
"category": null,
553+
"survey": 13,
554+
"type": "text",
555+
"choices": ""
556+
}
482557
},
483558
{
484559
"model": "survey.response",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import logging
2+
3+
from django.urls.base import reverse
4+
5+
from survey.tests import BaseTest
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
class TestSurveyCategory(BaseTest):
11+
def test_category_description_none_not_shown(self):
12+
"""
13+
Checks that blank category description is not shown (no 'None').
14+
"""
15+
response = self.client.get(reverse("survey-detail", args=(13,)))
16+
self.assertNotContains(response, "None")

0 commit comments

Comments
 (0)