Skip to content

Commit

Permalink
[#1494] Merged 'develop' into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Oct 9, 2015
2 parents be2a6a3 + 05f3698 commit 2dc552d
Show file tree
Hide file tree
Showing 275 changed files with 35,379 additions and 2,227 deletions.
5 changes: 4 additions & 1 deletion akvo/api/resources/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def dehydrate(self, bundle):
""" add thumbnails inline info for Project.current_image
"""
bundle = super(ProjectMapResource, self).dehydrate(bundle)
ignored_fields = ('goals_overview', 'current_status', 'project_plan', 'sustainability', 'background', 'project_rating', 'notes',)
ignored_fields = (
'goals_overview', 'current_status', 'project_plan', 'sustainability', 'background',
'notes',
)
for field in ignored_fields:
del bundle.data[field]
bundle.data['current_image'] = {
Expand Down
52 changes: 43 additions & 9 deletions akvo/api/resources/partnership.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
FIELD_NAME = 'name'
FIELD_LONG_NAME = 'long_name'
FIELD_NEW_ORGANISATION_TYPE = 'new_organisation_type'
FIELD_PARTNER_TYPE = 'partner_type'
FIELD_PARTNER_TYPE = 'iati_organisation_role'
ORG_FIELDS = [FIELD_IATI_ORG_ID, FIELD_NAME, FIELD_LONG_NAME, FIELD_NEW_ORGANISATION_TYPE]
# InternalOrganisationID
FIELD_INTERNAL_ORG_ID = 'internal_org_id'
Expand Down Expand Up @@ -173,7 +173,7 @@ def hydrate(self, bundle):
bundle.data[FIELD_ORGANISATION] = organisation
if (
organisation.iati_org_id != bundle.data[FIELD_REPORTING_ORG] or
bundle.data[FIELD_PARTNER_TYPE] != Partnership.SUPPORT_PARTNER
bundle.data[FIELD_PARTNER_TYPE] != Partnership.IATI_ACCOUNTABLE_PARTNER
):
bundle.data[FIELD_IATI_ACTIVITY_ID] = None
bundle.data[FIELD_INTERNAL_ID] = None
Expand All @@ -197,15 +197,48 @@ def hydrate_organisation(self, bundle):
class PartnershipResource(ConditionalFullResource):
organisation = ConditionalFullToOneField('akvo.api.resources.OrganisationResource', 'organisation')
project = ConditionalFullToOneField('akvo.api.resources.ProjectResource', 'project')
partner_type = fields.CharField(attribute='iati_role_to_partner_type')

def __init__(self, api_name=None):
""" override to be able to create custom help_text on the partner_type field
"""
super(PartnershipResource, self).__init__(api_name=None)
self.fields['partner_type'].help_text = "Uses the following key-value pair list: {%s}" % ', '.join(
['"%s": "%s"' % (k, v) for k, v in Partnership.PARTNER_TYPES]
self.fields[
'iati_organisation_role'].help_text = "Uses the following key-value pair list: {%s}" % ', '.join(
['"%s": "%s"' % (k, v) for k, v in Partnership.IATI_ROLES]
)

def apply_filters(self, request, applicable_filters):
""" Custom filtering for the "fake" field partner_type allowing the filtering of the
resource using the deprecated Akvo partner type values
Uses Partnership.PARTNER_TYPES_TO_ROLES_MAP map the filter to the
Partnership.iati_organisation_role field
"""

partner_type_filter = {}
if 'iati_role_to_partner_type' in [k.split('__')[0] for k in applicable_filters.keys()]:
for k in applicable_filters.keys():
if k.startswith('iati_role_to_partner_type'):
operator = k.split('__')[1]
if operator == 'in':
values = [
Partnership.PARTNER_TYPES_TO_ROLES_MAP[v] for v in applicable_filters[k]
]
partner_type_filter['iati_organisation_role__in'] = values
else:
partner_type_filter[
"iati_organisation_role__{}".format(operator)
] = Partnership.PARTNER_TYPES_TO_ROLES_MAP[applicable_filters[k]]
applicable_filters.pop(k)

default_filtering = super(PartnershipResource, self).apply_filters(request, applicable_filters)

if partner_type_filter:
return default_filtering.filter(**partner_type_filter)
else:
return default_filtering

class Meta:
max_limit = 10
allowed_methods = ['get']
Expand All @@ -214,10 +247,11 @@ class Meta:
filtering = dict(organisation=ALL_WITH_RELATIONS)
filtering = dict(
# other fields
iati_activity_id = ALL,
internal_id = ALL,
partner_type = ALL,
iati_activity_id = ALL,
internal_id = ALL,
partner_type = ALL,
iati_organisation_role = ALL,
# foreign keys
organisation = ALL_WITH_RELATIONS,
project = ALL_WITH_RELATIONS,
organisation = ALL_WITH_RELATIONS,
project = ALL_WITH_RELATIONS,
)
2 changes: 1 addition & 1 deletion akvo/api/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def alter_deserialized_detail_data(self, request, data):
reporting_org=temp_org['reporting_org'],
name='Incorrect business unit', #this should never be used, if it is the lookup of existing BUs is borked
long_name='Incorrect business unit',
partner_type='sponsor',
iati_organisation_role=100, # old partner type sponsor partner
new_organisation_type='21',
organisation=None,
)]
Expand Down
11 changes: 4 additions & 7 deletions akvo/api/xml/iati-xslt.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@
<xsl:value-of select="." />
</target_group>
</xsl:template>


<!-- project_rating Currently not used-->

<!-- notes Currently not used -->

Expand Down Expand Up @@ -527,16 +524,16 @@
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@role='Accountable'">
<partner_type>support</partner_type>
<iati_organisation_role>2</iati_organisation_role>
</xsl:if>
<xsl:if test="@role='Extending'">
<partner_type>support</partner_type>
<iati_organisation_role>3</iati_organisation_role>
</xsl:if>
<xsl:if test="@role='Funding'">
<partner_type>funding</partner_type>
<iati_organisation_role>1</iati_organisation_role>
</xsl:if>
<xsl:if test="@role='Implementing'">
<partner_type>field</partner_type>
<iati_organisation_role>4</iati_organisation_role>
</xsl:if>
</object>
</xsl:template>
Expand Down
4 changes: 1 addition & 3 deletions akvo/cordaid_org_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.core.files.temp import NamedTemporaryFile

from akvo.codelists.store.codelists_v201 import ORGANISATION_TYPE as IATI_LIST_ORGANISATION_TYPE
from akvo.rsr.models import InternalOrganisationID, Organisation, PartnerType
from akvo.rsr.models import InternalOrganisationID, Organisation
from akvo.utils import model_and_instance_based_filename


Expand Down Expand Up @@ -95,8 +95,6 @@ def import_orgs(xml_file):
identifier=identifier
)
internal_org_id.save()
for partner_type in PartnerType.objects.all():
referenced_org.partner_types.add(partner_type)
except Exception, e:
action = "failed"
internal_org_id.delete()
Expand Down
11 changes: 0 additions & 11 deletions akvo/iati/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
]
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
# 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

from akvo.rsr.models import PartnerType

from .rsr_serializer import BaseRSRSerializer


class PartnerTypeSerializer(BaseRSRSerializer):

class Meta:
model = PartnerType
__all__ = [
'V201Checks',
]
Loading

0 comments on commit 2dc552d

Please sign in to comment.