From 086a1e5168f649369d7fb3617d22b773369fe2d0 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 27 Apr 2019 15:57:04 -0400 Subject: [PATCH] Load one language in the document properties form Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + docs/releases/3.2.rst | 1 + mayan/apps/documents/forms/document_forms.py | 6 ++---- mayan/apps/documents/utils.py | 11 +++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 89e53aee26..02799954e7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -179,6 +179,7 @@ * Add new and default Tesseract OCR backend to avoid Tesseract bug 1670 (https://github.com/tesseract-ocr/tesseract/issues/1670) +* Load only one language in the document properties form. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 7bccfb6467..8a447e0a04 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -211,6 +211,7 @@ Other changes * Add new and default Tesseract OCR backend to avoid Tesseract bug 1670 (https://github.com/tesseract-ocr/tesseract/issues/1670) +* Load only one language in the document properties form. Removals -------- diff --git a/mayan/apps/documents/forms/document_forms.py b/mayan/apps/documents/forms/document_forms.py index 0cd853fcb1..c1febeffbe 100644 --- a/mayan/apps/documents/forms/document_forms.py +++ b/mayan/apps/documents/forms/document_forms.py @@ -12,7 +12,7 @@ from mayan.apps.common.forms import DetailForm from ..fields import DocumentField from ..models import Document from ..literals import DEFAULT_ZIP_FILENAME, PAGE_RANGE_ALL, PAGE_RANGE_CHOICES -from ..utils import get_language_choices +from ..utils import get_language, get_language_choices __all__ = ( 'DocumentDownloadForm', 'DocumentForm', 'DocumentPreviewForm', @@ -151,9 +151,7 @@ class DocumentPropertiesForm(DetailForm): {'label': _('UUID'), 'field': 'uuid'}, { 'label': _('Language'), - 'field': lambda x: dict(get_language_choices()).get( - document.language, _('Unknown') - ) + 'field': lambda x: get_language(language_code=document.language) }, ] diff --git a/mayan/apps/documents/utils.py b/mayan/apps/documents/utils.py index a4836be527..21b2df2107 100644 --- a/mayan/apps/documents/utils.py +++ b/mayan/apps/documents/utils.py @@ -7,6 +7,17 @@ from django.utils.translation import ugettext_lazy as _ from .settings import setting_language_codes +def get_language(language_code): + language = getattr( + pycountry.languages.get(alpha_3=language_code), 'name', None + ) + + if language: + return _(language) + else: + return _('Unknown language "%s"') % language_code + + def get_language_choices(): return sorted( [