From 4f889fc21ddcb365480799a20bdb06863f11b7ca Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 31 Dec 2016 02:18:29 -0400 Subject: [PATCH] Move the document language choice list from the model to the form. Pycoutry upgrades or user changes to the language choice list won't trigger a migration anymore. Closes GitLab issue #328. --- docs/releases/2.2.rst | 2 ++ mayan/apps/documents/forms.py | 25 +++++++++++++------ .../migrations/0037_auto_20161231_0617.py | 20 +++++++++++++++ mayan/apps/documents/models.py | 3 +-- mayan/apps/documents/settings.py | 4 --- 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 mayan/apps/documents/migrations/0037_auto_20161231_0617.py diff --git a/docs/releases/2.2.rst b/docs/releases/2.2.rst index 07b8812949..b3bb438a9f 100644 --- a/docs/releases/2.2.rst +++ b/docs/releases/2.2.rst @@ -38,6 +38,7 @@ on production install to debug errors live. - Addition of a new OCR backend using PyOCR. This backend tries first to do OCR using libtesseract. If libtesseract is not available the backend fallsback to calling the Tesseract executable. +- Language list moved from document model to document form. Removals -------- @@ -103,6 +104,7 @@ Bugs fixed or issues closed * `GitLab issue #307 `_ Enter multiple Tags at once * `GitLab issue #311 `_ acl page return ContentType:Document * `GitLab issue #319 `_ TransformationResize issue with very "long" image +* `GitLab issue #328 `_ Upgrade Warning/Error during performupgrade (v2.1.3 to v2.1.4) * `GitLab issue #342 `_ Tags should be of unordered / unsorted data type * `GitLab issue #343 `_ Bootstrap's dependency on fonts.googleapis.com causes Mayan EDMS web interface load slowly if public internet is unreachable diff --git a/mayan/apps/documents/forms.py b/mayan/apps/documents/forms.py index 6740c3472c..772c900a4d 100644 --- a/mayan/apps/documents/forms.py +++ b/mayan/apps/documents/forms.py @@ -8,15 +8,15 @@ from django.template.defaultfilters import filesizeformat from django.utils.translation import ugettext_lazy as _ from acls.models import AccessControlList -from common.forms import DetailForm, ModelForm +from common.forms import DetailForm from .models import ( Document, DocumentType, DocumentPage, DocumentTypeFilename ) from .literals import DEFAULT_ZIP_FILENAME, PAGE_RANGE_ALL, PAGE_RANGE_CHOICES from .permissions import permission_document_create +from .settings import setting_language_choices from .widgets import DocumentPagesCarouselWidget, DocumentPageImageWidget - logger = logging.getLogger(__name__) @@ -42,8 +42,6 @@ class DocumentPageForm(DetailForm): # Document forms - - class DocumentPreviewForm(forms.Form): def __init__(self, *args, **kwargs): document = kwargs.pop('instance', None) @@ -59,14 +57,21 @@ class DocumentPreviewForm(forms.Form): preview = forms.CharField(widget=DocumentPagesCarouselWidget()) -class DocumentForm(ModelForm): +class DocumentForm(forms.ModelForm): """ Form sub classes from DocumentForm used only when editing a document """ class Meta: fields = ('label', 'description', 'language') model = Document - sorted_fields = {'language': itemgetter(1)} + widgets = { + 'language': forms.Select( + choices=setting_language_choices.value, attrs={ + 'class': 'select2' + } + ) + + } def __init__(self, *args, **kwargs): document_type = kwargs.pop('document_type', None) @@ -112,6 +117,12 @@ class DocumentPropertiesForm(DetailForm): 'widget': forms.widgets.DateTimeInput }, {'label': _('UUID'), 'field': 'uuid'}, + { + 'label': _('Language'), + 'field': lambda x: dict(setting_language_choices.value).get( + document.language, _('Unknown') + ) + }, ] if document.latest_version: @@ -145,7 +156,7 @@ class DocumentPropertiesForm(DetailForm): super(DocumentPropertiesForm, self).__init__(*args, **kwargs) class Meta: - fields = ('document_type', 'description', 'language') + fields = ('document_type', 'description') model = Document diff --git a/mayan/apps/documents/migrations/0037_auto_20161231_0617.py b/mayan/apps/documents/migrations/0037_auto_20161231_0617.py new file mode 100644 index 0000000000..b8bcf6c651 --- /dev/null +++ b/mayan/apps/documents/migrations/0037_auto_20161231_0617.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.4 on 2016-12-31 06:17 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '0036_auto_20161222_0534'), + ] + + operations = [ + migrations.AlterField( + model_name='document', + name='language', + field=models.CharField(blank=True, default='eng', max_length=8, verbose_name='Language'), + ), + ] diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index ec965dc24c..9703753ef5 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -159,8 +159,7 @@ class Document(models.Model): auto_now_add=True, db_index=True, verbose_name=_('Added') ) language = models.CharField( - blank=True, choices=setting_language_choices.value, - default=setting_language.value, max_length=8, + blank=True, default=setting_language.value, max_length=8, verbose_name=_('Language') ) in_trash = models.BooleanField( diff --git a/mayan/apps/documents/settings.py b/mayan/apps/documents/settings.py index e2e9fb4308..3b818cc4dc 100644 --- a/mayan/apps/documents/settings.py +++ b/mayan/apps/documents/settings.py @@ -6,10 +6,6 @@ from django.utils.translation import ugettext_lazy as _ from smart_settings import Namespace -# TODO: Findout method to make languages names' translatable. -# YAML fails to serialize ugettext_lazy and ugettext is not allowed at this -# level - LANGUAGE_CHOICES = [ (i.iso639_3_code, i.name) for i in list(pycountry.languages) ]