From 29f81b20870c7f86883f29a3aba558ca2fd5866e Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 15 Apr 2019 15:55:47 -0400 Subject: [PATCH] Convert language choices into a function Move language choices generation to documents.utils. Signed-off-by: Roberto Rosario --- HISTORY.rst | 2 ++ docs/releases/3.2.rst | 2 ++ mayan/apps/documents/forms.py | 6 +++--- mayan/apps/documents/runtime.py | 15 --------------- mayan/apps/documents/utils.py | 16 ++++++++++++++++ mayan/apps/ocr/tests/test_models.py | 4 ++-- 6 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 mayan/apps/documents/runtime.py diff --git a/HISTORY.rst b/HISTORY.rst index c22f958a85..e84bc41eae 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -70,6 +70,8 @@ * Expose new Django settings: AUTH_PASSWORD_VALIDATORS, DEFAULT_FROM_EMAIL, EMAIL_TIMEOUT, INTERNAL_IPS, LANGUAGES, LANGUAGE_CODE, STATIC_URL, STATICFILES_STORAGE, TIME_ZONE, WSGI_APPLICATION. +* Convert language choices into a function. +* Move language choices generation to documents.utils. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 03a1f6486f..71a77b8880 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -102,6 +102,8 @@ Other changes * Expose new Django settings: AUTH_PASSWORD_VALIDATORS, DEFAULT_FROM_EMAIL, EMAIL_TIMEOUT, INTERNAL_IPS, LANGUAGES, LANGUAGE_CODE, STATIC_URL, STATICFILES_STORAGE, TIME_ZONE, WSGI_APPLICATION. +* Convert language choices into a function. +* Move language choices generation to documents.utils. Removals -------- diff --git a/mayan/apps/documents/forms.py b/mayan/apps/documents/forms.py index 136939a3cb..96ccef3dcd 100644 --- a/mayan/apps/documents/forms.py +++ b/mayan/apps/documents/forms.py @@ -18,7 +18,7 @@ from .models import ( ) from .literals import DEFAULT_ZIP_FILENAME, PAGE_RANGE_ALL, PAGE_RANGE_CHOICES from .permissions import permission_document_create -from .runtime import language_choices +from .utils import get_language_choices logger = logging.getLogger(__name__) @@ -68,7 +68,7 @@ class DocumentForm(forms.ModelForm): model = Document widgets = { 'language': forms.Select( - choices=language_choices, attrs={ + choices=get_language_choices(), attrs={ 'class': 'select2' } ) @@ -153,7 +153,7 @@ class DocumentPropertiesForm(DetailForm): {'label': _('UUID'), 'field': 'uuid'}, { 'label': _('Language'), - 'field': lambda x: dict(language_choices).get( + 'field': lambda x: dict(get_language_choices()).get( document.language, _('Unknown') ) }, diff --git a/mayan/apps/documents/runtime.py b/mayan/apps/documents/runtime.py deleted file mode 100644 index f10fe5204d..0000000000 --- a/mayan/apps/documents/runtime.py +++ /dev/null @@ -1,15 +0,0 @@ -from __future__ import unicode_literals - -import pycountry - -from django.utils.translation import ugettext_lazy as _ - -from .settings import setting_language_codes - -language_choices = sorted( - [ - ( - iso639_3, _(pycountry.languages.get(alpha_3=iso639_3).name) - ) for iso639_3 in setting_language_codes.value - ], key=lambda x: x[1] -) diff --git a/mayan/apps/documents/utils.py b/mayan/apps/documents/utils.py index e33b45e9de..9c6b744e57 100644 --- a/mayan/apps/documents/utils.py +++ b/mayan/apps/documents/utils.py @@ -1,5 +1,21 @@ from __future__ import unicode_literals +import pycountry + +from django.utils.translation import ugettext_lazy as _ + +from .settings import setting_language_codes + + +def get_language_choices(): + return sorted( + [ + ( + iso639_3, _(pycountry.languages.get(alpha_3=iso639_3).name) + ) for iso639_3 in setting_language_codes.value + ], key=lambda x: x[1] + ) + def parse_range(astr): # http://stackoverflow.com/questions/4248399/ diff --git a/mayan/apps/ocr/tests/test_models.py b/mayan/apps/ocr/tests/test_models.py index 324ce44d61..8a5439e340 100644 --- a/mayan/apps/ocr/tests/test_models.py +++ b/mayan/apps/ocr/tests/test_models.py @@ -4,10 +4,10 @@ from __future__ import unicode_literals from mayan.apps.common.tests import BaseTestCase from mayan.apps.documents.models import DocumentType -from mayan.apps.documents.runtime import language_choices from mayan.apps.documents.tests import ( DocumentTestMixin, TEST_DEU_DOCUMENT_PATH, TEST_DOCUMENT_TYPE_LABEL ) +from mayan.apps.documents.utils import get_language_choices TEST_DOCUMENT_CONTENT = 'Mayan EDMS Documentation' TEST_DOCUMENT_CONTENT_DEU_1 = 'Repository für elektronische Dokumente.' @@ -39,7 +39,7 @@ class GermanOCRSupportTestCase(BaseTestCase): # Get corresponding language code for German from the default language # choices list language_code = [ - language for language in language_choices if language[1] == 'German' + language for language in get_language_choices() if language[1] == 'German' ][0][0] self.assertEqual('deu', language_code)