diff --git a/akvo/iati/checks/__init__.py b/akvo/iati/checks/__init__.py index 8bbceec412..e69de29bb2 100644 --- a/akvo/iati/checks/__init__.py +++ b/akvo/iati/checks/__init__.py @@ -1,11 +0,0 @@ -# -*- 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 .v201 import V201Checks - -__all__ = [ - 'V201Checks', -] diff --git a/akvo/iati/mandatory_fields.py b/akvo/iati/checks/mandatory_fields.py similarity index 89% rename from akvo/iati/mandatory_fields.py rename to akvo/iati/checks/mandatory_fields.py index 441e7edf50..77ebcc64ce 100644 --- a/akvo/iati/mandatory_fields.py +++ b/akvo/iati/checks/mandatory_fields.py @@ -4,7 +4,7 @@ # 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 >. -import checks +import versions def check_export_fields(project, version='2.01'): @@ -15,6 +15,6 @@ def check_export_fields(project, version='2.01'): """ # TODO: Add check for IATI versions (generic) version_file = "V%sChecks" % version.replace('.', '') - project_checks = getattr(checks, version_file)(project) + project_checks = getattr(versions, version_file)(project) project_checks.execute_all_checks() return project_checks.all_checks_passed, project_checks.checks_results diff --git a/akvo/iati/checks/versions/__init__.py b/akvo/iati/checks/versions/__init__.py new file mode 100644 index 0000000000..8bbceec412 --- /dev/null +++ b/akvo/iati/checks/versions/__init__.py @@ -0,0 +1,11 @@ +# -*- 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 .v201 import V201Checks + +__all__ = [ + 'V201Checks', +] diff --git a/akvo/iati/checks/v201.py b/akvo/iati/checks/versions/v201.py similarity index 100% rename from akvo/iati/checks/v201.py rename to akvo/iati/checks/versions/v201.py diff --git a/akvo/iati/elements/__init__.py b/akvo/iati/elements/__init__.py deleted file mode 100644 index 4d808c3366..0000000000 --- a/akvo/iati/elements/__init__.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- 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', -] diff --git a/akvo/iati/elements/activity_date.py b/akvo/iati/elements/activity_date.py deleted file mode 100644 index ad3aa082f7..0000000000 --- a/akvo/iati/elements/activity_date.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- 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 diff --git a/akvo/iati/elements/activity_scope.py b/akvo/iati/elements/activity_scope.py deleted file mode 100644 index 6f5f7aaab6..0000000000 --- a/akvo/iati/elements/activity_scope.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 [] diff --git a/akvo/iati/elements/activity_status.py b/akvo/iati/elements/activity_status.py deleted file mode 100644 index f4f51ced84..0000000000 --- a/akvo/iati/elements/activity_status.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- 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 [] diff --git a/akvo/iati/elements/background.py b/akvo/iati/elements/background.py deleted file mode 100644 index ff31589402..0000000000 --- a/akvo/iati/elements/background.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 [] diff --git a/akvo/iati/elements/budget.py b/akvo/iati/elements/budget.py deleted file mode 100644 index 304461de5d..0000000000 --- a/akvo/iati/elements/budget.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- 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 diff --git a/akvo/iati/elements/capital_spend.py b/akvo/iati/elements/capital_spend.py deleted file mode 100644 index d73e895575..0000000000 --- a/akvo/iati/elements/capital_spend.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 [] diff --git a/akvo/iati/elements/collaboration_type.py b/akvo/iati/elements/collaboration_type.py deleted file mode 100644 index 1dd345c947..0000000000 --- a/akvo/iati/elements/collaboration_type.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 [] diff --git a/akvo/iati/elements/conditions.py b/akvo/iati/elements/conditions.py deleted file mode 100644 index c4d31461a2..0000000000 --- a/akvo/iati/elements/conditions.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- 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] diff --git a/akvo/iati/elements/contact_info.py b/akvo/iati/elements/contact_info.py deleted file mode 100644 index 54e900299e..0000000000 --- a/akvo/iati/elements/contact_info.py +++ /dev/null @@ -1,64 +0,0 @@ -# -*- 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 contact_info(project): - """ - Generate the contact-info elements. - - :param project: Project object - :return: A list of Etree elements - """ - contact_info_elements = [] - - for contact in project.contacts.all(): - element = etree.Element("contact-info") - - if contact.type: - element.attrib['type'] = str(contact.type) - - if contact.organisation: - organisation_element = etree.SubElement(element, "organisation") - narrative_element = etree.SubElement(organisation_element, "narrative") - narrative_element.text = contact.organisation - - if contact.department: - department_element = etree.SubElement(element, "department") - narrative_element = etree.SubElement(department_element, "narrative") - narrative_element.text = contact.department - - if contact.person_name: - person_name_element = etree.SubElement(element, "person-name") - narrative_element = etree.SubElement(person_name_element, "narrative") - narrative_element.text = contact.person_name - - if contact.job_title: - job_title_element = etree.SubElement(element, "job-title") - narrative_element = etree.SubElement(job_title_element, "narrative") - narrative_element.text = contact.job_title - - if contact.telephone: - telephone_element = etree.SubElement(element, "telephone") - telephone_element.text = contact.telephone - - if contact.email: - email_element = etree.SubElement(element, "email") - email_element.text = contact.email - - if contact.website: - website_element = etree.SubElement(element, "website") - website_element.text = contact.website - - if contact.mailing_address: - mailing_address_element = etree.SubElement(element, "mailing-address") - narrative_element = etree.SubElement(mailing_address_element, "narrative") - narrative_element.text = contact.mailing_address - - contact_info_elements.append(element) - - return contact_info_elements diff --git a/akvo/iati/elements/country_budget_items.py b/akvo/iati/elements/country_budget_items.py deleted file mode 100644 index 09145bcb19..0000000000 --- a/akvo/iati/elements/country_budget_items.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- 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 country_budget_items(project): - """ - Generate the country-budget-items element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.country_budget_items.all(): - country_budget_items_element = etree.Element("country-budget-items") - else: - return [] - - if project.country_budget_vocabulary: - country_budget_items_element.attrib['vocabulary'] = project.country_budget_vocabulary - - for budget_item in project.country_budget_items.all(): - if budget_item.code: - element = etree.SubElement(country_budget_items_element, "budget-item") - element.attrib['code'] = budget_item.code - - if budget_item.description: - description_element = etree.SubElement(element, "description") - narrative_element = etree.SubElement(description_element, "narrative") - narrative_element.text = budget_item.description - - country_budget_items_element.append(element) - - return [country_budget_items_element] diff --git a/akvo/iati/elements/crs_add.py b/akvo/iati/elements/crs_add.py deleted file mode 100644 index f676ce1413..0000000000 --- a/akvo/iati/elements/crs_add.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- 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 crs_add(project): - """ - Generate the crs-add element. - - :param project: Project object - :return: A list of Etree elements - """ - try: - crs = project.crsadd - except: - return [] - - element = etree.Element("crs-add") - - for flag in crs.other_flags.all(): - if flag.code and flag.significance is not None: - other_flag_element = etree.SubElement(element, "other-flags") - other_flag_element.attrib['code'] = flag.code - other_flag_element.attrib['significance'] = '1' if flag.significance else '0' - - element.append(other_flag_element) - - loan_terms_element = etree.SubElement(element, "loan-terms") - - if crs.loan_terms_rate1: - loan_terms_element.attrib['rate-1'] = str(crs.loan_terms_rate1) - - if crs.loan_terms_rate2: - loan_terms_element.attrib['rate-2'] = str(crs.loan_terms_rate2) - - if crs.repayment_type: - repayment_type_element = etree.SubElement(loan_terms_element, "repayment-type") - repayment_type_element.attrib['code'] = crs.repayment_type - - if crs.repayment_plan: - repayment_plan_element = etree.SubElement(loan_terms_element, "repayment-plan") - repayment_plan_element.attrib['code'] = crs.repayment_plan - - if crs.commitment_date: - commitment_date_element = etree.SubElement(loan_terms_element, "commitment-date") - commitment_date_element.attrib['iso-date'] = str(crs.commitment_date) - - if crs.repayment_first_date: - repayment_first_date_element = etree.SubElement(loan_terms_element, "repayment-first-date") - repayment_first_date_element.attrib['iso-date'] = str(crs.repayment_first_date) - - if crs.repayment_final_date: - repayment_final_date_element = etree.SubElement(loan_terms_element, "repayment-final-date") - repayment_final_date_element.attrib['iso-date'] = str(crs.repayment_final_date) - - element.append(loan_terms_element) - - loan_status_element = etree.SubElement(element, "loan-status") - - if crs.loan_status_year: - loan_status_element.attrib['year'] = str(crs.loan_status_year) - - if crs.loan_status_currency: - loan_status_element.attrib['currency'] = crs.loan_status_currency - - if crs.loan_status_value_date: - loan_status_element.attrib['value-date'] = str(crs.loan_status_value_date) - - if crs.interest_received: - interest_received_element = etree.SubElement(loan_status_element, "interest-received") - interest_received_element.text = str(crs.interest_received) - - if crs.principal_outstanding: - principal_outstanding_element = etree.SubElement(loan_status_element, "principal-outstanding") - principal_outstanding_element.text = str(crs.principal_outstanding) - - if crs.principal_arrears: - principal_arrears_element = etree.SubElement(loan_status_element, "principal-arrears") - principal_arrears_element.text = str(crs.principal_arrears) - - if crs.interest_arrears: - interest_arrears_element = etree.SubElement(loan_status_element, "interest-arrears") - interest_arrears_element.text = str(crs.interest_arrears) - - element.append(loan_status_element) - - return [element] diff --git a/akvo/iati/elements/current_situation.py b/akvo/iati/elements/current_situation.py deleted file mode 100644 index 9b4f9e8075..0000000000 --- a/akvo/iati/elements/current_situation.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 current_situation(project): - """ - Generate the current situation element, a description element with type "1" and akvo type "9". - - :param project: Project object - :return: A list of Etree elements - """ - if project.current_status: - element = etree.Element("description") - element.attrib['type'] = '1' - element.attrib['{http://akvo.org/iati-activities}type'] = '9' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.current_status - return [element] - - return [] diff --git a/akvo/iati/elements/default_aid_type.py b/akvo/iati/elements/default_aid_type.py deleted file mode 100644 index 08c1e121b5..0000000000 --- a/akvo/iati/elements/default_aid_type.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 default_aid_type(project): - """ - Generate the default-aid-type element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.default_aid_type: - element = etree.Element("default-aid-type") - element.attrib['code'] = project.default_aid_type - return [element] - - return [] diff --git a/akvo/iati/elements/default_finance_type.py b/akvo/iati/elements/default_finance_type.py deleted file mode 100644 index 28a53bcccb..0000000000 --- a/akvo/iati/elements/default_finance_type.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 default_finance_type(project): - """ - Generate the default-finance-type element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.default_finance_type: - element = etree.Element("default-finance-type") - element.attrib['code'] = project.default_finance_type - return [element] - - return [] diff --git a/akvo/iati/elements/default_flow_type.py b/akvo/iati/elements/default_flow_type.py deleted file mode 100644 index 40656f3804..0000000000 --- a/akvo/iati/elements/default_flow_type.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 default_flow_type(project): - """ - Generate the default-flow-type element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.default_flow_type: - element = etree.Element("default-flow-type") - element.attrib['code'] = project.default_flow_type - return [element] - - return [] diff --git a/akvo/iati/elements/default_tied_status.py b/akvo/iati/elements/default_tied_status.py deleted file mode 100644 index 434a911932..0000000000 --- a/akvo/iati/elements/default_tied_status.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 default_tied_status(project): - """ - Generate the default-aid-type element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.default_tied_status: - element = etree.Element("default-tied-status") - element.attrib['code'] = project.default_tied_status - return [element] - - return [] diff --git a/akvo/iati/elements/document_link.py b/akvo/iati/elements/document_link.py deleted file mode 100644 index 9b7ea7b8cf..0000000000 --- a/akvo/iati/elements/document_link.py +++ /dev/null @@ -1,104 +0,0 @@ -# -*- 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 document_link(project): - """ - Generate the document-link elements. - - :param project: Project object - :return: A list of Etree elements - """ - document_link_elements = [] - - if project.current_image: - current_image_element = etree.Element("document-link") - current_image_element.attrib['url'] = "http://rsr.akvo.org" + project.current_image.url - current_image_element.attrib['format'] = "image/jpeg" - - title_element = etree.SubElement(current_image_element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - - if project.current_image_caption or project.current_image_credit: - if project.current_image_caption and project.current_image_credit: - narrative_element.text = "%s, credit: %s" % ( - project.current_image_caption, - project.current_image_credit - ) - elif project.current_image_caption: - narrative_element.text = project.current_image_caption - elif project.current_image_credit: - narrative_element.text = "Credit: %s" % (project.current_image_credit,) - else: - narrative_element.text = "Project photo" - - category_element = etree.SubElement(current_image_element, "category") - category_element.attrib['code'] = "A12" - - document_link_elements.append(current_image_element) - - for link in project.links.all(): - if link.url: - link_element = etree.Element("document-link") - link_element.attrib['url'] = link.url - link_element.attrib['format'] = "application/http" - - title_element = etree.SubElement(link_element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - narrative_element.text = link.caption if link.caption else "Project link" - - category_element = etree.SubElement(link_element, "category") - category_element.attrib['code'] = "A12" - - document_link_elements.append(link_element) - - for document in project.documents.all(): - if document.url or document.document: - document_element = etree.Element("document-link") - - if document.url: - document_element.attrib['url'] = document.url - elif document.document: - document_element.attrib['url'] = "http://rsr.akvo.org" + document.document.url - - if document.format: - document_element.attrib['format'] = document.format - - title_element = etree.SubElement(document_element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - narrative_element.text = document.title if document.title else "Project document" - - if document.category: - category_element = etree.SubElement(document_element, "category") - category_element.attrib['code'] = document.category - - if document.language: - language_element = etree.SubElement(document_element, "language") - language_element.attrib['code'] = document.language - - document_link_elements.append(document_element) - - for update in project.project_updates.all(): - update_element = etree.Element("document-link") - update_element.attrib['url'] = "http://rsr.akvo.org/project/%s/update/%s/" % (str(project.pk), str(update.pk)) - update_element.attrib['format'] = "application/http" - - title_element = etree.SubElement(update_element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - narrative_element.text = update.title if update.title else "Project update" - - category_element = etree.SubElement(update_element, "category") - category_element.attrib['code'] = "A12" - - if update.language: - language_element = etree.SubElement(update_element, "language") - language_element.attrib['code'] = update.language - - document_link_elements.append(update_element) - - return document_link_elements diff --git a/akvo/iati/elements/fss.py b/akvo/iati/elements/fss.py deleted file mode 100644 index 4645e5cb71..0000000000 --- a/akvo/iati/elements/fss.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- 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 fss(project): - """ - Generate the fss element. - - :param project: Project object - :return: A list of Etree elements - """ - try: - fss_object = project.fss - except: - return [] - - element = etree.Element("fss") - - if fss_object.extraction_date: - element.attrib['extraction-date'] = str(fss_object.extraction_date) - - if fss_object.priority is not None: - element.attrib['priority'] = '1' if fss_object.priority else '0' - - if fss_object.phaseout_year: - element.attrib['phaseout-year'] = str(fss_object.phaseout_year) - - for forecast in fss_object.forecasts.all(): - if forecast.value: - forecast_element = etree.SubElement(element, "forecast") - forecast_element.text = str(forecast.value) - - if forecast.year: - forecast_element.attrib['year'] = str(forecast.year) - - if forecast.value_date: - forecast_element.attrib['value-date'] = str(forecast.value_date) - - if forecast.currency: - forecast_element.attrib['currency'] = str(forecast.currency) - - element.append(forecast_element) - - return [element] diff --git a/akvo/iati/elements/goals_overview.py b/akvo/iati/elements/goals_overview.py deleted file mode 100644 index af53ddeb55..0000000000 --- a/akvo/iati/elements/goals_overview.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 goals_overview(project): - """ - Generate the goals overview element, a description element with type "2" and akvo type "8". - - :param project: Project object - :return: A list of Etree elements - """ - if project.goals_overview: - element = etree.Element("description") - element.attrib['type'] = '2' - element.attrib['{http://akvo.org/iati-activities}type'] = '8' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.goals_overview - return [element] - - return [] diff --git a/akvo/iati/elements/iati_identifier.py b/akvo/iati/elements/iati_identifier.py deleted file mode 100644 index 9666620b89..0000000000 --- a/akvo/iati/elements/iati_identifier.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- 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 iati_identifier(project): - """ - Generate the iati-identifier element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.iati_activity_id: - element = etree.Element("iati-identifier") - element.text = project.iati_activity_id - return [element] - - return [] diff --git a/akvo/iati/elements/legacy_data.py b/akvo/iati/elements/legacy_data.py deleted file mode 100644 index 0e69acc6e6..0000000000 --- a/akvo/iati/elements/legacy_data.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- 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 legacy_data(project): - """ - Generate the legacy-data element. - - :param project: Project object - :return: A list of Etree elements - """ - legacy_data_elements = [] - - for legacy in project.legacy_data.all(): - if legacy.name and legacy.value: - element = etree.Element("legacy-data") - element.attrib['name'] = legacy.name - element.attrib['value'] = legacy.value - - if legacy.iati_equivalent: - element.attrib['iati-equivalent'] = legacy.iati_equivalent - - legacy_data_elements.append(element) - - return legacy_data_elements diff --git a/akvo/iati/elements/location.py b/akvo/iati/elements/location.py deleted file mode 100644 index c7518791d6..0000000000 --- a/akvo/iati/elements/location.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- 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 location(project): - """ - Generate the location elements. - - :param project: Project object - :return: A list of Etree elements - """ - location_elements = [] - - for loc in project.locations.all(): - element = etree.Element("location") - - if loc.reference: - element.attrib['ref'] = loc.reference - - if loc.location_reach: - reach_element = etree.SubElement(element, "location-reach") - reach_element.attrib['code'] = loc.location_reach - - if loc.location_code and loc.vocabulary: - id_element = etree.SubElement(element, "location-id") - id_element.attrib['vocabulary'] = loc.vocabulary - id_element.attrib['code'] = loc.location_code - - if loc.name: - name_element = etree.SubElement(element, "name") - narrative_element = etree.SubElement(name_element, "narrative") - narrative_element.text = loc.name - - if loc.description: - description_element = etree.SubElement(element, "description") - narrative_element = etree.SubElement(description_element, "narrative") - narrative_element.text = loc.description - - if loc.activity_description: - activity_description_element = etree.SubElement(element, "activity-description") - narrative_element = etree.SubElement(activity_description_element, "narrative") - narrative_element.text = loc.activity_description - - for administrative in loc.administratives.all(): - if administrative.code and administrative.vocabulary: - administrative_element = etree.SubElement(element, "administrative") - administrative_element.attrib['vocabulary'] = administrative.vocabulary - administrative_element.attrib['code'] = administrative.code - - if administrative.level: - administrative_element.attrib['level'] = str(administrative.level) - - if loc.latitude and loc.longitude: - point_element = etree.SubElement(element, "point") - point_element.attrib['srsName'] = 'http://www.opengis.net/def/crs/EPSG/0/4326' - pos_element = etree.SubElement(point_element, "pos") - pos_element.text = "%s %s" % (str(loc.latitude), str(loc.longitude)) - - if loc.exactness: - exactness_element = etree.SubElement(element, "exactness") - exactness_element.attrib['code'] = str(loc.exactness) - - if loc.location_class: - class_element = etree.SubElement(element, "location-class") - class_element.attrib['code'] = str(loc.location_class) - - if loc.feature_designation: - feature_element = etree.SubElement(element, "feature-designation") - feature_element.attrib['code'] = str(loc.feature_designation) - - location_elements.append(element) - - return location_elements diff --git a/akvo/iati/elements/other_identifier.py b/akvo/iati/elements/other_identifier.py deleted file mode 100644 index bbad59c9a1..0000000000 --- a/akvo/iati/elements/other_identifier.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- 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 other_identifier(project): - """ - Generate the other-identifier elements. - - :param project: Project object - :return: A list of Etree elements - """ - other_identifier_elements = [] - - element = etree.Element("other-identifier") - element.attrib['ref'] = str(project.pk) - element.attrib['type'] = 'B9' - - owner_org_element = etree.SubElement(element, "owner-org") - owner_org_element.attrib['ref'] = 'NL-KVK-27327087' - - narrative_element = etree.SubElement(owner_org_element, "narrative") - narrative_element.text = 'Akvo Foundation' - - other_identifier_elements.append(element) - - for partnership in project.partnerships.all(): - org = partnership.organisation - - if partnership.internal_id: - element = etree.Element("other-identifier") - element.attrib['ref'] = str(partnership.internal_id) - element.attrib['type'] = 'A1' if org == project.sync_owner else 'B9' - - owner_org_element = etree.SubElement(element, "owner-org") - - if org.iati_org_id: - owner_org_element.attrib['ref'] = org.iati_org_id - - narrative_element = etree.SubElement(owner_org_element, "narrative") - - if org.long_name: - narrative_element.text = org.long_name - elif org.name: - narrative_element.text = org.name - - other_identifier_elements.append(element) - - return other_identifier_elements diff --git a/akvo/iati/elements/participating_org.py b/akvo/iati/elements/participating_org.py deleted file mode 100644 index a8346acdb7..0000000000 --- a/akvo/iati/elements/participating_org.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- 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 - -TYPE_TO_CODE = { - 'funding': '1', - 'support': '2', - 'sponsor': '3', - 'field': '4', -} - - -def participating_org(project): - """ - Generate the participating-org element. - - :param project: Project object - :return: A list of Etree elements - """ - partnership_elements = [] - - from akvo.rsr.models import Partnership - - for partnership in project.partnerships.all(): - org = partnership.organisation - element = etree.Element("participating-org") - - if org.iati_org_id: - element.attrib['ref'] = org.iati_org_id - - if org.new_organisation_type: - element.attrib['type'] = str(org.new_organisation_type) - # don't include old akvo sponsor partner value when checking - if partnership.iati_organisation_role in Partnership.IATI_ROLE_LIST[:-1]: - element.attrib['role'] = str(partnership.iati_organisation_role) - - narrative_element = etree.SubElement(element, "narrative") - - if org.long_name: - narrative_element.text = org.long_name - elif org.name: - narrative_element.text = org.name - - partnership_elements.append(element) - - return partnership_elements diff --git a/akvo/iati/elements/planned_disbursement.py b/akvo/iati/elements/planned_disbursement.py deleted file mode 100644 index 5955556eb5..0000000000 --- a/akvo/iati/elements/planned_disbursement.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- 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 planned_disbursement(project): - """ - Generate the planned-disbursement elements. - - :param project: Project object - :return: A list of Etree elements - """ - planned_disbursement_elements = [] - - for planned_disbursement in project.planned_disbursements.all(): - if planned_disbursement.value: - element = etree.Element("planned-disbursement") - - if planned_disbursement.type: - element.attrib['type'] = planned_disbursement.type - - if planned_disbursement.period_start: - period_start_element = etree.SubElement(element, "period-start") - period_start_element.attrib['iso-date'] = str(planned_disbursement.period_start) - - if planned_disbursement.period_end: - period_end_element = etree.SubElement(element, "period-end") - period_end_element.attrib['iso-date'] = str(planned_disbursement.period_end) - - value_element = etree.SubElement(element, "value") - value_element.text = str(planned_disbursement.value) - - if planned_disbursement.value_date: - value_element.attrib['value-date'] = str(planned_disbursement.value_date) - - if planned_disbursement.currency: - value_element.attrib['currency'] = planned_disbursement.currency - - planned_disbursement_elements.append(element) - - return planned_disbursement_elements diff --git a/akvo/iati/elements/policy_marker.py b/akvo/iati/elements/policy_marker.py deleted file mode 100644 index faf553cc80..0000000000 --- a/akvo/iati/elements/policy_marker.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- 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 policy_marker(project): - """ - Generate the policy-marker element. - - :param project: Project object - :return: A list of Etree elements - """ - policy_marker_elements = [] - - for policy in project.policy_markers.all(): - if policy.policy_marker and policy.significance: - element = etree.Element("policy-marker") - element.attrib['code'] = policy.policy_marker - element.attrib['significance'] = policy.significance - - if policy.vocabulary: - element.attrib['vocabulary'] = policy.vocabulary - - if policy.description: - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = policy.description - - policy_marker_elements.append(element) - - return policy_marker_elements diff --git a/akvo/iati/elements/project_plan.py b/akvo/iati/elements/project_plan.py deleted file mode 100644 index afce1a0aba..0000000000 --- a/akvo/iati/elements/project_plan.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 project_plan(project): - """ - Generate the project plan element, a description element with type "1" and akvo type "7". - - :param project: Project object - :return: A list of Etree elements - """ - if project.project_plan: - element = etree.Element("description") - element.attrib['type'] = '1' - element.attrib['{http://akvo.org/iati-activities}type'] = '7' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.project_plan - return [element] - - return [] diff --git a/akvo/iati/elements/recipient_country.py b/akvo/iati/elements/recipient_country.py deleted file mode 100644 index b9baa9671a..0000000000 --- a/akvo/iati/elements/recipient_country.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- 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 recipient_country(project): - """ - Generate the recipient-country element. - - :param project: Project object - :return: A list of Etree elements - """ - recipient_country_elements = [] - - for country in project.recipient_countries.all(): - if country.country: - element = etree.Element("recipient-country") - element.attrib['code'] = country.country - - if country.percentage: - element.attrib['percentage'] = str(country.percentage) - - if country.text: - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = country.text - - recipient_country_elements.append(element) - - return recipient_country_elements diff --git a/akvo/iati/elements/recipient_region.py b/akvo/iati/elements/recipient_region.py deleted file mode 100644 index bda1134d13..0000000000 --- a/akvo/iati/elements/recipient_region.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- 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 recipient_region(project): - """ - Generate the recipient-region element. - - :param project: Project object - :return: A list of Etree elements - """ - recipient_region_elements = [] - - for region in project.recipient_regions.all(): - if region.region: - element = etree.Element("recipient-region") - element.attrib['code'] = region.region - - if region.percentage: - element.attrib['percentage'] = str(region.percentage) - - if region.region_vocabulary: - element.attrib['vocabulary'] = str(region.region_vocabulary) - - if region.text: - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = region.text - - recipient_region_elements.append(element) - - return recipient_region_elements diff --git a/akvo/iati/elements/related_activity.py b/akvo/iati/elements/related_activity.py deleted file mode 100644 index bea90a3e68..0000000000 --- a/akvo/iati/elements/related_activity.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- 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 related_activity(project): - """ - Generate the related-activity elements. - - :param project: Project object - :return: A list of Etree elements - """ - related_activity_elements = [] - - for related_project in project.related_projects.all(): - if related_project.related_project and related_project.relation: - if related_project.related_project.iati_activity_id: - element = etree.Element("related-activity") - element.attrib['ref'] = related_project.related_project.iati_activity_id - element.attrib['type'] = related_project.relation - - related_activity_elements.append(element) - - elif related_project.related_iati_id and related_project.relation: - element = etree.Element("related-activity") - element.attrib['ref'] = related_project.related_iati_id - element.attrib['type'] = related_project.relation - - related_activity_elements.append(element) - - for related_to_project in project.related_to_projects.all(): - if related_to_project.project.iati_activity_id and related_to_project.relation: - element = etree.Element("related-activity") - element.attrib['ref'] = related_to_project.project.iati_activity_id - element.attrib['type'] = related_to_project.relation - - related_activity_elements.append(element) - - return related_activity_elements diff --git a/akvo/iati/elements/reporting_org.py b/akvo/iati/elements/reporting_org.py deleted file mode 100644 index be874b9f42..0000000000 --- a/akvo/iati/elements/reporting_org.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- 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 reporting_org(project): - """ - Generate the reporting-org element. - - :param project: Project object - :return: A list of Etree elements - """ - org = project.sync_owner - if org: - element = etree.Element("reporting-org") - - if org.iati_org_id: - element.attrib['ref'] = org.iati_org_id - - if project.sync_owner_secondary_reporter is not None: - element.attrib['secondary-reporter'] = '1' if project.sync_owner_secondary_reporter else '0' - - if org.new_organisation_type: - element.attrib['type'] = str(org.new_organisation_type) - - narrative_element = etree.SubElement(element, "narrative") - - if org.long_name: - narrative_element.text = org.long_name - elif org.name: - narrative_element.text = org.name - - return [element] - - return [] diff --git a/akvo/iati/elements/result.py b/akvo/iati/elements/result.py deleted file mode 100644 index 10ba4d3e17..0000000000 --- a/akvo/iati/elements/result.py +++ /dev/null @@ -1,102 +0,0 @@ -# -*- 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 result(project): - """ - Generate the result elements. - - :param project: Project object - :return: A list of Etree elements - """ - result_elements = [] - - for res in project.results.all(): - element = etree.Element("result") - - if res.type: - element.attrib['type'] = res.type - - if res.aggregation_status is not None: - element.attrib['aggregation-status'] = '1' if res.aggregation_status else '0' - - if res.title: - title_element = etree.SubElement(element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - narrative_element.text = res.title - - if res.description: - description_element = etree.SubElement(element, "description") - narrative_element = etree.SubElement(description_element, "narrative") - narrative_element.text = res.description - - for indicator in res.indicators.all(): - indicator_element = etree.SubElement(element, "indicator") - - if indicator.measure: - indicator_element.attrib['measure'] = indicator.measure - - if indicator.ascending is not None: - indicator_element.attrib['ascending'] = '1' if indicator.ascending else '0' - - if indicator.title: - title_element = etree.SubElement(indicator_element, "title") - narrative_element = etree.SubElement(title_element, "narrative") - narrative_element.text = indicator.title - - if indicator.description: - description_element = etree.SubElement(indicator_element, "description") - narrative_element = etree.SubElement(description_element, "narrative") - narrative_element.text = res.description - - if indicator.baseline_year and indicator.baseline_value: - baseline_element = etree.SubElement(indicator_element, "baseline") - baseline_element.attrib['year'] = str(indicator.baseline_year) - baseline_element.attrib['value'] = indicator.baseline_value - - if indicator.baseline_comment: - comment_element = etree.SubElement(baseline_element, "comment") - narrative_element = etree.SubElement(comment_element, "narrative") - narrative_element.text = indicator.baseline_comment - - for period in indicator.periods.all(): - period_element = etree.SubElement(indicator_element, "period") - - if period.period_start: - period_start_element = etree.SubElement(period_element, "period-start") - period_start_element.attrib['iso-date'] = str(period.period_start) - - if period.period_end: - period_end_element = etree.SubElement(period_element, "period-end") - period_end_element.attrib['iso-date'] = str(period.period_end) - - if period.target_value: - target_element = etree.SubElement(period_element, "target") - target_element.attrib['value'] = period.target_value - - if period.target_comment: - comment_element = etree.SubElement(target_element, "comment") - narrative_element = etree.SubElement(comment_element, "narrative") - narrative_element.text = period.target_comment - - if period.actual_value: - actual_element = etree.SubElement(period_element, "actual") - actual_element.attrib['value'] = period.actual_value - - if period.actual_comment: - comment_element = etree.SubElement(actual_element, "comment") - narrative_element = etree.SubElement(comment_element, "narrative") - narrative_element.text = period.actual_comment - - indicator_element.append(period_element) - - element.append(indicator_element) - - result_elements.append(element) - - return result_elements diff --git a/akvo/iati/elements/sector.py b/akvo/iati/elements/sector.py deleted file mode 100644 index a05bd2f16f..0000000000 --- a/akvo/iati/elements/sector.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- 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 sector(project): - """ - Generate the sector elements. - - :param project: Project object - :return: A list of Etree elements - """ - sector_elements = [] - - for sec in project.sectors.all(): - if sec.sector_code: - element = etree.Element("sector") - element.attrib['code'] = sec.sector_code - - if not sec.vocabulary or sec.vocabulary == 'DAC': - element.attrib['vocabulary'] = '1' - elif sec.vocabulary == 'DAC-3': - element.attrib['vocabulary'] = '2' - else: - element.attrib['vocabulary'] = sec.vocabulary - - if sec.percentage: - element.attrib['percentage'] = str(sec.percentage) - - sector_elements.append(element) - - return sector_elements diff --git a/akvo/iati/elements/subtitle.py b/akvo/iati/elements/subtitle.py deleted file mode 100644 index de05017c90..0000000000 --- a/akvo/iati/elements/subtitle.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 subtitle(project): - """ - Generate the subtitle element, a description element with type "1" and akvo type "4". - - :param project: Project object - :return: A list of Etree elements - """ - if project.subtitle: - element = etree.Element("description") - element.attrib['type'] = '1' - element.attrib['{http://akvo.org/iati-activities}type'] = '4' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.subtitle - return [element] - - return [] diff --git a/akvo/iati/elements/summary.py b/akvo/iati/elements/summary.py deleted file mode 100644 index bd894d8c6f..0000000000 --- a/akvo/iati/elements/summary.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 summary(project): - """ - Generate the summary element, a description element with type "1" and akvo type "5". - - :param project: Project object - :return: A list of Etree elements - """ - if project.project_plan_summary: - element = etree.Element("description") - element.attrib['type'] = '1' - element.attrib['{http://akvo.org/iati-activities}type'] = '5' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.project_plan_summary - return [element] - - return [] diff --git a/akvo/iati/elements/sustainability.py b/akvo/iati/elements/sustainability.py deleted file mode 100644 index c19caaa3c9..0000000000 --- a/akvo/iati/elements/sustainability.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 sustainability(project): - """ - Generate the sustainability element, a description element with type "1" and akvo type "10". - - :param project: Project object - :return: A list of Etree elements - """ - if project.sustainability: - element = etree.Element("description") - element.attrib['type'] = '1' - element.attrib['{http://akvo.org/iati-activities}type'] = '10' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.sustainability - return [element] - - return [] diff --git a/akvo/iati/elements/target_group.py b/akvo/iati/elements/target_group.py deleted file mode 100644 index 9f7438a90a..0000000000 --- a/akvo/iati/elements/target_group.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 target_group(project): - """ - Generate the target group element, a description element with type "3" and akvo type "3". - - :param project: Project object - :return: A list of Etree elements - """ - if project.target_group: - element = etree.Element("description") - element.attrib['type'] = '3' - element.attrib['{http://akvo.org/iati-activities}type'] = '3' - - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.target_group - return [element] - - return [] diff --git a/akvo/iati/elements/title.py b/akvo/iati/elements/title.py deleted file mode 100644 index 18b90ed5e0..0000000000 --- a/akvo/iati/elements/title.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- 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 title(project): - """ - Generate the title element. - - :param project: Project object - :return: A list of Etree elements - """ - if project.title: - element = etree.Element("title") - narrative_element = etree.SubElement(element, "narrative") - narrative_element.text = project.title - return [element] - - return [] diff --git a/akvo/iati/elements/transaction.py b/akvo/iati/elements/transaction.py deleted file mode 100644 index b935d07587..0000000000 --- a/akvo/iati/elements/transaction.py +++ /dev/null @@ -1,161 +0,0 @@ -# -*- 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 _provider_organisation(element, trans): - """ - Helper function for transaction() - """ - org = trans.provider_organisation - provider_org_element = etree.SubElement(element, "provider-org") - - if trans.provider_organisation_activity: - provider_org_element.attrib['provider-activity-id'] = trans.provider_organisation_activity - - if org.iati_org_id: - provider_org_element.attrib['ref'] = org.iati_org_id - - if org.long_name: - narrative_element = etree.SubElement(provider_org_element, "narrative") - narrative_element.text = org.long_name - elif org.name: - narrative_element = etree.SubElement(provider_org_element, "narrative") - narrative_element.text = org.name - - return element - - -def _receiver_organisation(element, trans): - """ - Helper function for transaction() - """ - org = trans.receiver_organisation - receiver_org_element = etree.SubElement(element, "receiver-org") - - if trans.receiver_organisation_activity: - receiver_org_element.attrib['receiver-activity-id'] = trans.receiver_organisation_activity - - if org.iati_org_id: - receiver_org_element.attrib['ref'] = org.iati_org_id - - if org.long_name: - narrative_element = etree.SubElement(receiver_org_element, "narrative") - narrative_element.text = org.long_name - elif org.name: - narrative_element = etree.SubElement(receiver_org_element, "narrative") - narrative_element.text = org.name - - return element - - -def _sector(element, sector): - """ - Helper function for transaction() - """ - if sector.code: - sector_element = etree.SubElement(element, "sector") - sector_element.attrib['code'] = sector.code - - if not sector.vocabulary or sector.vocabulary == 'DAC': - sector_element.attrib['vocabulary'] = '1' - elif sector.vocabulary == 'DAC-3': - sector_element.attrib['vocabulary'] = '2' - else: - sector_element.attrib['vocabulary'] = sector.vocabulary - - if sector.percentage: - sector_element.attrib['percentage'] = str(sector.percentage) - - if sector.text: - sector_element.text = sector.text - - return element - - -def transaction(project): - """ - Generate the transaction elements. - - :param project: Project object - :return: A list of Etree elements - """ - - transaction_elements = [] - - for trans in project.transactions.all(): - element = etree.Element("transaction") - - if trans.reference: - element.attrib['ref'] = trans.reference - - if trans.transaction_type: - type_element = etree.SubElement(element, "transaction-type") - type_element.attrib['code'] = trans.transaction_type - - if trans.transaction_date: - date_element = etree.SubElement(element, "transaction-date") - date_element.attrib['iso-date'] = str(trans.transaction_date) - - if trans.value: - value_element = etree.SubElement(element, "value") - value_element.text = str(trans.value) - - if trans.currency: - value_element.attrib['currency'] = trans.currency - - if trans.value_date: - value_element.attrib['value-date'] = str(trans.value_date) - - if trans.description: - description_element = etree.SubElement(element, "description") - narrative_element = etree.SubElement(description_element, "narrative") - narrative_element.text = trans.description - - if trans.provider_organisation: - element = _provider_organisation(element, trans) - - if trans.receiver_organisation: - element = _receiver_organisation(element, trans) - - if trans.disbursement_channel: - disbursement_channel_element = etree.SubElement(element, "disbursement-channel") - disbursement_channel_element.attrib['code'] = trans.disbursement_channel - - for sector in trans.sectors.all(): - element = _sector(element, sector) - - if trans.recipient_country: - recipient_country_element = etree.SubElement(element, "recipient-country") - recipient_country_element.attrib['code'] = trans.recipient_country - - if trans.recipient_region: - recipient_region_element = etree.SubElement(element, "recipient-region") - recipient_region_element.attrib['code'] = trans.recipient_region - - if trans.recipient_region_vocabulary: - recipient_region_element.attrib['vocabulary'] = trans.recipient_region_vocabulary - - if trans.flow_type: - flow_type_element = etree.SubElement(element, "flow-type") - flow_type_element.attrib['code'] = trans.flow_type - - if trans.finance_type: - finance_type_element = etree.SubElement(element, "finance-type") - finance_type_element.attrib['code'] = trans.finance_type - - if trans.aid_type: - aid_type_element = etree.SubElement(element, "aid-type") - aid_type_element.attrib['code'] = trans.aid_type - - if trans.tied_status: - tied_status_element = etree.SubElement(element, "tied-status") - tied_status_element.attrib['code'] = trans.tied_status - - transaction_elements.append(element) - - return transaction_elements diff --git a/akvo/iati/exports/__init__.py b/akvo/iati/exports/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/akvo/iati/iati_export.py b/akvo/iati/exports/iati_export.py similarity index 99% rename from akvo/iati/iati_export.py rename to akvo/iati/exports/iati_export.py index d8bece4c18..4558a96f5c 100644 --- a/akvo/iati/iati_export.py +++ b/akvo/iati/exports/iati_export.py @@ -8,7 +8,6 @@ import os from datetime import datetime -from io import BytesIO from lxml import etree ELEMENTS = [ diff --git a/akvo/iati/imports/__init__.py b/akvo/iati/imports/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/akvo/iati/iati_import.py b/akvo/iati/imports/iati_import.py similarity index 97% rename from akvo/iati/iati_import.py rename to akvo/iati/imports/iati_import.py index ae3b1344b9..212f46edc6 100644 --- a/akvo/iati/iati_import.py +++ b/akvo/iati/imports/iati_import.py @@ -4,7 +4,7 @@ # 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 ..rsr.models.iati_import_log import IatiImportLog +from ...rsr.models.iati_import_log import IatiImportLog from django.core.files import File from django.core.files.temp import NamedTemporaryFile @@ -125,7 +125,8 @@ def __init__(self, iati_import): # Start import process self.set_status(3) self.activities = self.get_activities() + self.globals = self.activities.items() # Import process complete - self.set_end_date() self.set_status(4) + self.set_end_date() diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py index 70a7a9aaa8..0591693638 100644 --- a/akvo/rsr/models/project.py +++ b/akvo/rsr/models/project.py @@ -29,7 +29,7 @@ BUDGET_IDENTIFIER_VOCABULARY) from akvo.utils import codelist_choices, codelist_value, rsr_image_path, rsr_show_keywords -from ...iati.mandatory_fields import check_export_fields +from ...iati.checks.mandatory_fields import check_export_fields from ..fields import ProjectLimitedTextField, ValidXMLCharField, ValidXMLTextField from ..mixins import TimestampsMixin diff --git a/akvo/rsr/signals.py b/akvo/rsr/signals.py index 12c49b6e11..32785f7755 100644 --- a/akvo/rsr/signals.py +++ b/akvo/rsr/signals.py @@ -23,8 +23,8 @@ from sorl.thumbnail import ImageField from akvo.utils import send_donation_confirmation_emails, rsr_send_mail, rsr_send_mail_to_users -from akvo.iati.iati_export import IatiXML -from akvo.iati.iati_import import IatiImportProcess +from akvo.iati.exports.iati_export import IatiXML +from akvo.iati.imports.iati_import import IatiImportProcess def create_publishing_status(sender, **kwargs): diff --git a/akvo/rsr/views/project.py b/akvo/rsr/views/project.py index d70b95a434..de659f3900 100644 --- a/akvo/rsr/views/project.py +++ b/akvo/rsr/views/project.py @@ -20,7 +20,7 @@ from ..filters import remove_empty_querydict_items, ProjectFilter from ..models import Invoice, Project, ProjectUpdate, Organisation from ...utils import pagination, filter_query_string -from ...iati.iati_export import IatiXML +from ...iati.exports.iati_export import IatiXML from .utils import apply_keywords, org_projects