Repository: akvo/akvo-rsr

Issue:
Add language as required for IATI
Language is required for IATI, so we should update this:
- [x] Add language to IATI checks;
- [x] Add language to IATI (and DGIS) validation sets.



Discussion:

Resolving patch:
diff --git a/akvo/iati/checks/fields/__init__.py b/akvo/iati/checks/fields/__init__.py
--- a/akvo/iati/checks/fields/__init__.py
+++ b/akvo/iati/checks/fields/__init__.py
@@ -15,6 +15,7 @@
 from .fss import fss
 from .humanitarian_scope import humanitarian_scope
 from .iati_identifier import iati_identifier
+from .language import language
 from .legacy_data import legacy_data
 from .locations import locations
 from .partners import partners
@@ -41,6 +42,7 @@
     'fss',
     'humanitarian_scope',
     'iati_identifier',
+    'language',
     'legacy_data',
     'locations',
     'partners',
diff --git a/akvo/iati/checks/fields/language.py b/akvo/iati/checks/fields/language.py
new file mode 100644
--- /dev/null
+++ b/akvo/iati/checks/fields/language.py
@@ -0,0 +1,19 @@
+# -*- 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 >.
+
+
+def language(project):
+    """
+    Check if a project has a language.
+
+    :param project: Project object
+    :return: All checks passed boolean, [Check results]
+    """
+    if project.language:
+        return True, [(u'success', u'has language')]
+
+    else:
+        return False, [(u'error', u'language missing')]
diff --git a/akvo/rsr/migrations/0082_auto_20160811_1633.py b/akvo/rsr/migrations/0082_auto_20160811_1633.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/migrations/0082_auto_20160811_1633.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+def add_language_to_validations(apps, schema_editor):
+    """
+    Add the language field as a mandatory field for the IATI validation sets.
+    """
+    ProjectEditorValidationSet = apps.get_model('rsr', 'ProjectEditorValidationSet')
+    ProjectEditorValidation = apps.get_model('rsr', 'ProjectEditorValidation')
+
+    for validation_set in ProjectEditorValidationSet.objects.filter(name__icontains="iati"):
+        ProjectEditorValidation.objects.get_or_create(
+            validation_set=validation_set,
+            validation='rsr_project.language',
+            action=1,
+        )
+
+
+def remove_language_from_validations(apps, schema_editor):
+    """
+    Remove the language field as a mandatory field from the IATI validation sets.
+    """
+    ProjectEditorValidationSet = apps.get_model('rsr', 'ProjectEditorValidationSet')
+    ProjectEditorValidation = apps.get_model('rsr', 'ProjectEditorValidation')
+
+    for validation_set in ProjectEditorValidationSet.objects.filter(name__icontains="iati"):
+        try:
+            validation = ProjectEditorValidation.objects.get(
+                validation_set=validation_set,
+                validation='rsr_project.language',
+                action=1,
+            )
+            validation.delete()
+        except ProjectEditorValidation.DoesNotExist:
+            pass
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('rsr', '0081_auto_20160721_0945'),
+    ]
+
+    operations = [
+        migrations.RunPython(add_language_to_validations, remove_language_from_validations),
+    ]


Test patch: