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:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user