From 594014b89c5c251947741a06b2944ca6d5e70c9c Mon Sep 17 00:00:00 2001
From: Fredrik Jonsson <frjo@xdeb.org>
Date: Thu, 23 Aug 2018 10:19:53 +0200
Subject: [PATCH] Seed review forms with applications.

---
 .../management/commands/migration_base.py     |  1 +
 .../seed_community_lab_application.py         | 31 +++++++--
 .../management/commands/seed_concept_note.py  | 63 ++++++++++++++++++-
 .../management/commands/seed_fellowship.py    | 42 ++++++++++++-
 .../commands/seed_rapid_response.py           | 27 +++++++-
 5 files changed, 150 insertions(+), 14 deletions(-)

diff --git a/opentech/apply/funds/management/commands/migration_base.py b/opentech/apply/funds/management/commands/migration_base.py
index f43491dde..34335f08c 100644
--- a/opentech/apply/funds/management/commands/migration_base.py
+++ b/opentech/apply/funds/management/commands/migration_base.py
@@ -13,6 +13,7 @@ from opentech.apply.categories.models import Category, Option
 from opentech.apply.categories.categories_seed import CATEGORIES
 from opentech.apply.funds.models import ApplicationSubmission, FundType, Round, LabType
 from opentech.apply.funds.models.forms import RoundBaseForm, LabBaseForm
+from opentech.apply.review.models import ReviewForm
 from opentech.apply.funds.workflow import INITIAL_STATE
 
 
diff --git a/opentech/apply/funds/management/commands/seed_community_lab_application.py b/opentech/apply/funds/management/commands/seed_community_lab_application.py
index 497b39543..6c9832ed3 100644
--- a/opentech/apply/funds/management/commands/seed_community_lab_application.py
+++ b/opentech/apply/funds/management/commands/seed_community_lab_application.py
@@ -1,13 +1,12 @@
 import json
 
-from datetime import date
-
 from django.contrib.auth import get_user_model
 from django.core.management.base import BaseCommand
 from django.db import transaction
 
 from opentech.apply.funds.models import ApplicationForm, LabType
-from opentech.apply.funds.models.forms import LabBaseForm
+from opentech.apply.funds.models.forms import LabBaseForm, LabBaseReviewForm
+from opentech.apply.review.models import ReviewForm
 
 from opentech.apply.home.models import ApplyHomePage
 from opentech.apply.users.groups import STAFF_GROUP_NAME
@@ -19,7 +18,8 @@ class Command(BaseCommand):
     @transaction.atomic
     def handle(self, *args, **options):
         application_form = self.create_community_lab_form()
-        self.create_community_lab_fund_type(application_form)
+        application_review_form = self.create_community_lab_review_form()
+        self.create_community_lab_fund_type(application_form, application_review_form)
 
     def create_community_lab_form(self):
 
@@ -61,7 +61,26 @@ class Command(BaseCommand):
 
         return application_form
 
-    def create_community_lab_fund_type(self, application_form):
+    def create_community_lab_review_form(self):
+
+        data2 = [
+            {"type": "text_markup", "value": "<h3>Conflicts of Interest and Confidentialit</h3>", "id": "fe01dccb-87db-4dba-8cb8-f75e6f3448e6"},
+            {"type": "rich_text", "value": {"field_label": "Conflict(s) of interest disclosure", "help_text": "", "required": "", "default_value": ""}, "id": "f3c42cf1-e5ef-4674-bf6c-8e4640ee0d58"},
+            {"type": "Recommendation", "value": {"field_label": "Do you think we should support this request?", "help_text": "", "info": None}, "id": "caa6d522-4cfc-4f96-a29b-773a2de03e31"},
+            {"type": "score", "value": {"field_label": "How well do the goals and objectives fit OTF’s remit?", "help_text": "", "required": ""}, "id": "732fc004-3086-44e1-8508-e0f17c3732a8"},
+            {"type": "rich_text", "value": {"field_label": "What do you like about the proposed effort?", "help_text": "", "required": "", "default_value": ""}, "id": "f3c42cf1-e5ef-4674-bf6c-8e4640ee0d58"},
+            {"type": "rich_text", "value": {"field_label": "What do you not like about the proposed effort?", "help_text": "", "required": "", "default_value": ""}, "id": "e1e69628-c663-4cd2-a0ea-507ad01149de"},
+            {"type": "rich_text", "value": {"field_label": "What areas, if any, would you like more information?", "help_text": "", "required": "", "default_value": ""}, "id": "3033f228-58af-4944-b884-736fe6258bd6"},
+            {"type": "rich_text", "value": {"field_label": "How could they can improve collaboration or the inclusion of diverse voices?", "help_text": "", "required": "", "default_value": ""}, "id": "20ec1ed7-4e3e-433c-944a-7c20cd6245c8"},
+            {"type": "rich_text", "value": {"field_label": "Are there any individuals, communities, or networks they should reach out to?", "help_text": "", "required": "", "default_value": ""}, "id": "fd361c53-a263-4572-8403-74f6736d38fc"},
+            {"type": "Comments", "value": {"field_label": "Other comments", "help_text": "", "info": None}, "id": "d74e398e-6e64-43ae-b799-a3b79860c80e"}
+        ]
+
+        community_lab_review_form, _ = ReviewForm.objects.get_or_create(name='Community lab review', defaults={'form_fields': json.dumps(data2)})
+
+        return community_lab_review_form
+
+    def create_community_lab_fund_type(self, application_form, application_review_form):
         User = get_user_model()
 
         try:
@@ -79,6 +98,8 @@ class Command(BaseCommand):
 
             lab_form = LabBaseForm.objects.create(lab=lab, form=application_form)
             lab.forms = [lab_form]
+            lab_review_form = LabBaseReviewForm.objects.create(lab=lab, form=application_review_form)
+            lab.review_forms = [lab_review_form]
             lab.save()
 
         return lab
diff --git a/opentech/apply/funds/management/commands/seed_concept_note.py b/opentech/apply/funds/management/commands/seed_concept_note.py
index 579861405..f1abcd521 100644
--- a/opentech/apply/funds/management/commands/seed_concept_note.py
+++ b/opentech/apply/funds/management/commands/seed_concept_note.py
@@ -8,7 +8,9 @@ from django.db import transaction
 
 from opentech.apply.categories.models import Category
 from opentech.apply.funds.models import ApplicationForm, FundType, Round
-from opentech.apply.funds.models.forms import ApplicationBaseForm
+from opentech.apply.funds.models.forms import ApplicationBaseForm, ApplicationBaseReviewForm
+from opentech.apply.review.models import ReviewForm
+
 from opentech.apply.home.models import ApplyHomePage
 from opentech.apply.users.groups import STAFF_GROUP_NAME
 
@@ -28,7 +30,9 @@ class Command(BaseCommand):
 
         application_form = self.create_concept_note_form()
         proposal_form = self.create_proposal_form()
-        fund = self.create_concept_note_fund_type(application_form, proposal_form)
+        application_review_form = self.create_concept_review_form()
+        proposal_review_form = self.create_proposal_review_form()
+        fund = self.create_concept_note_fund_type(application_form, proposal_form, application_review_form, proposal_review_form)
         self.create_concept_note_round(fund)
 
     def create_concept_note_form(self):
@@ -144,7 +148,57 @@ class Command(BaseCommand):
 
         return proposal_form
 
-    def create_concept_note_fund_type(self, application_form, proposal_form):
+    def create_concept_review_form(self):
+
+        data3 = [
+            {"type": "text_markup", "value": "<h3>Conflicts of Interest and Confidentialit</h3>", "id": "4dc49d2f-a886-4244-b347-3614f8d1e399"},
+            {"type": "rich_text", "value": {"field_label": "Conflict(s) of interest disclosure", "help_text": "", "required": "", "default_value": ""}, "id": "f16be0b3-ef02-4876-b056-8a84238b1a52"},
+            {"type": "Recommendation", "value": {"field_label": "Do you think we should support this request?", "help_text": "", "info": None}, "id": "25d0d9b0-6e65-4fe3-906a-a1cd211def96"},
+            {"type": "score", "value": {"field_label": "Goals and principles", "help_text": "", "required": ""}, "id": "6dd8d5d2-09a5-4681-aebc-eb9ccd00395a"},
+            {"type": "score", "value": {"field_label": "Technical merit", "help_text": "", "required": ""}, "id": "52b1f53c-9656-4b0c-8b8b-a9c57869356d"},
+            {"type": "score", "value": {"field_label": "Reasonable and realistic", "help_text": "", "required": ""}, "id": "aedb27e7-6044-4e04-b2c7-358065c8fe5c"},
+            {"type": "rich_text", "value": {"field_label": "Request specific questions", "help_text": "", "required": "", "default_value": ""}, "id": "84405ba2-f94e-4d4d-92e1-190bd802f858"},
+            {"type": "Comments", "value": {"field_label": "Other comments", "help_text": "", "info": None}, "id": "5028cac1-752f-4d47-b83a-4f766f19fb2d"}
+        ]
+
+        concept_review_form, _ = ReviewForm.objects.get_or_create(name='Concept review', defaults={'form_fields': json.dumps(data3)})
+
+        return concept_review_form
+
+    def create_proposal_review_form(self):
+
+        data4 = [
+            {"type": "text_markup", "value": "<h3>A. Conflicts of Interest and Confidentialit</h3>", "id": "976386e1-3a66-490f-9e82-bfbe1f134cf2"},
+            {"type": "checkbox", "value": {"field_label": "I understand about confidentiality", "help_text": "", "default_value": ""}, "id": "65fb2c22-a0c5-4cde-94a7-feb27072bc3d"},
+            {"type": "dropdown", "value": {"field_label": "Do you have any conflicts of interest to report?", "help_text": "", "required": "", "choices": ["Yes", "No"]}, "id": "dd75ce49-e3c4-43da-b724-4cb8bb88dcf8"},
+            {"type": "text_markup", "value": "<h3>B. General thoughts</h3>", "id": "976386e1-3a66-490f-9e82-bfbe1f134cf2"},
+            {"type": "rich_text", "value": {"field_label": "1. Positive aspects", "help_text": "", "required": "", "default_value": ""}, "id": "e91ed603-61ad-483e-be7b-21716d05a3bd"},
+            {"type": "rich_text", "value": {"field_label": "2. Concerns", "help_text": "", "required": "", "default_value": ""}, "id": "821fb071-7db7-4cc1-ac3a-34b9eee40c94"},
+            {"type": "rich_text", "value": {"field_label": "3. Items that must be ", "help_text": "", "required": "", "default_value": ""}, "id": "021624ac-6628-430d-ba86-e68fd518c87e"},
+            {"type": "text_markup", "value": "<h3>C. Specific aspects</h3>", "id": "976386e1-3a66-490f-9e82-bfbe1f134cf2"},
+            {"type": "score", "value": {"field_label": "1. Project overview", "help_text": "", "required": ""}, "id": "9c5603d5-f897-42fa-8739-5935769c94bd"},
+            {"type": "score", "value": {"field_label": "2. Proposal objectives", "help_text": "", "required": ""}, "id": "6b748400-fad9-4b31-bb85-e3a53c99f4df"},
+            {"type": "score", "value": {"field_label": "3. Appropriate activities and strategy", "help_text": "", "required": ""}, "id": "a806a944-1d8a-4904-ace0-acfce5634a50"},
+            {"type": "score", "value": {"field_label": "4. Technical feasibility (where applicable)", "help_text": "", "required": ""}, "id": "512a86a5-ec5b-4d36-9630-90648b5b43e4"},
+            {"type": "score", "value": {"field_label": "5. Alternative analysis - red teaming", "help_text": "", "required": ""}, "id": "d9695d1d-3373-4acf-ada5-3b2593b3a634"},
+            {"type": "score", "value": {"field_label": "6. Usability", "help_text": "", "required": ""}, "id": "e43dd4dc-d2fa-493c-9f55-5a126d0e0579"},
+            {"type": "score", "value": {"field_label": "7. Sustainability", "help_text": "", "required": ""}, "id": "ee7009b8-ad18-46b5-a981-ccc52972c0a5"},
+            {"type": "score", "value": {"field_label": "8. Collaboration", "help_text": "", "required": ""}, "id": "dc5dc5e0-e4d6-462f-8296-a0e58933e701"},
+            {"type": "score", "value": {"field_label": "9. Cost realism", "help_text": "", "required": ""}, "id": "31e9b202-24b1-4993-80b7-9851624e2162"},
+            {"type": "score", "value": {"field_label": "10. Qualifications", "help_text": "", "required": ""}, "id": "d3f5479c-68da-41d9-a266-130d383bab6b"},
+            {"type": "score", "value": {"field_label": "11. Evaluation", "help_text": "", "required": ""}, "id": "2a61c71a-74f6-4963-8850-9289e852f604"},
+            {"type": "text_markup", "value": "<h3>D. Rationale and appropriateness consideration</h3>", "id": "976386e1-3a66-490f-9e82-bfbe1f134cf2"},
+            {"type": "score", "value": {"field_label": "Rationale and appropriateness ", "help_text": "", "required": ""}, "id": "0d1bf533-968c-44b9-bb30-d437ae039474"},
+            {"type": "text_markup", "value": "<h3>E. General recommendation</h3>", "id": "976386e1-3a66-490f-9e82-bfbe1f134cf2"},
+            {"type": "Recommendation", "value": {"field_label": "Recommendation", "help_text": "", "info": None}, "id": "4bf80578-1c8f-4515-9d6a-e52e87629e3e"},
+            {"type": "Comments", "value": {"field_label": "Recommendation comments", "help_text": "", "info": None}, "id": "a814d7ac-8291-4f3e-b733-4a9a4f1f8a49"}
+        ]
+
+        proposal_review_form, _ = ReviewForm.objects.get_or_create(name='Proposal review', defaults={'form_fields': json.dumps(data4)})
+
+        return proposal_review_form
+
+    def create_concept_note_fund_type(self, application_form, proposal_form, application_review_form, proposal_review_form):
         try:
             fund = FundType.objects.get(title=CN_FUND_TITLE)
         except FundType.DoesNotExist:
@@ -156,6 +210,9 @@ class Command(BaseCommand):
             fund_form = ApplicationBaseForm.objects.create(application=fund, form=application_form)
             fund_form2 = ApplicationBaseForm.objects.create(application=fund, form=proposal_form)
             fund.forms = [fund_form, fund_form2]
+            fund_review_form = ApplicationBaseReviewForm.objects.create(application=fund, form=application_review_form)
+            fund_review_form2 = ApplicationBaseReviewForm.objects.create(application=fund, form=proposal_review_form)
+            fund.review_forms = [fund_review_form, fund_review_form2]
             fund.save()
 
         return fund
diff --git a/opentech/apply/funds/management/commands/seed_fellowship.py b/opentech/apply/funds/management/commands/seed_fellowship.py
index d0a791b55..910fb405a 100644
--- a/opentech/apply/funds/management/commands/seed_fellowship.py
+++ b/opentech/apply/funds/management/commands/seed_fellowship.py
@@ -8,7 +8,8 @@ from django.db import transaction
 
 from opentech.apply.categories.models import Category
 from opentech.apply.funds.models import ApplicationForm, FundType, Round
-from opentech.apply.funds.models.forms import ApplicationBaseForm
+from opentech.apply.funds.models.forms import ApplicationBaseForm, ApplicationBaseReviewForm
+from opentech.apply.review.models import ReviewForm
 
 from opentech.apply.home.models import ApplyHomePage
 from opentech.apply.users.groups import STAFF_GROUP_NAME
@@ -29,7 +30,9 @@ class Command(BaseCommand):
 
         application_form = self.create_fellowship_application_form()
         proposal_form = self.create_fellowship_proposal_form()
-        fund = self.create_fellowship_fund_type(application_form, proposal_form)
+        application_review_form = self.create_fellowship_application_review_form()
+        proposal_review_form = self.create_fellowship_proposal_review_form()
+        fund = self.create_fellowship_fund_type(application_form, proposal_form, application_review_form, proposal_review_form)
         self.create_fellowship_round(fund)
 
     def create_fellowship_application_form(self):
@@ -107,7 +110,37 @@ class Command(BaseCommand):
 
         return proposal_form
 
-    def create_fellowship_fund_type(self, application_form, proposal_form):
+    def create_fellowship_application_review_form(self):
+
+        data3 = [
+            {"type": "Recommendation", "value": {"field_label": "Overall, do you think we should select this applicant and their project to be part of the fellowship program?", "help_text": "", "info": None}, "id": "56264b32-fa39-4c08-b41e-68e9c54b2712"},
+            {"type": "rich_text", "value": {"field_label": "If no, please select a reason why not.", "help_text": "", "required": "", "default_value": ""}, "id": "f0533950-57f5-4bb7-81ec-2d3813490c88"},
+            {"type": "rich_text", "value": {"field_label": "Request specific questions", "help_text": "", "required": "", "default_value": ""}, "id": "ba789376-e3f9-434e-8da5-330811723b30"},
+            {"type": "Comments", "value": {"field_label": "Other comments", "help_text": "", "info": None}, "id": "e74e2581-d06c-43b1-9c0b-911407225834"}
+        ]
+
+        application_review_form, _ = ReviewForm.objects.get_or_create(name='Fellowship application review', defaults={'form_fields': json.dumps(data3)})
+
+        return application_review_form
+
+    def create_fellowship_proposal_review_form(self):
+
+        data4 = [
+            {"type": "Recommendation", "value": {"field_label": "Overall, do you think we should select this applicant and their project to be part of the fellowship program?", "help_text": "", "info": None}, "id": "e1ea4f9d-64e2-4f28-a68a-851ec0f2d9ad"},
+            {"type": "rich_text", "value": {"field_label": "If no, please select a reason why not.", "help_text": "", "required": "", "default_value": ""}, "id": "e68b6fe9-8b11-4cf0-8ae4-2ffed75e1e80"},
+            {"type": "rich_text", "value": {"field_label": "If yes, but you believe some changes need to be made to the proposed effort, please let us know.", "help_text": "", "required": "", "default_value": ""}, "id": "a413f3a2-b486-4bf3-9e2d-c48d19626876"},
+            {"type": "score", "value": {"field_label": "Goals and principles", "help_text": "", "required": ""}, "id": "d40e541c-ccc0-4ede-94d1-bd8680b47004"},
+            {"type": "score", "value": {"field_label": "Technical merit", "help_text": "", "required": ""}, "id": "4af1e000-25be-4cf1-a787-8e5fd91feba8"},
+            {"type": "score", "value": {"field_label": "Reasonable and realistic", "help_text": "", "required": ""}, "id": "f839ec7e-1136-4fcd-b59e-c04e02d5abf6"},
+            {"type": "rich_text", "value": {"field_label": "Request specific questions", "help_text": "", "required": "", "default_value": ""}, "id": "536c963a-f183-45bc-b83f-458b46dc5542"},
+            {"type": "Comments", "value": {"field_label": "Anything else you'd like to give us feedback on?", "help_text": "", "info": None}, "id": "cc82ba7b-b55e-4309-85f0-f68ad6f43471"}
+        ]
+
+        proposal_review_form, _ = ReviewForm.objects.get_or_create(name='Fellowship proposal review', defaults={'form_fields': json.dumps(data4)})
+
+        return proposal_review_form
+
+    def create_fellowship_fund_type(self, application_form, proposal_form, application_review_form, proposal_review_form):
         try:
             fund = FundType.objects.get(title=FS_FUND_TITLE)
         except FundType.DoesNotExist:
@@ -119,6 +152,9 @@ class Command(BaseCommand):
             fund_form = ApplicationBaseForm.objects.create(application=fund, form=application_form)
             fund_form2 = ApplicationBaseForm.objects.create(application=fund, form=proposal_form)
             fund.forms = [fund_form, fund_form2]
+            fund_review_form = ApplicationBaseReviewForm.objects.create(application=fund, form=application_review_form)
+            fund_review_form2 = ApplicationBaseReviewForm.objects.create(application=fund, form=proposal_review_form)
+            fund.review_forms = [fund_review_form, fund_review_form2]
             fund.save()
 
         return fund
diff --git a/opentech/apply/funds/management/commands/seed_rapid_response.py b/opentech/apply/funds/management/commands/seed_rapid_response.py
index b77c6d30b..88fcd884e 100644
--- a/opentech/apply/funds/management/commands/seed_rapid_response.py
+++ b/opentech/apply/funds/management/commands/seed_rapid_response.py
@@ -8,7 +8,8 @@ from django.db import transaction
 
 from opentech.apply.categories.models import Category
 from opentech.apply.funds.models import ApplicationForm, FundType, Round
-from opentech.apply.funds.models.forms import ApplicationBaseForm
+from opentech.apply.funds.models.forms import ApplicationBaseForm, ApplicationBaseReviewForm
+from opentech.apply.review.models import ReviewForm
 
 from opentech.apply.home.models import ApplyHomePage
 from opentech.apply.users.groups import STAFF_GROUP_NAME
@@ -27,7 +28,8 @@ class Command(BaseCommand):
             return
 
         application_form = self.create_rapid_response_form()
-        fund = self.create_rapid_response_fund_type(application_form)
+        application_review_form = self.create_rapid_response_review_form()
+        fund = self.create_rapid_response_fund_type(application_form, application_review_form)
         self.create_rapid_response_round(fund)
 
     def create_rapid_response_form(self):
@@ -87,7 +89,24 @@ class Command(BaseCommand):
 
         return application_form
 
-    def create_rapid_response_fund_type(self, application_form):
+    def create_rapid_response_review_form(self):
+
+        data2 = [
+            {"type": "Recommendation", "value": {"field_label": "Do you think we should support this request?", "help_text": "", "info": None}, "id": "d350fbf9-e332-4d7f-b238-7f545cff927a"},
+            {"type": "rich_text", "value": {"field_label": "Things that you liked", "help_text": "", "required": "", "default_value": ""}, "id": "cec815a0-fab1-4142-9fc6-71319b054b2a"},
+            {"type": "rich_text", "value": {"field_label": "Things that concern you", "help_text": "", "required": "", "default_value": ""}, "id": "6915acf0-9a19-4e73-8d2b-d96e39e3b00e"},
+            {"type": "score", "value": {"field_label": "How appropriate are the proposed objectives for rapid response support?", "help_text": "", "required": ""}, "id": "71bfe95d-89c5-401b-ae7a-778e91d5c8c5"},
+            {"type": "score", "value": {"field_label": "How would you rate the applicant's capacity and knowledge to carry out this project?", "help_text": "", "required": ""}, "id": "3aa164c1-4386-4046-997a-a2778e1d894e"},
+            {"type": "score", "value": {"field_label": "Does the applicant provide sufficient justification for the amount of funding requested (is this cost effective)?", "help_text": "", "required": ""}, "id": "7cc12bb6-4c12-48aa-a269-1fd6d725abfe"},
+            {"type": "rich_text", "value": {"field_label": "Justification comments", "help_text": "", "required": "", "default_value": ""}, "id": "abc61bba-2a9e-4a9e-8c06-a1824ea2a998"},
+            {"type": "Comments", "value": {"field_label": "Other comments", "help_text": "", "info": None}, "id": "d94e51d3-026c-443f-a98a-a66b1f6c968c"}
+        ]
+
+        rapid_response_review_form, _ = ReviewForm.objects.get_or_create(name='Rapid response review', defaults={'form_fields': json.dumps(data2)})
+
+        return rapid_response_review_form
+
+    def create_rapid_response_fund_type(self, application_form, application_review_form):
         try:
             fund = FundType.objects.get(title='Rapid Response')
         except FundType.DoesNotExist:
@@ -98,6 +117,8 @@ class Command(BaseCommand):
 
             fund_form = ApplicationBaseForm.objects.create(application=fund, form=application_form)
             fund.forms = [fund_form]
+            fund_review_form = ApplicationBaseReviewForm.objects.create(application=fund, form=application_review_form)
+            fund.review_forms = [fund_review_form]
             fund.save()
 
         return fund
-- 
GitLab