Skip to content

Commit

Permalink
Merge pull request #2070 from akvo/#2011-results-improve
Browse files Browse the repository at this point in the history
[#2011] Improve the results framework
  • Loading branch information
KasperBrandt committed Mar 31, 2016
2 parents a92cc92 + 3171d17 commit 276100a
Show file tree
Hide file tree
Showing 22 changed files with 2,250 additions and 1,169 deletions.
4 changes: 4 additions & 0 deletions akvo/rest/serializers/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ResultSerializer(BaseRSRSerializer):

project_title = serializers.Field(source='project.title')
type_label = serializers.Field(source='iati_type')
parent_project = serializers.Field(source='parent_project')
child_projects = serializers.Field(source='child_projects')

class Meta:
model = Result
Expand All @@ -24,6 +26,8 @@ class ResultsFrameworkSerializer(BaseRSRSerializer):

indicators = IndicatorFrameworkSerializer(many=True, required=False, allow_add_remove=True)
project_title = serializers.Field(source='project.title')
parent_project = serializers.Field(source='parent_project')
child_projects = serializers.Field(source='child_projects')

class Meta:
model = Result
17 changes: 17 additions & 0 deletions akvo/rsr/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ def has_info(self):
def is_calculated(self):
return self.project.is_impact_project

def parent_project(self):
"""
Return a dictionary of this result's parent project.
"""
if self.parent_result:
return {self.parent_result.project.id: self.parent_result.project.title}
return {}

def child_projects(self):
"""
Return a dictionary of this result's child projects.
"""
projects = {}
for result in Result.objects.filter(parent_result=self):
projects[result.project.id] = result.project.title
return projects

class Meta:
app_label = 'rsr'
verbose_name = _(u'result')
Expand Down
Loading

0 comments on commit 276100a

Please sign in to comment.