Repository: akvo/akvo-rsr

Issue:
Sector codes in project editor
- [x] Remove permanent help text for sectors.
- [x] Select DAC-3 and DAC-5 from lists.
- [x] Remove sector mandatory for RSR validation set. Also in publishing status checks.



Discussion:

Resolving patch:
diff --git a/akvo/rsr/migrations/0079_auto_20160620_1418.py b/akvo/rsr/migrations/0079_auto_20160620_1418.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/migrations/0079_auto_20160620_1418.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+def sector_validation(apps, schema_editor):
+    """ Remove sector from RSR validation set """
+    ProjectEditorValidation = apps.get_model('rsr', 'ProjectEditorValidation')
+
+    sector_validators = ['rsr_sector', 'rsr_sector.sector_code', 'rsr_sector.vocabulary']
+
+    for v in sector_validators:
+        validation = ProjectEditorValidation.objects.filter(validation_set_id=1, validation__exact=v)
+        if validation:
+            validation.delete()
+
+def undo_sector_validation(apps, schema_editor):
+    """ Remove sector from RSR validation set """
+    ProjectEditorValidation = apps.get_model('rsr', 'ProjectEditorValidation')
+
+    sector_validators = ['rsr_sector', 'rsr_sector.sector_code', 'rsr_sector.vocabulary']
+
+    for v in sector_validators:
+        ProjectEditorValidation.objects.get_or_create(validation=v, action=1, validation_set_id=1)
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('rsr', '0078_auto_20160613_1428'),
+    ]
+
+    operations = [
+        migrations.RunPython(sector_validation, undo_sector_validation),
+    ]
diff --git a/akvo/rsr/models/publishing_status.py b/akvo/rsr/models/publishing_status.py
--- a/akvo/rsr/models/publishing_status.py
+++ b/akvo/rsr/models/publishing_status.py
@@ -138,20 +138,6 @@ def clean(self):
                     )
                 )
 
-            if not self.project.sectors.all():
-                validation_errors.append(
-                    ValidationError(_('Project needs to have at least one sector.'),
-                                    code='sector')
-                )
-            else:
-                for sector in self.project.sectors.all():
-                    if not (sector.sector_code and sector.vocabulary):
-                        validation_errors.append(
-                            ValidationError(_('All sectors need to have a sector code and '
-                                              'vocabulary.'), code='sector')
-                        )
-                        break
-
             if validation_errors:
                 raise ValidationError(validation_errors)
 
diff --git a/akvo/rsr/views/my_rsr.py b/akvo/rsr/views/my_rsr.py
--- a/akvo/rsr/views/my_rsr.py
+++ b/akvo/rsr/views/my_rsr.py
@@ -19,11 +19,12 @@
 from tastypie.models import ApiKey
 
 from akvo.codelists.models import Country, Version
+from akvo.codelists.store.codelists_v202 import SECTOR_CATEGORY,SECTOR
 
 from ..forms import (PasswordForm, ProfileForm, UserOrganisationForm, UserAvatarForm,
                      SelectOrgForm)
 from ..filters import remove_empty_querydict_items
-from ...utils import codelist_name, pagination, filter_query_string
+from ...utils import codelist_name, codelist_choices, pagination, filter_query_string
 from ..models import (Employment, Organisation, OrganisationCustomField, Project,
                       ProjectEditorValidation, ProjectEditorValidationSet)
 
@@ -282,17 +283,25 @@ def project_editor(request, project_id):
     validation_sets = ProjectEditorValidationSet.objects.all()
     project_validation_sets = project.validations.all()
 
-    # Countries
+    # IATI fields
     countries = Country.objects.filter(version=Version.objects.get(code=settings.IATI_VERSION))
+    dac5_codes = codelist_choices(SECTOR)
+    dac3_codes = codelist_choices(SECTOR_CATEGORY)
 
     context = {
         'id': project_id,
         'project': project,
         'projectmodel': Project,
+
+        # Validation
         'validations': validations,
         'validation_sets': validation_sets,
         'project_validation_sets': project_validation_sets,
+
+        # IATI fields
         'countries': countries,
+        'dac5_codes': dac5_codes,
+        'dac3_codes': dac3_codes,
 
         # Custom fields
         'custom_fields_section_1': custom_fields_section_1,


Test patch: