Add workaround for pycountry versions without the bibliographical key.

GitHub issue #250.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-08-02 23:58:52 -04:00
parent a5a5690d66
commit 3d6a32c7b6

View File

@@ -10,9 +10,18 @@ def change_bibliographic_to_terminology(apps, schema_editor):
Document = apps.get_model('documents', 'Document')
for document in Document.objects.all():
language = pycountry.languages.get(bibliographic=document.language)
document.language = language.terminology
document.save()
try:
language = pycountry.languages.get(bibliographic=document.language)
except KeyError:
# The pycountry version used doesn't support the 'bibliographic'
# key. Reset the document's language to English.
# GitHub issue #250
# https://github.com/mayan-edms/mayan-edms/issues/250
document.language = 'eng'
document.save()
else:
document.language = language.terminology
document.save()
class Migration(migrations.Migration):