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.
This commit is contained in:
Roberto Rosario
2016-12-31 02:18:29 -04:00
parent 6bfdb053e3
commit 4f889fc21d
5 changed files with 41 additions and 13 deletions

View File

@@ -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 <https://gitlab.com/mayan-edms/mayan-edms/issues/307>`_ Enter multiple Tags at once
* `GitLab issue #311 <https://gitlab.com/mayan-edms/mayan-edms/issues/311>`_ acl page return ContentType:Document
* `GitLab issue #319 <https://gitlab.com/mayan-edms/mayan-edms/issues/319>`_ TransformationResize issue with very "long" image
* `GitLab issue #328 <https://gitlab.com/mayan-edms/mayan-edms/issues/328>`_ Upgrade Warning/Error during performupgrade (v2.1.3 to v2.1.4)
* `GitLab issue #342 <https://gitlab.com/mayan-edms/mayan-edms/issues/342>`_ Tags should be of unordered / unsorted data type
* `GitLab issue #343 <https://gitlab.com/mayan-edms/mayan-edms/issues/343>`_ Bootstrap's dependency on fonts.googleapis.com causes Mayan EDMS web interface load slowly if public internet is unreachable

View File

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

View File

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

View File

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

View File

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