Repository: Pierre-Sassoulas/django-survey (language: python)

Issue:
String 'None' is displayed if category description is empty
Value `category.description` is not checked against `None` in the template https://github.com/Pierre-Sassoulas/django-survey/blob/09a7c271c823dea598d177c2c4c4db03b7abc5f0/survey/templates/survey/survey.html#L36
It would be nicer to have something like `{{category.description|default_if_none:""}}` there

(I would make a PR request, but I cannot test is easily)
String 'None' is displayed if category description is empty
Value `category.description` is not checked against `None` in the template https://github.com/Pierre-Sassoulas/django-survey/blob/09a7c271c823dea598d177c2c4c4db03b7abc5f0/survey/templates/survey/survey.html#L36
It would be nicer to have something like `{{category.description|default_if_none:""}}` there

(I would make a PR request, but I cannot test is easily)


Discussion / hints:
There's fixtures in the existing tests, you can add a null description and load the fixtures to check manually.
There's fixtures in the existing tests, you can add a null description and load the fixtures to check manually.

Fix patch:
diff --git a/survey/templates/survey/survey.html b/survey/templates/survey/survey.html
index 4e72e1e7..614607dd 100644
--- a/survey/templates/survey/survey.html
+++ b/survey/templates/survey/survey.html
@@ -33,7 +33,7 @@ <h1> {{survey.name}} </h1>
 	    {% csrf_token %}
         {% for category in categories %}
             <h3> {{category}} </h3>
-            <p> {{category.description}} </p>
+            <p> {{category.description|default_if_none:""}} </p>
 			<div class="panel-group" id="accordion">
 				<div class="panel panel-default">
 				    <div class="panel-heading">


Test patch:
diff --git a/survey/tests/testdump.json b/survey/tests/testdump.json
index 2232ca44..5e95be6d 100644
--- a/survey/tests/testdump.json
+++ b/survey/tests/testdump.json
@@ -222,6 +222,22 @@
    "redirect_url": "https://www.google.com"
   }
 },
+{
+ "model": "survey.survey",
+ "pk": 13,
+ "fields": {
+  "name": "Category without description",
+  "description": "Test survey with category without description",
+  "is_published": true,
+  "need_logged_user": false,
+  "editable_answers": true,
+  "display_method": 0,
+  "template": null,
+  "publish_date": "2022-10-29",
+  "expire_date": "2050-03-15",
+  "redirect_url": ""
+ }
+},
 {
  "model": "survey.category",
  "pk": 1,
@@ -272,6 +288,26 @@
   "description": "A second multipage category"
  }
 },
+{
+ "model": "survey.category",
+ "pk": 6,
+ "fields": {
+  "name": "Category with description",
+  "survey": 13,
+  "order": 1,
+  "description": "Description of category"
+ }
+},
+{
+ "model": "survey.category",
+ "pk": 7,
+ "fields": {
+  "name": "Category without description",
+  "survey": 13,
+  "order": 2,
+  "description": null
+ }
+},
 {
  "model": "survey.question",
  "pk": 1,
@@ -478,7 +514,46 @@
   "survey": 12,
   "type": "text",
   "choices": ""
-}
+ }
+},
+{
+ "model": "survey.question",
+ "pk": 17,
+ "fields": {
+  "text": "Question for category with description",
+  "order": 1,
+  "required": false,
+  "category": 6,
+  "survey": 13,
+  "type": "text",
+  "choices": ""
+ }
+},
+{
+ "model": "survey.question",
+ "pk": 18,
+ "fields": {
+  "text": "Question for category without description",
+  "order": 2,
+  "required": false,
+  "category": 7,
+  "survey": 13,
+  "type": "text",
+  "choices": ""
+ }
+},
+{
+ "model": "survey.question",
+ "pk": 19,
+ "fields": {
+  "text": "Question without category",
+  "order": 3,
+  "required": false,
+  "category": null,
+  "survey": 13,
+  "type": "text",
+  "choices": ""
+ }
 },
 {
  "model": "survey.response",
diff --git a/survey/tests/views/test_survey_category.py b/survey/tests/views/test_survey_category.py
new file mode 100644
index 00000000..a6bc7aa4
--- /dev/null
+++ b/survey/tests/views/test_survey_category.py
@@ -0,0 +1,16 @@
+import logging
+
+from django.urls.base import reverse
+
+from survey.tests import BaseTest
+
+LOGGER = logging.getLogger(__name__)
+
+
+class TestSurveyCategory(BaseTest):
+    def test_category_description_none_not_shown(self):
+        """
+        Checks that blank category description is not shown (no 'None').
+        """
+        response = self.client.get(reverse("survey-detail", args=(13,)))
+        self.assertNotContains(response, "None")