Skip to content

Commit

Permalink
[#1351] Add IATI export checks
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Mar 27, 2015
1 parent 2465d88 commit 67b5afc
Show file tree
Hide file tree
Showing 18 changed files with 1,125 additions and 931 deletions.
11 changes: 11 additions & 0 deletions akvo/iati/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
]
747 changes: 747 additions & 0 deletions akvo/iati/checks/v201.py

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions akvo/iati/elements/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ def budget(project):
budget_elements = []

for budget_item in project.budget_items.all():
if budget_item.amount:
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

if budget_item.period_start:
period_start_element = etree.SubElement(element, "period-start")
period_start_element.attrib['iso-date'] = str(budget_item.period_start)
period_start_element = etree.SubElement(element, "period-start")
period_start_element.attrib['iso-date'] = str(budget_item.period_start)

if budget_item.period_end:
period_end_element = etree.SubElement(element, "period-end")
period_end_element.attrib['iso-date'] = str(budget_item.period_end)
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)
Expand Down
9 changes: 4 additions & 5 deletions akvo/iati/elements/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ def conditions(project):
:param project: Project object
:return: A list of Etree elements
"""
conditions_element = etree.Element("conditions")

if project.conditions.all():
conditions_element = etree.Element("conditions")
conditions_element.attrib['attached'] = '1'
else:
return []

if project.conditions_attached is not None:
conditions_element.attrib['attached'] = '1' if project.conditions_attached else '0'
conditions_element.attrib['attached'] = '0'

for condition in project.conditions.all():
if condition.type:
Expand Down
15 changes: 8 additions & 7 deletions akvo/iati/elements/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ def location(project):
narrative_element = etree.SubElement(activity_description_element, "narrative")
narrative_element.text = loc.activity_description

if loc.administrative_code and loc.administrative_vocabulary:
administrative_element = etree.SubElement(element, "administrative")
administrative_element.attrib['vocabulary'] = loc.administrative_vocabulary
administrative_element.attrib['code'] = loc.administrative_code

if loc.administrative_level:
administrative_element.attrib['level'] = str(loc.administrative_code)
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")
Expand Down
9 changes: 8 additions & 1 deletion akvo/iati/elements/sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ def sector(project):
element = etree.Element("sector")
element.attrib['code'] = sec.sector_code

if sec.vocabulary:
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)

if sec.text:
element.text = sec.text

sector_elements.append(element)

return sector_elements
32 changes: 17 additions & 15 deletions akvo/iati/elements/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,23 @@ def transaction(project):
disbursement_channel_element = etree.SubElement(element, "disbursement-channel")
disbursement_channel_element.attrib['code'] = trans.disbursement_channel

if trans.sector:
sector_element = etree.SubElement(element, "sector")
sector_element.attrib['code'] = trans.sector
sector_element.attrib['vocabulary'] = '1'

if trans.sector_category:
sector_category_element = etree.SubElement(element, "sector")
sector_category_element.attrib['code'] = trans.sector_category
sector_category_element.attrib['vocabulary'] = '2'

if trans.sector_other:
sector_other_element = etree.SubElement(element, "sector")
sector_other_element.attrib['vocabulary'] = '99'
narrative_element = etree.SubElement(sector_other_element, "narrative")
narrative_element.text = trans.sector_other
for sector in trans.sectors.all():
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

if trans.recipient_country:
recipient_country_element = etree.SubElement(element, "recipient-country")
Expand Down
20 changes: 20 additions & 0 deletions akvo/iati/mandatory_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- 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 >.

import checks


def check_export_fields(project, version='2.01'):
"""
:param project: Project object
:param version: String of IATI version
:return: List of checks
"""
# TODO: Add check for IATI versions (generic)
version_file = "V%sChecks" % version.replace('.', '')
project_checks = getattr(checks, version_file)(project)
project_checks.execute_all_checks()
return project_checks.all_checks_passed, project_checks.checks_results
41 changes: 24 additions & 17 deletions akvo/rsr/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,7 @@ class BudgetItemAdminInLine(NestedTabularInline):
model = get_model('rsr', 'budgetitem')
extra = 1
formset = BudgetItemAdminInLineFormSet
fieldsets = (
(None, {
'fields': ('label', 'other_extra', 'type', 'amount', 'period_start', 'period_end', 'value_date')
}),
('IATI fields (advanced)', {
'classes': ('collapse',),
'fields': ('period_start_text', 'period_end_text', )
})
)
fields = ('label', 'other_extra', 'type', 'amount', 'period_start', 'period_end', 'value_date')

def get_extra(self, request, obj=None, **kwargs):
if obj:
Expand Down Expand Up @@ -319,17 +311,24 @@ def get_extra(self, request, obj=None, **kwargs):
return 1


class LocationAdministrativeInline(NestedTabularInline):
model = get_model('rsr', 'administrativelocation')
fields = ('code', 'vocabulary', 'level')
extra = 0


class ProjectLocationInline(NestedStackedInline):
model = get_model('rsr', 'projectlocation')
inlines = (LocationAdministrativeInline,)
fieldsets = (
(None, {
'fields': ('latitude', 'longitude', 'country', 'city', 'state', 'address_1', 'address_2', 'postcode')
'fields': ('latitude', 'longitude', 'country', 'city', 'state', 'address_1',
'address_2', 'postcode')
}),
('IATI fields (advanced)', {
'classes': ('collapse',),
'fields': ('reference', 'location_code', 'name', 'description', 'activity_description',
'administrative_code', 'administrative_vocabulary', 'administrative_level', 'exactness',
'location_reach', 'location_class', 'feature_designation')
'exactness', 'location_reach', 'location_class', 'feature_designation')
}),
)

Expand Down Expand Up @@ -488,18 +487,26 @@ def get_extra(self, request, obj=None, **kwargs):
return 1


class TransactionSectorInline(NestedTabularInline):
model = get_model('rsr', 'TransactionSector')
fields = ('code', 'vocabulary', 'text')
extra = 0


class TransactionInline(NestedStackedInline):
model = get_model('rsr', 'Transaction')
inlines = (TransactionSectorInline, )
fieldsets = (
(None, {
'fields': ('reference', 'transaction_type', 'value', 'transaction_date', 'description')
}),
('IATI fields (advanced)', {
'classes': ('collapse',),
'fields': ('currency', 'value_date', 'provider_organisation', 'provider_organisation_activity',
'receiver_organisation', 'receiver_organisation_activity', 'aid_type', 'disbursement_channel',
'finance_type', 'flow_type', 'tied_status', 'recipient_country', 'recipient_region',
'recipient_region_vocabulary', 'sector', 'sector_category', 'sector_other')
'fields': ('currency', 'value_date', 'provider_organisation',
'provider_organisation_activity', 'receiver_organisation',
'receiver_organisation_activity', 'aid_type', 'disbursement_channel',
'finance_type', 'flow_type', 'tied_status', 'recipient_country',
'recipient_region', 'recipient_region_vocabulary')
}),
)

Expand Down Expand Up @@ -676,7 +683,7 @@ class ProjectAdmin(TimestampsAdminDisplayMixin, ObjectPermissionsModelAdmin, Nes
'description': u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">%s</p>' % _(
u'Optionally, you can add additional information based on the IATI standard.'
),
'fields': ('conditions_attached',),
'fields': (),
}),
(_(u'Keywords'), {
'description': u'<p style="margin-left:0; padding-left:0; margin-top:1em; width:75%%;">%s</p>' % _(
Expand Down
Loading

0 comments on commit 67b5afc

Please sign in to comment.