From f5bf78cec41c98d87be4f19d812ae4ef5eadd373 Mon Sep 17 00:00:00 2001 From: Gabriel von Heijne Date: Thu, 30 Oct 2014 10:10:25 +0100 Subject: [PATCH] [#865] Remove IATIProjectResource.sync_owner The IATIProjectResource.sync_owner field is causing the Cordaid IATI import to be very slow, so we're removing the field and setting the ownership in the post import step instead. --- akvo/api/resources/project.py | 14 ++++++++------ akvo/scripts/cordaid/post_import.py | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/akvo/api/resources/project.py b/akvo/api/resources/project.py index 2e72359bb2..072ac7a928 100644 --- a/akvo/api/resources/project.py +++ b/akvo/api/resources/project.py @@ -66,10 +66,14 @@ class IATIProjectResource(ModelResource): 'partnerships', full=True, related_name='project' ) - sync_owner = fields.ToOneField( - 'akvo.api.resources.OrganisationResource', - 'sync_owner', full=True, related_name='project' - ) + # This field makes the Cordaid import dismally slow, and isn't used for anything else, + # so rather than trying to fix it by re-writing the OrganisationResource, we set the sync_owner + # to Cordaid in the post_import.py script + # This commented code remains as a reminder NOT to add the field as currently defined ;-) + # sync_owner = fields.ToOneField( + # 'akvo.api.resources.OrganisationResource', + # 'sync_owner', full=True, related_name='project' + # ) class Meta: allowed_methods = ['post', 'put'] @@ -127,7 +131,6 @@ def alter_deserialized_detail_data(self, request, data): reporting_iati_org_id = data['partnerships'][0]['reporting_org'] # Cordaid custom code if reporting_iati_org_id == getattr(settings, 'CORDAID_IATI_ID', 'NL-KVK-41160054'): - data['sync_owner'] = Organisation.objects.get(iati_org_id__exact='NL-KVK-41160054') # Figure out the category for the project from the business unit business_unit_categories = { "K6020": dict(cat_name="Children & Education", fa="Education"), @@ -158,7 +161,6 @@ def alter_deserialized_detail_data(self, request, data): benchmarks.append(new_benchmark) data['benchmarks'] = benchmarks if reporting_iati_org_id == getattr(settings, 'RAIN_IATI_ID', 'NL-KVK-34200988'): - data['sync_owner'] = Organisation.objects.get(iati_org_id__exact='NL-KVK-34200988') # remove benchmarks, as they currently have no category data['benchmarks'] = [] diff --git a/akvo/scripts/cordaid/post_import.py b/akvo/scripts/cordaid/post_import.py index 4a995182f9..f8ba7e42cd 100644 --- a/akvo/scripts/cordaid/post_import.py +++ b/akvo/scripts/cordaid/post_import.py @@ -102,6 +102,9 @@ def assign_funding_partner(project, organisation, amount): project = Project.objects.get( partnerships__internal_id=internal_id, partnerships__organisation=cordaid ) + # Set sync_owner of project to Cordaid + project.sync_owner = cordaid + project.save() cordaid_funding = budget.get('cordaid_funding', 0) others_funding = budget.get('others_funding', 0) if cordaid_funding: