Skip to content

Commit

Permalink
Merge pull request #2240 from akvo/#2189-new-iati-status-mapping
Browse files Browse the repository at this point in the history
[#2189] New IATI status mapping
  • Loading branch information
damienallen committed Jun 8, 2016
2 parents abb425f + 02405e4 commit 869d937
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 47 deletions.
9 changes: 0 additions & 9 deletions akvo/iati/exports/elements/activity_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

from lxml import etree

STATUS_TO_CODE = {
'N': '0',
'H': '1',
'A': '2',
'C': '3',
'L': '5',
'R': '6',
}


def activity_status(project):
"""
Expand Down
12 changes: 1 addition & 11 deletions akvo/iati/imports/mappers/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@
# 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 akvo.rsr.models.project import Project
from akvo.rsr.models.project_condition import ProjectCondition

from .. import ImportMapper, xml_ns

CODE_TO_STATUS = {
'1': 'H',
'2': 'A',
'3': 'C',
'4': 'C',
'5': 'L',
'6': 'R'
}


class Language(ImportMapper):

Expand Down Expand Up @@ -183,7 +173,7 @@ def do_import(self):

if not iati_status:
self.add_log('activity-status@code', 'iati_status', 'invalid status code')
iati_status = '0'
iati_status = ''

return self.update_project_field('iati_status', iati_status)

Expand Down
3 changes: 1 addition & 2 deletions akvo/rsr/migrations/0075_auto_20160525_1006.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
class Migration(migrations.Migration):

dependencies = [
# ('rsr', '0070_auto_20160519_1205'),
('rsr', '0074_auto_20160526_0938'),
]

operations = [
migrations.AddField(
model_name='project',
name='iati_status',
field=akvo.rsr.fields.ValidXMLCharField(default=b'0', choices=[('0', ''), ('1', '1 - Pipeline/identification'), ('2', '2 - Implementation'), ('3', '3 - Completion'), ('4', '4 - Post-completion'), ('5', '5 - Cancelled'), ('6', '6 - Suspended')], max_length=1, help_text='There are six different project statuses:<br/>1) Pipeline/identification: the project is being scoped or planned<br/>2) Implementation: the project is currently being implemented<br/>3) Completion: the project is complete or the final disbursement has been made<br/>4) Post-completion: the project is complete or the final disbursement has been made, but the project remains open pending financial sign off or M&E<br/>5) Cancelled: the project has been cancelled<br/>6) Suspended: the project has been temporarily suspended or the reporting partner no longer uses RSR.', verbose_name='status', db_index=True),
field=akvo.rsr.fields.ValidXMLCharField(blank=True, choices=[('1', '1 - Pipeline/identification'), ('2', '2 - Implementation'), ('3', '3 - Completion'), ('4', '4 - Post-completion'), ('5', '5 - Cancelled'), ('6', '6 - Suspended')], max_length=1, help_text='There are six different project statuses:<br/>1) Pipeline/identification: the project is being scoped or planned<br/>2) Implementation: the project is currently being implemented<br/>3) Completion: the project is complete or the final disbursement has been made<br/>4) Post-completion: the project is complete or the final disbursement has been made, but the project remains open pending financial sign off or M&E<br/>5) Cancelled: the project has been cancelled<br/>6) Suspended: the project has been temporarily suspended or the reporting partner no longer uses RSR.', verbose_name='status', db_index=True),
preserve_default=True,
),
]
101 changes: 89 additions & 12 deletions akvo/rsr/migrations/0076_auto_20160525_1008.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,99 @@
from django.db import models, migrations


# convert old rsr statuses to equivalent iati status codes
# # see http://iatistandard.org/202/codelists/ActivityStatus/
# Convert old rsr statuses to equivalent iati status codes
# See http://iatistandard.org/202/codelists/ActivityStatus/
STATUS_TO_CODE = {
'N': '0',
'N': '',
'H': '1',
'A': '2',
'C': '3',
'L': '5',
'R': '6',
'R': '3'
}

# update new field with existing values
# Some 'Archived' projects should be mapped to either 'None' or 'Cancelled'.
# Otherwise, 'Archived' projects use the regular mapping (to 'Completion').
SPECIAL_ARCHIVED_MAPPING = {
18: '5',
31: '',
33: '',
34: '',
35: '',
37: '',
44: '5',
45: '5',
52: '5',
66: '',
81: '5',
83: '5',
84: '5',
85: '5',
86: '5',
87: '5',
88: '5',
89: '5',
90: '5',
91: '5',
92: '5',
93: '5',
95: '5',
96: '5',
97: '5',
98: '5',
99: '5',
100: '5',
103: '5',
109: '5',
110: '5',
111: '5',
114: '5',
117: '5',
118: '5',
119: '',
122: '5',
123: '5',
124: '5',
125: '5',
126: '5',
127: '5',
132: '',
144: '5',
156: '',
159: '',
160: '',
173: '',
176: '',
177: '5',
200: '5',
234: '',
271: '5',
279: '',
280: '',
281: '',
283: '',
455: '',
308: '',
309: '',
1010: '',
}


def populate_iati_status(apps, schema_editor):
"""
Update new field with existing values. If a project is mentioned in the special mapping and
this project has the status 'Archived' (this is a double-check), then use the special mapping.
Otherwise, the regular mapping of STATUS_TO_CODE is applied.
"""
Project = apps.get_model('rsr', 'Project')
for p in Project.objects.all():
p.iati_status = STATUS_TO_CODE[p.status]
p.save()
if p.id in SPECIAL_ARCHIVED_MAPPING.keys() and p.status == 'R':
p.iati_status = SPECIAL_ARCHIVED_MAPPING[p.id]
p.save()
else:
p.iati_status = STATUS_TO_CODE[p.status]
p.save()


class Migration(migrations.Migration):
Expand All @@ -31,9 +107,10 @@ class Migration(migrations.Migration):

operations = [
migrations.RunPython(populate_iati_status, populate_iati_status),
migrations.RunSQL("UPDATE rsr_projecteditorvalidation SET validation = 'rsr_project.iati_status' "
"WHERE validation = 'rsr_project.status';",
"UPDATE rsr_projecteditorvalidation SET validation = 'rsr_project.status' "
"WHERE validation = 'rsr_project.iati_status';"
)
migrations.RunSQL(
"UPDATE rsr_projecteditorvalidation SET validation = 'rsr_project.iati_status' "
"WHERE validation = 'rsr_project.status';",
"UPDATE rsr_projecteditorvalidation SET validation = 'rsr_project.status' "
"WHERE validation = 'rsr_project.iati_status';"
)
]
45 changes: 45 additions & 0 deletions akvo/rsr/migrations/0077_auto_20160608_1227.py

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions akvo/rsr/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Project(TimestampsMixin, models.Model):
)

STATUSES_COLORS = {
'0': 'grey',
'': 'grey',
'1': 'orange',
'2': '#AFF167',
'3': 'grey',
Expand All @@ -105,40 +105,44 @@ class Project(TimestampsMixin, models.Model):
}

CODE_TO_STATUS = {
'0': 'N',
'': 'N',
'1': 'H',
'2': 'A',
'3': 'C',
'4': 'C',
'5': 'L',
'6': 'R'
'6': 'C'
}

STATUS_TO_CODE = {
'N': '0',
'N': '',
'H': '1',
'A': '2',
'C': '3',
'L': '5',
'R': '6'
'R': '3'
}

# Status combinations used in conditionals
EDIT_DISABLED = ['3', '5']
DONATE_DISABLED = ['0', '3', '4', '5', '6']
NOT_SUSPENDED = ['1', '2', '3', '4', '5']
DONATE_DISABLED = ['', '3', '4', '5', '6']
NOT_SUSPENDED = ['', '1', '2', '3', '4', '5']

title = ValidXMLCharField(_(u'project title'), max_length=200, db_index=True, blank=True)
subtitle = ValidXMLCharField(_(u'project subtitle'), max_length=200, blank=True)
status = ValidXMLCharField(_(u'status'), max_length=1, choices=STATUSES, db_index=True, default=STATUS_NONE)
status = ValidXMLCharField(
_(u'status'), max_length=1, choices=STATUSES, db_index=True, default=STATUS_NONE
)
iati_status = ValidXMLCharField(
_(u'status'), max_length=1, choices=([('0', '')] + codelist_choices(ACTIVITY_STATUS)),
db_index=True, default='0',
_(u'status'), max_length=1, choices=(codelist_choices(ACTIVITY_STATUS)), db_index=True,
blank=True,
help_text=_(u'There are six different project statuses:<br/>'
u'1) Pipeline/identification: the project is being scoped or planned<br/>'
u'2) Implementation: the project is currently being implemented<br/>'
u'3) Completion: the project is complete or the final disbursement has been made<br/>'
u'4) Post-completion: the project is complete or the final disbursement has been made, '
u'3) Completion: the project is complete or the final disbursement has been '
u'made<br/>'
u'4) Post-completion: the project is complete or the final disbursement has '
u'been made, '
u'but the project remains open pending financial sign off or M&E<br/>'
u'5) Cancelled: the project has been cancelled<br/>'
u'6) Suspended: the project has been temporarily suspended '
Expand Down
2 changes: 1 addition & 1 deletion akvo/templates/myrsr/project_editor/section_1.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h5>{% trans 'Related projects' %}</h5>
</div>

{% include choice_input with obj=project field="hierarchy" %}
{% include choice_input with obj=project field="iati_status" not_empty=True %}
{% include choice_input with obj=project field="iati_status" %}

<div class="row">
<div class="col-md-6">
Expand Down

0 comments on commit 869d937

Please sign in to comment.