Convert language choices into a function

Move language choices generation to documents.utils.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-15 15:55:47 -04:00
parent 5071eb6fda
commit 29f81b2087
6 changed files with 25 additions and 20 deletions

View File

@@ -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)
===================

View File

@@ -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
--------

View File

@@ -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')
)
},

View File

@@ -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]
)

View File

@@ -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/

View File

@@ -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)