From 7b71d7f67f62804b5f0be69287d3fde1d3792c30 Mon Sep 17 00:00:00 2001
From: Fredrik Jonsson <frjo@xdeb.org>
Date: Thu, 30 Aug 2018 10:22:22 +0200
Subject: [PATCH] Correcting spelling of @example.com.

---
 .../migrate_concept_determinations.py         | 43 +++++++++++--------
 .../migrate_proposal_determinations.py        |  5 ++-
 .../management/commands/migration_base.py     |  2 +-
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/opentech/apply/determinations/management/commands/migrate_concept_determinations.py b/opentech/apply/determinations/management/commands/migrate_concept_determinations.py
index 30f2ae236..14e4f5dcf 100644
--- a/opentech/apply/determinations/management/commands/migrate_concept_determinations.py
+++ b/opentech/apply/determinations/management/commands/migrate_concept_determinations.py
@@ -54,6 +54,19 @@ class Command(BaseCommand):
         node = self.data[id]
         form_data = {}
 
+        try:
+            determination = Determination.objects.get(drupal_id=node['nid'])
+        except Determination.DoesNotExist:
+            determination = Determination(drupal_id=node['nid'])
+
+        # TODO timezone?
+        determination.created_at = datetime.fromtimestamp(int(node['created']), timezone.utc)
+        determination.updated_at = datetime.fromtimestamp(int(node['changed']), timezone.utc)
+        determination.author = self.get_user(node['uid'])
+        determination.submission = self.get_submission(node)
+        determination.outcome = self.get_determination(node)
+        determination.message = self.get_field_value('field_cnsr_determination_message', node)
+
         for field in node:
             if field in self.STREAMFIELD_MAP:
                 try:
@@ -63,24 +76,17 @@ class Command(BaseCommand):
                 except TypeError:
                     pass
 
+        determination.data = form_data
+
+        import pprint
+        pprint.pprint(f"{node['nid']}: {determination}")
+        pprint.pprint(determination.data)
+
         try:
-            determination = Determination.objects.create(
-                created_at=datetime.fromtimestamp(int(node['created']), timezone.utc),
-                updated_at=datetime.fromtimestamp(int(node['changed']), timezone.utc),
-                author=self.get_user(node['uid']),
-                submission=self.get_submission(node['field_submission_proposal']['target_id']),
-                outcome=self.get_determination(node),
-                message=self.get_field_value('field_cnsr_determination_message', node),
-                data=form_data,
-            )
-            try:
-                determination.save()
-                self.stdout.write(f"Processed \"{node['title']}\" ({node['nid']})")
-            except IntegrityError:
-                self.stdout.write(f"Skipped \"{node['title']}\" ({node['nid']}) due to IntegrityError")
-                pass
-        except ValueError:
-            self.stdout.write(f"Skipped \"{node['title']}\" ({node['nid']}) due to ValueError")
+            determination.save()
+            self.stdout.write(f"Processed \"{node['title']}\" ({node['nid']})")
+        except IntegrityError:
+            self.stdout.write(f"Skipped \"{node['title']}\" ({node['nid']}) due to IntegrityError")
             pass
 
     def get_field_value(self, field, node):
@@ -144,8 +150,9 @@ class Command(BaseCommand):
         except User.DoesNotExist:
             return None
 
-    def get_submission(self, nid):
+    def get_submission(self, node):
         try:
+            nid = node['field_submission_concept_note']['target_id']
             return ApplicationSubmission.objects.get(drupal_id=nid)
         except ApplicationSubmission.DoesNotExist:
             return 'None'
diff --git a/opentech/apply/determinations/management/commands/migrate_proposal_determinations.py b/opentech/apply/determinations/management/commands/migrate_proposal_determinations.py
index 3522574f9..177e5f0c2 100644
--- a/opentech/apply/determinations/management/commands/migrate_proposal_determinations.py
+++ b/opentech/apply/determinations/management/commands/migrate_proposal_determinations.py
@@ -128,7 +128,7 @@ class Command(BaseCommand):
                 created_at=datetime.fromtimestamp(int(node['created']), timezone.utc),
                 updated_at=datetime.fromtimestamp(int(node['changed']), timezone.utc),
                 author=self.get_user(node['uid']),
-                submission=self.get_submission(node['field_submission_concept_note']['target_id']),
+                submission=self.get_submission(node),
                 outcome=self.get_determination(node),
                 message=self.get_field_value('field_psr_determination_message', node),
                 data=form_data,
@@ -204,8 +204,9 @@ class Command(BaseCommand):
         except User.DoesNotExist:
             return None
 
-    def get_submission(self, nid):
+    def get_submission(self, node):
         try:
+            nid = node['field_submission_proposal']['target_id']
             return ApplicationSubmission.objects.get(drupal_id=nid)
         except ApplicationSubmission.DoesNotExist:
             return 'None'
diff --git a/opentech/apply/funds/management/commands/migration_base.py b/opentech/apply/funds/management/commands/migration_base.py
index 75cbf0f97..c1cfd452d 100644
--- a/opentech/apply/funds/management/commands/migration_base.py
+++ b/opentech/apply/funds/management/commands/migration_base.py
@@ -107,7 +107,7 @@ class MigrateCommand(BaseCommand):
             if hasattr(submission.user, 'email'):
                 form_data["email"] = submission.user.email
             else:
-                form_data["email"] = f"user+{node['uid']}@exeample.com"
+                form_data["email"] = f"user+{node['uid']}@example.com"
 
         if "address" not in form_data or not form_data["address"]:
             form_data["address"] = json.dumps({"country": "GB", "thoroughfare": "This is not a real address!", "premise": "", "localityname": "London", "administrativearea": "", "postalcode": "123"})
-- 
GitLab