-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1770] Get or create project based on IATI activity ID
- Loading branch information
1 parent
ac15ddb
commit eb0e42c
Showing
43 changed files
with
1,864 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from .activity_date import activity_date | ||
from .activity_scope import activity_scope | ||
from .activity_status import activity_status | ||
from .background import background | ||
from .budget import budget | ||
from .capital_spend import capital_spend | ||
from .collaboration_type import collaboration_type | ||
from .contact_info import contact_info | ||
from .country_budget_items import country_budget_items | ||
from .conditions import conditions | ||
from .crs_add import crs_add | ||
from .current_situation import current_situation | ||
from .default_aid_type import default_aid_type | ||
from .default_finance_type import default_finance_type | ||
from .default_flow_type import default_flow_type | ||
from .default_tied_status import default_tied_status | ||
from .document_link import document_link | ||
from .fss import fss | ||
from .goals_overview import goals_overview | ||
from .iati_identifier import iati_identifier | ||
from .legacy_data import legacy_data | ||
from .location import location | ||
from .other_identifier import other_identifier | ||
from .participating_org import participating_org | ||
from .planned_disbursement import planned_disbursement | ||
from .policy_marker import policy_marker | ||
from .project_plan import project_plan | ||
from .recipient_country import recipient_country | ||
from .recipient_region import recipient_region | ||
from .related_activity import related_activity | ||
from .reporting_org import reporting_org | ||
from .result import result | ||
from .sector import sector | ||
from .subtitle import subtitle | ||
from .sustainability import sustainability | ||
from .summary import summary | ||
from .target_group import target_group | ||
from .title import title | ||
from .transaction import transaction | ||
|
||
__all__ = [ | ||
'activity_date', | ||
'activity_scope', | ||
'activity_status', | ||
'background', | ||
'budget', | ||
'capital_spend', | ||
'collaboration_type', | ||
'conditions', | ||
'contact_info', | ||
'country_budget_items', | ||
'crs_add', | ||
'current_situation', | ||
'default_aid_type', | ||
'default_finance_type', | ||
'default_flow_type', | ||
'default_tied_status', | ||
'document_link', | ||
'fss', | ||
'goals_overview', | ||
'iati_identifier', | ||
'legacy_data', | ||
'location', | ||
'participating_org', | ||
'planned_disbursement', | ||
'policy_marker', | ||
'project_plan', | ||
'recipient_country', | ||
'recipient_region', | ||
'related_activity', | ||
'reporting_org', | ||
'result', | ||
'sector', | ||
'subtitle', | ||
'sustainability', | ||
'summary', | ||
'target_group', | ||
'title', | ||
'transaction', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def activity_date(project): | ||
""" | ||
Generate the activity-date elements. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
activity_date_elements = [] | ||
|
||
if project.date_start_planned: | ||
date_start_planned_element = etree.Element("activity-date") | ||
date_start_planned_element.attrib['iso-date'] = str(project.date_start_planned) | ||
date_start_planned_element.attrib['type'] = '1' | ||
activity_date_elements.append(date_start_planned_element) | ||
|
||
if project.date_start_actual: | ||
date_start_actual_element = etree.Element("activity-date") | ||
date_start_actual_element.attrib['iso-date'] = str(project.date_start_actual) | ||
date_start_actual_element.attrib['type'] = '2' | ||
activity_date_elements.append(date_start_actual_element) | ||
|
||
if project.date_end_planned: | ||
date_end_planned_element = etree.Element("activity-date") | ||
date_end_planned_element.attrib['iso-date'] = str(project.date_end_planned) | ||
date_end_planned_element.attrib['type'] = '3' | ||
activity_date_elements.append(date_end_planned_element) | ||
|
||
if project.date_end_actual: | ||
date_end_actual_element = etree.Element("activity-date") | ||
date_end_actual_element.attrib['iso-date'] = str(project.date_end_actual) | ||
date_end_actual_element.attrib['type'] = '4' | ||
activity_date_elements.append(date_end_actual_element) | ||
|
||
return activity_date_elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def activity_scope(project): | ||
""" | ||
Generate the activity-scope element. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
if project.project_scope: | ||
element = etree.Element("activity-scope") | ||
element.attrib['code'] = project.project_scope | ||
return [element] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
STATUS_TO_CODE = { | ||
'N': '6', | ||
'H': '1', | ||
'A': '2', | ||
'C': '3', | ||
'L': '5', | ||
'R': '6', | ||
} | ||
|
||
|
||
def activity_status(project): | ||
""" | ||
Generate the activity-status element. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
if project.status in STATUS_TO_CODE.keys(): | ||
element = etree.Element("activity-status") | ||
element.attrib['code'] = STATUS_TO_CODE[project.status] | ||
return [element] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def background(project): | ||
""" | ||
Generate the background element, a description element with type "1" and akvo type "6". | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
if project.background: | ||
element = etree.Element("description") | ||
element.attrib['type'] = '1' | ||
element.attrib['{http://akvo.org/iati-activities}type'] = '6' | ||
|
||
narrative_element = etree.SubElement(element, "narrative") | ||
narrative_element.text = project.background | ||
return [element] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def budget(project): | ||
""" | ||
Generate the budget elements. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
budget_elements = [] | ||
|
||
for budget_item in project.budget_items.all(): | ||
if budget_item.amount and budget_item.period_start and budget_item.period_end: | ||
element = etree.Element("budget") | ||
|
||
if budget_item.type: | ||
element.attrib['type'] = budget_item.type | ||
|
||
period_start_element = etree.SubElement(element, "period-start") | ||
period_start_element.attrib['iso-date'] = str(budget_item.period_start) | ||
|
||
period_end_element = etree.SubElement(element, "period-end") | ||
period_end_element.attrib['iso-date'] = str(budget_item.period_end) | ||
|
||
value_element = etree.SubElement(element, "value") | ||
value_element.text = str(budget_item.amount) | ||
|
||
if budget_item.value_date: | ||
value_element.attrib['value-date'] = str(budget_item.value_date) | ||
|
||
if budget_item.currency: | ||
value_element.attrib['currency'] = budget_item.currency | ||
|
||
if budget_item.other_extra: | ||
value_element.attrib['{http://akvo.org/iati-activities}label'] = budget_item.other_extra | ||
elif budget_item.label.label: | ||
value_element.attrib['{http://akvo.org/iati-activities}label'] = budget_item.label.label | ||
|
||
budget_elements.append(element) | ||
|
||
return budget_elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def capital_spend(project): | ||
""" | ||
Generate the capital-spend element. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
if project.capital_spend_percentage: | ||
element = etree.Element("capital-spend") | ||
element.attrib['percentage'] = str(project.capital_spend_percentage) | ||
return [element] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def collaboration_type(project): | ||
""" | ||
Generate the collaboration-type element. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
if project.collaboration_type: | ||
element = etree.Element("collaboration-type") | ||
element.attrib['code'] = project.collaboration_type | ||
return [element] | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Akvo RSR is covered by the GNU Affero General Public License. | ||
# See more details in the license.txt file located at the root folder of the Akvo RSR module. | ||
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
from lxml import etree | ||
|
||
|
||
def conditions(project): | ||
""" | ||
Generate the conditions element. | ||
:param project: Project object | ||
:return: A list of Etree elements | ||
""" | ||
conditions_element = etree.Element("conditions") | ||
|
||
if project.conditions.all(): | ||
conditions_element.attrib['attached'] = '1' | ||
else: | ||
conditions_element.attrib['attached'] = '0' | ||
|
||
for condition in project.conditions.all(): | ||
if condition.type: | ||
condition_element = etree.SubElement(conditions_element, "condition") | ||
condition_element.attrib['type'] = condition.type | ||
|
||
if condition.text: | ||
narrative_element = etree.SubElement(condition_element, "narrative") | ||
narrative_element.text = condition.text | ||
|
||
conditions_element.append(condition_element) | ||
|
||
return [conditions_element] |
Oops, something went wrong.