diff --git a/iati_datastore/iatilib/frontend/serialize/csv.py b/iati_datastore/iatilib/frontend/serialize/csv.py
index 787cff30..faa90ec2 100644
--- a/iati_datastore/iatilib/frontend/serialize/csv.py
+++ b/iati_datastore/iatilib/frontend/serialize/csv.py
@@ -141,6 +141,24 @@ def transaction_org(field, transaction):
receiver_org = partial(transaction_org, 'receiver_org')
+def transaction_org_name(field, transaction):
+ org = getattr(transaction, field)
+ if org:
+ locale = request.args.get("locale", "en")
+ if org.name_all_values and locale in org.name_all_values:
+ return org.name_all_values[locale]
+ elif org.name_all_values and 'default' in org.name_all_values:
+ return org.name_all_values['default']
+ else:
+ return org.name
+ else:
+ return ""
+
+
+provider_org_name = partial(transaction_org_name, 'provider_org')
+receiver_org_name = partial(transaction_org_name, 'receiver_org')
+
+
def title(activity):
"""Select most appropriate title for request locale"""
locale = request.args.get("locale", "en")
@@ -234,7 +252,13 @@ def reporting_org_ref(activity):
def reporting_org_name(activity):
try:
- return activity.reporting_org.name
+ locale = request.args.get("locale", "en")
+ if activity.reporting_org.name_all_values and locale in activity.reporting_org.name_all_values:
+ return activity.reporting_org.name_all_values[locale]
+ elif activity.reporting_org.name_all_values and 'default' in activity.reporting_org.name_all_values:
+ return activity.reporting_org.name_all_values['default']
+ else:
+ return activity.reporting_org.name
except AttributeError:
return ""
@@ -253,13 +277,29 @@ def reporting_org_type_code(activity):
return ""
+def participating_org_localised_name(org):
+ try:
+ locale = request.args.get("locale", "en")
+ if org.name_all_values and locale in org.name_all_values:
+ return org.name_all_values[locale]
+ elif org.name_all_values and 'default' in org.name_all_values:
+ return org.name_all_values['default']
+ else:
+ return org.name
+ except AttributeError:
+ return ""
+
+
def participating_org(attr, role, activity):
activity_by_role = dict(
[(a.role.value, a) for a in activity.participating_orgs])
participant = activity_by_role.get(role.value, "")
if participant:
- return getattr(participant.organisation, attr)
+ if attr == "name":
+ return participating_org_localised_name(participant.organisation)
+ else:
+ return getattr(participant.organisation, attr)
else:
return ''
@@ -807,11 +847,11 @@ def wrapper(args):
(u'transaction_ref', lambda t: t.ref),
(u'transaction_value_currency', value_currency),
(u'transaction_value_value-date', lambda t: t.value_date),
- (u'transaction_provider-org', lambda t: t.provider_org_text),
+ (u'transaction_provider-org', provider_org_name),
(u'transaction_provider-org_ref', provider_org),
(u'transaction_provider-org_provider-activity-id',
lambda t: t.provider_org_activity_id),
- (u'transaction_receiver-org', lambda t: t.receiver_org_text),
+ (u'transaction_receiver-org', receiver_org_name),
(u'transaction_receiver-org_ref', receiver_org),
(u'transaction_receiver-org_receiver-activity-id',
lambda t: t.receiver_org_activity_id),
@@ -830,7 +870,6 @@ def wrapper(args):
(u"transaction_sector", sector),
(u"transaction_sector-vocabulary", sector_vocabulary),
(u"transaction_sector-vocabulary-code", sector_vocabulary_code),
- # (u'reporting-org', lambda t: t.activity.reporting_org_ref),
)
_transaction_fields = (
diff --git a/iati_datastore/iatilib/test/fixtures/localised-org-names.xml b/iati_datastore/iatilib/test/fixtures/localised-org-names.xml
index acbe19f2..93c04c7a 100644
--- a/iati_datastore/iatilib/test/fixtures/localised-org-names.xml
+++ b/iati_datastore/iatilib/test/fixtures/localised-org-names.xml
@@ -4,6 +4,7 @@
Bundesministerium für wirtschaftliche Zusammenarbeit und Entwicklung (BMZ)
Federal Ministry for Economic Cooperation and Development (BMZ)
+ Ministère fédéral de la Coopération économique et du Développement (BMZ)
Esgotamento Sanitário Pernambuco
@@ -12,6 +13,7 @@
Bundesministerium für wirtschaftliche Zusammenarbeit und Entwicklung (BMZ)
Federal Ministry for Economic Cooperation and Development (BMZ)
+ Ministère fédéral de la Coopération économique et du Développement (BMZ)
KfW Bankengruppe (KfW)
@@ -28,9 +30,11 @@
Norwegian Agency for Development Cooperation (NORAD)
+ Agence norvégienne de coopération au développement (NORAD)
Care Danmark
+ Soins Danemark
@@ -42,9 +46,11 @@
ActionAid Bangladesh
+ Ayuda en Acción Bangladesh
SKS Foundation
+ Fondation SKS
diff --git a/iati_datastore/iatilib/test/test_api.py b/iati_datastore/iatilib/test/test_api.py
index b828bdef..373b4291 100644
--- a/iati_datastore/iatilib/test/test_api.py
+++ b/iati_datastore/iatilib/test/test_api.py
@@ -972,6 +972,7 @@ def test_french_description_target_groups(self):
output[1][i]
)
+
class TestActivityCurrencyConversionOutput(ClientTestCase):
"""Test new functionality to output USD and EUR in activities"""
@@ -1097,3 +1098,86 @@ def test_eur_currency_fields(self):
self.assertEquals(u'3924408.74', output[4][csv_headers.index('budget-value-EUR')]) # 2019-12-10: 3343511 GBP
self.assertEquals(u'3999715.84', output[5][csv_headers.index('budget-value-EUR')]) # 2020-12-10: 3587780 GBP
+class TestActivityLocalesOrganisationNames(ClientTestCase):
+ """Test new functionality to output locale appropriate organisation names"""
+
+ base_url = '/api/1/access/activity.csv'
+
+ def test_csv_activity_count(self):
+ load_fix("localised-org-names.xml")
+ resp = self.client.get(self.base_url)
+ self.assertEquals(2, resp.get_data(as_text=True).count("\n"))
+
+ def test_english_reporting_org(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url).get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('reporting-org')
+ self.assertEquals(
+ u'Federal Ministry for Economic Cooperation and Development (BMZ)',
+ output[1][i]
+ )
+
+ def test_french_reporting_org(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url + '?locale=fr').get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('reporting-org')
+ self.assertEquals(
+ u"Ministère fédéral de la Coopération économique et du Développement (BMZ)",
+ output[1][i]
+ )
+
+ def test_english_participating_org(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url).get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('participating-org (Funding)')
+ self.assertEquals(
+ u'Federal Ministry for Economic Cooperation and Development (BMZ)',
+ output[1][i]
+ )
+
+ def test_french_participating_org(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url + '?locale=fr').get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('participating-org (Funding)')
+ self.assertEquals(
+ u'Ministère fédéral de la Coopération économique et du Développement (BMZ)',
+ output[1][i]
+ )
+
+
+class TestTransactionLocalesOrganisationNames(ClientTestCase):
+ """Test new functionality to output locale appropriate organisation names"""
+
+ base_url = '/api/1/access/transaction.csv'
+
+ def test_provider_org_output(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url).get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('transaction_provider-org')
+ self.assertEquals(u'Norwegian Agency for Development Cooperation (NORAD)', output[1][i])
+
+ def test_provider_org_french_output(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url + '?locale=fr').get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('transaction_provider-org')
+ self.assertEquals(u'Agence norvégienne de coopération au développement (NORAD)', output[1][i])
+
+ def test_receiver_org_output(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url).get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('transaction_receiver-org')
+ self.assertEquals(u'SKS Foundation', output[2][i])
+
+ def test_receiver_org_french_output(self):
+ load_fix("localised-org-names.xml")
+ output = list(csv.reader(StringIO(self.client.get(self.base_url + '?locale=fr').get_data(as_text=True))))
+ csv_headers = output[0]
+ i = csv_headers.index('transaction_receiver-org')
+ self.assertEquals(u'Fondation SKS', output[2][i])
diff --git a/iati_datastore/iatilib/test/test_parser.py b/iati_datastore/iatilib/test/test_parser.py
index 1d8c5300..2b128337 100644
--- a/iati_datastore/iatilib/test/test_parser.py
+++ b/iati_datastore/iatilib/test/test_parser.py
@@ -1118,14 +1118,16 @@ def test_reporting_org_name(self):
self.assertEquals(
self.act.reporting_org.name_all_values,
{'de': 'Bundesministerium für wirtschaftliche Zusammenarbeit und Entwicklung (BMZ)',
- 'en': 'Federal Ministry for Economic Cooperation and Development (BMZ)'}
+ 'en': 'Federal Ministry for Economic Cooperation and Development (BMZ)',
+ 'fr': 'Ministère fédéral de la Coopération économique et du Développement (BMZ)'}
)
def test_participating_orgs(self):
self.assertEquals(
self.act.participating_orgs[0].organisation.name_all_values,
{"de": 'Bundesministerium für wirtschaftliche Zusammenarbeit und Entwicklung (BMZ)',
- "en": 'Federal Ministry for Economic Cooperation and Development (BMZ)'}
+ "en": 'Federal Ministry for Economic Cooperation and Development (BMZ)',
+ "fr": 'Ministère fédéral de la Coopération économique et du Développement (BMZ)'}
)
self.assertEquals(
self.act.participating_orgs[1].organisation.name_all_values,
@@ -1138,16 +1140,20 @@ def test_participating_orgs(self):
def test_transaction_reciever_org_name(self):
self.assertEquals(self.act.transactions[0].provider_org.name_all_values,
- {"en": 'Norwegian Agency for Development Cooperation (NORAD)'}
+ {"en": 'Norwegian Agency for Development Cooperation (NORAD)',
+ "fr": 'Agence norvégienne de coopération au développement (NORAD)'}
)
self.assertEquals(self.act.transactions[0].receiver_org.name_all_values,
- {"en": 'Care Danmark'}
+ {"en": 'Care Danmark',
+ "fr": 'Soins Danemark'}
)
self.assertEquals(self.act.transactions[1].provider_org.name_all_values,
- {"en": 'ActionAid Bangladesh'}
+ {"en": 'ActionAid Bangladesh',
+ "es": 'Ayuda en Acción Bangladesh'}
)
self.assertEquals(self.act.transactions[1].receiver_org.name_all_values,
- {"en": 'SKS Foundation'}
+ {"en": 'SKS Foundation',
+ "fr": 'Fondation SKS'}
)
class TestLocalisedOrganisationNamesActivityDefault(AppTestCase):
@@ -1191,3 +1197,4 @@ def test_transaction_reciever_org_name(self):
self.assertEquals(self.act.transactions[1].receiver_org.name_all_values,
{"de": 'SKS-Stiftung'}
)
+