From 861b181d4c37d42234199f08ebb57089b928f2f5 Mon Sep 17 00:00:00 2001 From: Kasper Brandt Date: Mon, 20 Oct 2014 11:59:44 +0200 Subject: [PATCH] [#799] Updated IATI activity ID generation New rules for generating the IATI activity ID: 1. Look whether the activity ID is filled in for the partnership of the support partner 2. If not, generate the activity ID based on the organisation ID + the Akvo project ID Also, the related activity ID's are added as such, either from other partnerships or from the 'related activity id' field on partnership level. --- akvo/rsr/iati/iati_file_generator.py | 29 +++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/akvo/rsr/iati/iati_file_generator.py b/akvo/rsr/iati/iati_file_generator.py index d01613cd8c..c0e754ea26 100644 --- a/akvo/rsr/iati/iati_file_generator.py +++ b/akvo/rsr/iati/iati_file_generator.py @@ -15,7 +15,7 @@ BudgetItemLabel, InternalOrganisationID, Link, Benchmark, Benchmarkname, Category) import sys, argparse, os.path, cgi -import akvo.rsr.iati_schema as schema +import akvo.rsr.iati.iati_schema as schema class MandatoryError(Exception): @@ -464,13 +464,32 @@ def iati_identifier(activity, partnerships, organisation): """Collects the IATI identifier from the RSR project and adds it to the activity.""" identifier = "" + support_partner_has_id = False - # Return the first identifier that is found + # First look for activity ID of support partner partnership for partnership in partnerships: - if check_value(partnership.iati_activity_id): + if partnership.partner_type == partnership.SUPPORT_PARTNER and partnership.iati_activity_id: identifier = partnership.iati_activity_id internal_id = partnership.internal_id - break + support_partner_has_id = True + + # Additional IDs that are entered into other partnerships should be added as related activities. + elif not partnership.partner_type == partnership.SUPPORT_PARTNER and partnership.iati_activity_id: + related_activity_node = schema.iati_identifier(valueOf_=xml_enc(partnership.iati_activity_id)) + activity.add_related_activity(related_activity_node) + # Also add 'related activity id' of every partnership as a related activity id + if partnership.related_activity_id: + related_activity_node = schema.iati_identifier(valueOf_=xml_enc(partnership.iati_activity_id)) + activity.add_related_activity(related_activity_node) + + # When no IATI activity ID is specified for the support partner, the ID this should be generated by + # taking the IATI Org ID of the partner and affixing the Project ID. + if not support_partner_has_id: + for partnership in partnerships: + if partnership.partner_type == partnership.SUPPORT_PARTNER and partnership.organisation.iati_org_id: + identifier = partnership.organisation.iati_org_id + identifier += "-" + str(partnership.project.pk) + internal_id = partnership.internal_id if check_value(identifier): identifier_node = schema.iati_identifier(valueOf_=xml_enc(identifier)) @@ -493,7 +512,7 @@ def process_project(xml, project, org_id): """Convert a project to an IATI XML.""" # Get all necessary data - partnerships = Partnership.objects.filter(organisation_id=org_id, project_id=project.pk) + partnerships = Partnership.objects.filter(project_id=project.pk) goals = Goal.objects.filter(project_id=project.pk) try: location = project.primary_location