From 2d3fc7eb73502f9cfe3711b660b375ccd7e6c02f Mon Sep 17 00:00:00 2001
From: Fredrik Jonsson <frjo@xdeb.org>
Date: Wed, 29 Aug 2018 12:01:24 +0200
Subject: [PATCH] Migrating request custom question in submissions.

---
 .../migrate_fellowship_application.py         | 28 ++++++++++++++++-
 .../commands/migrate_fellowship_proposals.py  | 20 +++++++++++-
 .../commands/migrate_rr_applications.py       | 31 +++++++++++++++++++
 .../management/commands/migration_base.py     |  9 ++++++
 .../commands/seed_rapid_response.py           |  1 +
 5 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/opentech/apply/funds/management/commands/migrate_fellowship_application.py b/opentech/apply/funds/management/commands/migrate_fellowship_application.py
index 5e33d7fd0..e27b09468 100644
--- a/opentech/apply/funds/management/commands/migrate_fellowship_application.py
+++ b/opentech/apply/funds/management/commands/migrate_fellowship_application.py
@@ -71,7 +71,7 @@ class Command(MigrateCommand):
         },
         "field_application_questions": {
             "id": "57cc52e2-b3ff-4e9f-a5fe-42e7735e16c2",
-            "type": "value",
+            "type": "merge_value",
             "key": "safe_value",
         },
         "field_application_status": {
@@ -142,3 +142,29 @@ class Command(MigrateCommand):
             "type": "boolean",
         },
     }
+
+    REQUEST_QUESTION_MAP = {
+        "3618": {
+            0: "What will be the outcome(s) of your research?",
+            1: "How will the results of your research be accessible to a non-technical audience?",
+            2: "How will your work build on the existing research in your area of focus?",
+            3: "Why is the organization chosen well suited to host your project?",
+            4: "Please include a resume or CV (Feel free to attach a file at the bottom of the application)",
+        },
+        "3667": {
+            0: "Does your fellowship project address an urgent and time-bound digital emergency? If so, how? ",
+            1: "What steps will you take post-emergency to prevent a similar problem from occurring again in the future? ",
+        },
+        "3681": {
+            0: "How does your fellowship project idea address the digital security threats the host organization(s) face?",
+            1: "What are the anticipated results from your fellowship project?",
+            2: "How will the results of your fellowship project be accessible to internet freedom technology developer community?",
+            3: "Why is the organization(s) chosen well suited for your idea under the DIFP remit?",
+            4: "Please include a resume or CV (Feel free to attach a file at the bottom of the application)",
+        },
+        "3861": {
+            0: "Where are you located or would you like to be located during this fellowship?",
+            1: "When would you ideally start and why?",
+            2: "Please list any links to your portfolio or prior work",
+        },
+    }
diff --git a/opentech/apply/funds/management/commands/migrate_fellowship_proposals.py b/opentech/apply/funds/management/commands/migrate_fellowship_proposals.py
index e9b319872..ba18e14b1 100644
--- a/opentech/apply/funds/management/commands/migrate_fellowship_proposals.py
+++ b/opentech/apply/funds/management/commands/migrate_fellowship_proposals.py
@@ -51,7 +51,7 @@ class Command(MigrateCommand):
         },
         "field_proposal_request_questions": {
             "id": "b6d71932-98c2-4ce8-a5e6-454a1f800d21",
-            "type": "value",
+            "type": "merge_value",
             "key": "safe_value",
         },
         "field_proposal_upload": {
@@ -60,3 +60,21 @@ class Command(MigrateCommand):
             # TODO: finish mapping
         },
     }
+
+    REQUEST_QUESTION_MAP = {
+        "3618": {
+            0: "How will this project leverage the resources made available by the host organization?",
+            1: "Please detail the specific steps the applicant will take to ensure the project outcomes reach non-technical audiences",
+            2: "In what ways will this effort advance understanding in the relevant field?",
+            3: "What risks or variables could jeopardize either the outcomes of the project or the safety of the applicant?",
+            4: "How is the applicant well equipped to carry out the technical work proposed? (if applicable)",
+        },
+        "3681": {
+            0: "Please detail the specific steps the applicant will take to ensure the project outcomes reach the internet freedom technology community.",
+            1: "What risks could jeopardize the fellowship project?",
+            2: "How would those risks be mitigated or addressed?",
+            3: "How will your work be sustained following the completion of your fellowship?",
+            4: "If your project includes public gatherings, do you have a code of conduct? If yes, please list below or provide links to where it can be publicly accessed.",
+            5: "Please include letters of support for the organization or organizations you would be working with (Please attach a file at the bottom of the application)",
+        },
+    }
diff --git a/opentech/apply/funds/management/commands/migrate_rr_applications.py b/opentech/apply/funds/management/commands/migrate_rr_applications.py
index 61014b37b..157822fce 100644
--- a/opentech/apply/funds/management/commands/migrate_rr_applications.py
+++ b/opentech/apply/funds/management/commands/migrate_rr_applications.py
@@ -162,6 +162,11 @@ class Command(MigrateCommand):
                 "premise": "premise",
             }
         },
+        "field_application_questions": {
+            "id": "1889de86-0a0d-4abf-9916-4db87a499d35",
+            "type": "merge_value",
+            "key": "safe_value",
+        },
         "field_application_otf_mission": {
             "id": "e695f0d7-4c74-4cc6-853f-bd62ecd19d3d",
             "type": "boolean",
@@ -200,3 +205,29 @@ class Command(MigrateCommand):
             # TODO: finish mapping
         },
     }
+
+    REQUEST_QUESTION_MAP = {
+        "3618": {
+            "0": "What will be the outcome(s) of your research?",
+            "1": "How will the results of your research be accessible to a non-technical audience?",
+            "2": "How will your work build on the existing research in your area of focus?",
+            "3": "Why is the organization chosen well suited to host your project?",
+            "4": "Please include a resume or CV (Feel free to attach a file at the bottom of the application)",
+        },
+        "3667": {
+            "0": "Does your fellowship project address an urgent and time-bound digital emergency? If so, how? ",
+            "1": "What steps will you take post-emergency to prevent a similar problem from occurring again in the future? ",
+        },
+        "3681": {
+            "0": "How does your fellowship project idea address the digital security threats the host organization(s) face?",
+            "1": "What are the anticipated results from your fellowship project?",
+            "2": "How will the results of your fellowship project be accessible to internet freedom technology developer community?",
+            "3": "Why is the organization(s) chosen well suited for your idea under the DIFP remit?",
+            "4": "Please include a resume or CV (Feel free to attach a file at the bottom of the application)",
+        },
+        "3861": {
+            "0": "Where are you located or would you like to be located during this fellowship?",
+            "1": "When would you ideally start and why?",
+            "2": "Please list any links to your portfolio or prior work",
+        },
+    }
diff --git a/opentech/apply/funds/management/commands/migration_base.py b/opentech/apply/funds/management/commands/migration_base.py
index 4b4468480..ba0708c6b 100644
--- a/opentech/apply/funds/management/commands/migration_base.py
+++ b/opentech/apply/funds/management/commands/migration_base.py
@@ -141,6 +141,15 @@ class MigrateCommand(BaseCommand):
                 value = self.nl2br(source_value[key]) if source_value else ''
             else:
                 value = self.nl2br(source_value['value']) if source_value else ''
+        elif mapping_type == 'merge_value':
+            values = []
+            i = 0
+            for item in source_value:
+                question = self.REQUEST_QUESTION_MAP[node['field_application_request']['target_id']]
+                values.append(f"<strong>{question[i]}</strong>{item[key]}<br>\n")
+                i += 1
+            merged_values = ''.join(values)
+            value = self.nl2br(merged_values) if source_value else ''
         elif mapping_type == 'map' and 'map' in 'mapping':
             value = mapping['map'].get(source_value[key])
         elif mapping_type == 'address' and 'map' in mapping:
diff --git a/opentech/apply/funds/management/commands/seed_rapid_response.py b/opentech/apply/funds/management/commands/seed_rapid_response.py
index 9ecb0d392..826240707 100644
--- a/opentech/apply/funds/management/commands/seed_rapid_response.py
+++ b/opentech/apply/funds/management/commands/seed_rapid_response.py
@@ -70,6 +70,7 @@ class Command(BaseCommand):
             {"type": "char", "value": {"field_label": "Primary point of contact", "help_text": "", "required": "", "format": "", "default_value": ""}, "id": "13bb0d64-65f3-4340-8e7e-e5da80d706d5"},
             {"type": "char", "value": {"field_label": "Phone", "help_text": "", "required": "", "format": "", "default_value": ""}, "id": "2cb9fe4b-df45-4181-80e5-14382f853081"},
             {"type": "address", "value": {"field_label": "Address", "help_text": "", "info": None}, "id": "bd29eb88-9754-4305-9b2d-406a875ec56a"},
+            {"type": "rich_text", "value": {"field_label": "Request specific questions", "help_text": "", "required": "", "default_value": ""}, "id": "1889de86-0a0d-4abf-9916-4db87a499d35"},
             {"type": "multi_file", "value": {"field_label": "Upload", "help_text": "", "required": ""}, "id": "607daeba-1f33-4ad0-b135-eda743ba8e3a"},
             {"type": "text_markup", "value": "<h3>I acknowledge</h3>", "id": "5688ddc7-0397-41e7-9e6b-2c0fe44f42aa"},
             {"type": "checkbox", "value": {"field_label": "My application will be dismissed if it does not fit within OTF\'s mission, values, principles statements.", "help_text": "", "required": "true", "default_value": ""}, "id": "e695f0d7-4c74-4cc6-853f-bd62ecd19d3d"},
-- 
GitLab