-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#2320] Add IATI language check
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |