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:
@@ -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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
--------
|
||||
|
||||
@@ -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')
|
||||
)
|
||||
},
|
||||
|
||||
@@ -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]
|
||||
)
|
||||
@@ -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/
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user