From 6d9e7ea588b103c9791c4350351c8fc05246574a Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Tue, 9 Jan 2018 14:48:43 +0000
Subject: [PATCH] Add the reviewers and project listing to the fund

---
 .../people/includes/person_listing.html       |  7 ++++++
 .../templates/people/person_index_page.html   |  8 +------
 opentech/publicpages/blocks.py                | 22 +++++++++++++++++++
 .../publicpages/migrations/0001_initial.py    |  3 ++-
 opentech/publicpages/models.py                |  5 +++--
 .../publicpages/blocks/related_projects.html  |  3 +++
 .../publicpages/blocks/related_reviewers.html |  3 +++
 .../publicpages/includes/project_listing.html |  1 +
 opentech/templates/blocks/stream_block.html   |  3 ++-
 9 files changed, 44 insertions(+), 11 deletions(-)
 create mode 100644 opentech/people/templates/people/includes/person_listing.html
 create mode 100644 opentech/publicpages/blocks.py
 create mode 100644 opentech/publicpages/templates/publicpages/blocks/related_projects.html
 create mode 100644 opentech/publicpages/templates/publicpages/blocks/related_reviewers.html
 create mode 100644 opentech/publicpages/templates/publicpages/includes/project_listing.html

diff --git a/opentech/people/templates/people/includes/person_listing.html b/opentech/people/templates/people/includes/person_listing.html
new file mode 100644
index 000000000..9ec5a19cb
--- /dev/null
+++ b/opentech/people/templates/people/includes/person_listing.html
@@ -0,0 +1,7 @@
+<article class="person">
+    <h2><a href="{% pageurl person %}">{{ person.first_name }} {{ person.last_name }}</a></h2>
+
+    {% if person.listing_summary or person.introduction %}
+        <p>{{ person.listing_summary|default:person.introduction }}</p>
+    {% endif %}
+</article>
diff --git a/opentech/public/people/templates/people/person_index_page.html b/opentech/public/people/templates/people/person_index_page.html
index 873be5204..7d5f4d3a2 100644
--- a/opentech/public/people/templates/people/person_index_page.html
+++ b/opentech/public/people/templates/people/person_index_page.html
@@ -13,13 +13,7 @@
         <div class="container">
             {% if people.paginator.count %}
                 {% for person in people %}
-                    <article class="person">
-                        <h2><a href="{% pageurl person %}">{{ person.first_name }} {{ person.last_name }}</a></h2>
-
-                        {% if person.listing_summary or person.introduction %}
-                            <p>{{ person.listing_summary|default:person.introduction }}</p>
-                        {% endif %}
-                    </article>
+                    {% include "people/includes/person_listing.html" with person=person %}
                 {% endfor %}
 
                 {% include "includes/pagination.html" with paginator_page=people %}
diff --git a/opentech/publicpages/blocks.py b/opentech/publicpages/blocks.py
new file mode 100644
index 000000000..556a0090c
--- /dev/null
+++ b/opentech/publicpages/blocks.py
@@ -0,0 +1,22 @@
+from wagtail.wagtailcore.blocks import StaticBlock
+
+from opentech.utils.blocks import StoryBlock
+
+
+class ProjectsBlock(StaticBlock):
+    class Meta:
+        icon = 'grip'
+        label = 'List of Projects funded'
+        template = 'publicpages/blocks/related_projects.html'
+
+
+class ReviewersBlock(StaticBlock):
+    class Meta:
+        icon = 'grip'
+        label = 'List of fund Reviewers'
+        template = 'publicpages/blocks/related_reviewers.html'
+
+
+class FundBlock(StoryBlock):
+    project_list = ProjectsBlock()
+    reviewer_list = ReviewersBlock()
diff --git a/opentech/publicpages/migrations/0001_initial.py b/opentech/publicpages/migrations/0001_initial.py
index de11954b9..b63054064 100644
--- a/opentech/publicpages/migrations/0001_initial.py
+++ b/opentech/publicpages/migrations/0001_initial.py
@@ -11,6 +11,7 @@ import wagtail.wagtailembeds.blocks
 import wagtail.wagtailimages.blocks
 import wagtail.wagtailsnippets.blocks
 
+import opentech
 
 class Migration(migrations.Migration):
 
@@ -46,7 +47,7 @@ class Migration(migrations.Migration):
                 ('listing_title', models.CharField(blank=True, help_text='Override the page title used when this page appears in listings', max_length=255)),
                 ('listing_summary', models.CharField(blank=True, help_text="The text summary used when this page appears in listings. It's also used as the description for search engines if the 'Search description' field above is not defined.", max_length=255)),
                 ('introduction', models.TextField(blank=True)),
-                ('body', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title', icon='title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailcore.blocks.StructBlock((('image', wagtail.wagtailimages.blocks.ImageChooserBlock()), ('caption', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('quote', wagtail.wagtailcore.blocks.StructBlock((('quote', wagtail.wagtailcore.blocks.CharBlock(classname='title')), ('attribution', wagtail.wagtailcore.blocks.CharBlock(required=False)), ('job_title', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('embed', wagtail.wagtailembeds.blocks.EmbedBlock()), ('call_to_action', wagtail.wagtailsnippets.blocks.SnippetChooserBlock('utils.CallToActionSnippet', template='blocks/call_to_action_block.html')), ('document', wagtail.wagtailcore.blocks.StructBlock((('document', wagtail.wagtaildocs.blocks.DocumentChooserBlock()), ('title', wagtail.wagtailcore.blocks.CharBlock(required=False)))))))),
+                ('body', wagtail.wagtailcore.fields.StreamField((('heading', wagtail.wagtailcore.blocks.CharBlock(classname='full title', icon='title')), ('paragraph', wagtail.wagtailcore.blocks.RichTextBlock()), ('image', wagtail.wagtailcore.blocks.StructBlock((('image', wagtail.wagtailimages.blocks.ImageChooserBlock()), ('caption', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('quote', wagtail.wagtailcore.blocks.StructBlock((('quote', wagtail.wagtailcore.blocks.CharBlock(classname='title')), ('attribution', wagtail.wagtailcore.blocks.CharBlock(required=False)), ('job_title', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('embed', wagtail.wagtailembeds.blocks.EmbedBlock()), ('call_to_action', wagtail.wagtailsnippets.blocks.SnippetChooserBlock('utils.CallToActionSnippet', template='blocks/call_to_action_block.html')), ('document', wagtail.wagtailcore.blocks.StructBlock((('document', wagtail.wagtaildocs.blocks.DocumentChooserBlock()), ('title', wagtail.wagtailcore.blocks.CharBlock(required=False))))), ('project_list', opentech.publicpages.blocks.ProjectsBlock()), ('reviewer_list', opentech.publicpages.blocks.ReviewersBlock())))),
                 ('fund_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.Page')),
                 ('header_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage')),
                 ('listing_image', models.ForeignKey(blank=True, help_text='Choose the image you wish to be displayed when this page appears in listings', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage')),
diff --git a/opentech/publicpages/models.py b/opentech/publicpages/models.py
index 65aaab64e..0702a6af4 100644
--- a/opentech/publicpages/models.py
+++ b/opentech/publicpages/models.py
@@ -10,9 +10,10 @@ from wagtail.wagtailadmin.edit_handlers import (
 )
 from wagtail.wagtailcore.fields import StreamField
 
-from opentech.utils.blocks import StoryBlock
 from opentech.utils.models import BasePage
 
+from .blocks import FundBlock
+
 
 class FundPage(BasePage):
     subpage_types = []
@@ -26,7 +27,7 @@ class FundPage(BasePage):
         on_delete=models.SET_NULL,
         related_name='+',
     )
-    body = StreamField(StoryBlock())
+    body = StreamField(FundBlock())
 
     content_panels = BasePage.content_panels + [
         FieldPanel('introduction'),
diff --git a/opentech/publicpages/templates/publicpages/blocks/related_projects.html b/opentech/publicpages/templates/publicpages/blocks/related_projects.html
new file mode 100644
index 000000000..692e68dbb
--- /dev/null
+++ b/opentech/publicpages/templates/publicpages/blocks/related_projects.html
@@ -0,0 +1,3 @@
+{% for project in page.projects %}
+    {% include "publicpages/includes/project_listing.html" with project=project %}
+{% endfor %}
diff --git a/opentech/publicpages/templates/publicpages/blocks/related_reviewers.html b/opentech/publicpages/templates/publicpages/blocks/related_reviewers.html
new file mode 100644
index 000000000..fbb24ea53
--- /dev/null
+++ b/opentech/publicpages/templates/publicpages/blocks/related_reviewers.html
@@ -0,0 +1,3 @@
+{% for person in page.reviewers %}
+    {% include "person/includes/person_listing.html" with person=person %}
+{% endfor %}
diff --git a/opentech/publicpages/templates/publicpages/includes/project_listing.html b/opentech/publicpages/templates/publicpages/includes/project_listing.html
new file mode 100644
index 000000000..0ff5422e2
--- /dev/null
+++ b/opentech/publicpages/templates/publicpages/includes/project_listing.html
@@ -0,0 +1 @@
+<p>A PROJECT</p>
diff --git a/opentech/templates/blocks/stream_block.html b/opentech/templates/blocks/stream_block.html
index aa12d231f..2341b0510 100644
--- a/opentech/templates/blocks/stream_block.html
+++ b/opentech/templates/blocks/stream_block.html
@@ -1,7 +1,8 @@
+{% load wagtailcore_tags %}
 {% for block in value %}
     {% if block.block_type == 'heading' %}
         <h2>{{ block.value }}</h2>
     {% else %}
-        {{ block }}
+        {% include_block block %}
     {% endif %}
 {% endfor %}
-- 
GitLab