Skip to content

Commit

Permalink
Merge pull request #2325 from akvo/#2320-iati-language-check
Browse files Browse the repository at this point in the history
[#2320] Add IATI language check
  • Loading branch information
KasperBrandt authored Aug 11, 2016
2 parents a91a464 + cfcbc23 commit 80a1ab8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions akvo/iati/checks/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +42,7 @@
'fss',
'humanitarian_scope',
'iati_identifier',
'language',
'legacy_data',
'locations',
'partners',
Expand Down
19 changes: 19 additions & 0 deletions akvo/iati/checks/fields/language.py
Original file line number Diff line number Diff line change
@@ -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')]
49 changes: 49 additions & 0 deletions akvo/rsr/migrations/0082_auto_20160811_1633.py
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit 80a1ab8

Please sign in to comment.