From 1fde8f8e278e4d4dd29a613b9dc0d31e5a33e4a9 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Fri, 28 Sep 2018 13:21:47 +0100
Subject: [PATCH] Make sure we render the category block in the event of no
 responses

---
 opentech/apply/categories/blocks.py            | 5 +++--
 opentech/apply/categories/tests/test_blocks.py | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/opentech/apply/categories/blocks.py b/opentech/apply/categories/blocks.py
index ffa193a4e..b50ebba7e 100644
--- a/opentech/apply/categories/blocks.py
+++ b/opentech/apply/categories/blocks.py
@@ -77,11 +77,12 @@ class CategoryQuestionBlock(OptionalFormFieldBlock):
     def render(self, value, context):
         data = context['data']
         category = value['category']
-        context['data'] = category.options.filter(id__in=data).values_list('value', flat=True)
+        if data != self.no_response():
+            context['data'] = category.options.filter(id__in=data).values_list('value', flat=True)
         return super().render(value, context)
 
     def get_searchable_content(self, value, data):
         return None
 
     def no_response(self):
-        return None
+        return ['No Response']
diff --git a/opentech/apply/categories/tests/test_blocks.py b/opentech/apply/categories/tests/test_blocks.py
index fa8bee4ea..979b4df24 100644
--- a/opentech/apply/categories/tests/test_blocks.py
+++ b/opentech/apply/categories/tests/test_blocks.py
@@ -52,3 +52,9 @@ class TestCategoryQuestionBlock(TestCase):
             field.choices,
             [(option.id, option.value) for option in self.category.options.all()]
         )
+
+    def test_can_render_if_no_response(self):
+        context = self.block.get_context(None, {'data': None})
+        self.assertEqual(context['data'], self.block.no_response())
+        display = self.block.render({'category': self.category}, context)
+        self.assertIn(self.block.no_response()[0], display)
-- 
GitLab