From 8ebebeec2e3ca531b98a2fcf32d72e65dff26d28 Mon Sep 17 00:00:00 2001
From: Parbhat Puri <parbhatpuri17@gmail.com>
Date: Wed, 27 Mar 2019 08:57:33 +0000
Subject: [PATCH] Display first group answers in Open call index page for a
 submission

---
 opentech/apply/funds/models/mixins.py         | 27 ++++++++++++++++++-
 .../public_funds/open_call_index_page.html    | 13 +++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/opentech/apply/funds/models/mixins.py b/opentech/apply/funds/models/mixins.py
index 00f253ddf..6698ee2bc 100644
--- a/opentech/apply/funds/models/mixins.py
+++ b/opentech/apply/funds/models/mixins.py
@@ -4,7 +4,7 @@ from django.core.files import File
 from django.core.files.storage import get_storage_class
 
 from opentech.apply.stream_forms.blocks import (
-    FileFieldBlock, FormFieldBlock, ImageFieldBlock, MultiFileFieldBlock
+    FileFieldBlock, FormFieldBlock, GroupToggleBlock, ImageFieldBlock, MultiFileFieldBlock
 )
 from opentech.apply.utils.blocks import SingleIncludeMixin
 
@@ -124,6 +124,14 @@ class AccessFormData:
             elif isinstance(field.block, FormFieldBlock):
                 yield field_id
 
+    @property
+    def first_group_question_field_ids(self):
+        for field_id, field in self.fields.items():
+            if isinstance(field.block, GroupToggleBlock):
+                break
+            elif isinstance(field.block, FormFieldBlock):
+                yield field_id
+
     @property
     def raw_fields(self):
         # Field ids to field class mapping - similar to raw_data
@@ -157,6 +165,14 @@ class AccessFormData:
             if field_id not in self.named_blocks
         ]
 
+    @property
+    def first_group_normal_blocks(self):
+        return [
+            field_id
+            for field_id in self.first_group_question_field_ids
+            if field_id not in self.named_blocks
+        ]
+
     def serialize(self, field_id):
         field = self.field(field_id)
         data = self.data(field_id)
@@ -180,6 +196,12 @@ class AccessFormData:
             for field_id in self.normal_blocks
         ]
 
+    def render_first_group_answers(self):
+        return [
+            self.render_answer(field_id, include_question=True)
+            for field_id in self.first_group_normal_blocks
+        ]
+
     def render_text_blocks_answers(self):
         # Returns a list of the rendered answers of type text
         return [
@@ -191,3 +213,6 @@ class AccessFormData:
     def output_answers(self):
         # Returns a safe string of the rendered answers
         return mark_safe(''.join(self.render_answers()))
+
+    def output_first_group_answers(self):
+        return mark_safe(''.join(self.render_first_group_answers()))
diff --git a/opentech/public/funds/templates/public_funds/open_call_index_page.html b/opentech/public/funds/templates/public_funds/open_call_index_page.html
index 16cd611da..ac98b04e4 100644
--- a/opentech/public/funds/templates/public_funds/open_call_index_page.html
+++ b/opentech/public/funds/templates/public_funds/open_call_index_page.html
@@ -15,6 +15,19 @@
                     <h4 class="listing__title">{{ submission.title }}</h4>
                     <a class="listing__button" href="{% pageurl submission.page %}">Build it</a>
                 </div>
+                <div>
+                    <div>
+                        <h5>Project Duration</h5>
+                        {{ submission.get_duration_display }}
+                    </div>
+                    <div>
+                        <h5>Name</h5>
+                        {{ submission.get_full_name_display }}
+                    </div>
+                    <div class="rich-text rich-text--answers">
+                        {{ submission.output_first_group_answers }}
+                    </div>
+                </div>
 
             {% endfor %}
 
-- 
GitLab