Skip to content

Commit

Permalink
Merge pull request #818 from akvo/feature/799_iati_activity_id
Browse files Browse the repository at this point in the history
[#799] Updated IATI activity ID generation
  • Loading branch information
zzgvh committed Oct 21, 2014
2 parents a4175ea + 861b181 commit 408bade
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions akvo/rsr/iati/iati_file_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 408bade

Please sign in to comment.