Repository: akvo/akvo-rsr

Issue:
Move to IATI statuses
This is probably a bigger issue than we expect, but we should replace the current project.status with the IATI entries. A mapping will be done like this:

```
STATUS_TO_CODE = {
    'N': '6',
    'H': '1',
    'A': '2',
    'C': '3',
    'L': '5',
    'R': '6',
}
```
- [x] Convert status codes
- [x] Update IATI import / export
- [x] Update project editor
- [x] Update project page and project entry in projects list
- [x] Cancelled and completed projects can't be updated (see https://github.com/akvo/akvo-rsr/issues/2006#issuecomment-218499657)
- [x] Check where else in RSR the project's status is used



Discussion:
Report templates (project overview) will need to be updated to use IATI codes:

`STATUS_NONE = '6'`
`STATUS_NEEDS_FUNDING = '1'`
`STATUS_ACTIVE = '2'`
`STATUS_COMPLETE = '3'`
`STATUS_POST_COMPLETE = '4'`
`STATUS_CANCELLED = '5'`
`STATUS_ARCHIVED = '6'`

API calls with filter `?status=X` will need to be updated as well. Maybe this is something used in Up?

@Geerts @stellanl 

After a short discussion this morning, @damienallen and I decided to keep the current `project.status` field as is for legacy reasons (e.g. API, ReportServer, etc) and create a new field `project.iati_status` which stores the IATI statuses.

### Test plan (WIP)

IATI import/export:
- [x] Make sure both `project.iati_status` and `project.status` are set correctly for imports and exports
- [x] Make sure invalid codes are handled correctly (set to status 0) on import

Organisation page:
- [x] Check that project status labels and counts are correct
- [x] Check whether the counts link to appropriate filters
- [x] Confirm that sizing/styling of labels is correct

Project list:
- [x] Check status labels and coloring
- [x] Check that both `?status=` and `?iati_status=` filters work correctly

Project page:
- [x] Check status labels and coloring
- [x] Check whether the donate button is disabled for suspended, cancelled and completed projects

Project editor:
- [x] New projects should be created with 'None' iati status (status 0, blank in editor)
- [x] Status field should be replaced by IATI Status field
- [x] Editor progress bar should only progress if status is selected
- [x] Help text should be proofread

Widgets:
- [x] Check whether the new IATI statuses are displayed
- [x] Check whether the widgets are formatted correctly (especially for status 1)

Legacy support:
- [x] Try updating `project.status` and make sure changes also reflect in `project.iati_status`
- [x] Unit tests for existing calls to API referencing project status
- [x] Make sure status is still correctly handled by report server

Management:
- [x] Make sure migrations work correctly: `project.status` copied to `project.iati_status` with appropriate codes and `project.iati_status` set as mandatory in `rsr_projecteditorvalidation`
- [x] Make sure `funds_needed` management command still marks projects as complete

Small layout issue, the actions in the My projects list are not on one row anymore (probably due to the pipeline/identification status):

<img width="1136" alt="screen shot 2016-06-01 at 12 25 00" src="https://cloud.githubusercontent.com/assets/1497367/15706470/094027ea-27f4-11e6-85e9-d21abc9d24e2.png">

Just discussed with Marten and Mark;
- [x] Add 'No status' as default with empty string as code
- [x] New mapping of statuses:

Map None -> No status
Map Archived - > No status, Completed or Cancelled (check [this list](https://docs.google.com/spreadsheets/d/1PWkJxrmFYvJvZMwPjEALqxQlW4ae6-8xNnTEvz0cXvY/edit#gid=0) for an overview of archived projects and their new status).

## Test plan (2)
1. Re-migrate 0075 and 0076 (backwards and forwards);
2. Check that the status can be empty in the project editor, and that it is stored in the DB as an empty string;
3. Check that 'Archived' projects in general are now mapped to 'Completion';
4. On Test/UAT: Check [this list](https://docs.google.com/spreadsheets/d/1PWkJxrmFYvJvZMwPjEALqxQlW4ae6-8xNnTEvz0cXvY/edit#gid=0) for an overview of archived projects and their new status.


Resolving patch:
diff --git a/akvo/rsr/filters.py b/akvo/rsr/filters.py
--- a/akvo/rsr/filters.py
+++ b/akvo/rsr/filters.py
@@ -152,8 +152,8 @@ class ProjectFilter(django_filters.FilterSet):
 
     iati_status = django_filters.ChoiceFilter(
         initial=_('All'),
-        label=_(u'iati status'),
-        choices=([('', _('All'))] + codelist_choices(ACTIVITY_STATUS)))
+        label=_(u'status'),
+        choices=([('', _('All'))] + codelist_choices(ACTIVITY_STATUS, False)))
 
     title = django_filters.CharFilter(
         lookup_type='icontains',
@@ -167,7 +167,7 @@ class ProjectFilter(django_filters.FilterSet):
 
     class Meta:
         model = Project
-        fields = ['status', 'location', 'organisation', 'category',
+        fields = ['status', 'iati_status', 'location', 'organisation', 'category',
                   'sector', 'title', ]
 
 
diff --git a/akvo/utils.py b/akvo/utils.py
--- a/akvo/utils.py
+++ b/akvo/utils.py
@@ -487,11 +487,12 @@ def filter_query_string(qs):
         u'&'.join([u'{}={}'.format(k, u''.join(v)) for (k, v) in q.items()])).encode('utf-8')
 
 
-def codelist_choices(codelist):
+def codelist_choices(codelist, show_code=True):
     """
     Based on a model from the codelists app, returns a list of tuples with the available choices.
 
     :param codelist: Codelist from codelists store
+    :param show_code: Show the code (e.g. '1 - ..') in front of the name, True by default
     :return: List of tuples with available choices, tuples in the form of (code, name)
     """
     name_index = 0
@@ -500,7 +501,7 @@ def codelist_choices(codelist):
             name_index = index
             break
 
-    if name_index > 0:
+    if name_index > 0 and show_code:
         return [(cl[0], '%s - %s' % (cl[0], cl[name_index])) for cl in codelist[1:]]
     else:
         return [(cl[0], cl[name_index]) for cl in codelist[1:]]


Test patch: