diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-05 20:42:14 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 09:57:24 +0200 |
commit | 52f6b37f1a1deac66f0b84c466be6c8dab277514 (patch) | |
tree | 2e9d8c696298f89e33e713d4eaf2a4c1c48af3b5 /ishtar_common/forms_common.py | |
parent | e7418c19b122c5ac0505ad2be5350068d3bf6f6b (diff) | |
download | Ishtar-52f6b37f1a1deac66f0b84c466be6c8dab277514.tar.bz2 Ishtar-52f6b37f1a1deac66f0b84c466be6c8dab277514.zip |
Document form - refactoring (refs #4107)
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 0473d19b6..9abc6551a 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -34,7 +34,7 @@ from django.core.files import File from django.forms.formsets import formset_factory from django.forms.models import BaseModelFormSet, BaseFormSet from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, pgettext import models import widgets @@ -1057,24 +1057,30 @@ def get_image_help(): ####################### -class DocumentForm(CustomForm, ManageOldType): - form_label = _(u"Documentation informations") +class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): + form_label = _(u"Documentation") form_admin_name = _("Document - General") - + form_slug = "document-general" file_upload = True associated_models = {'source_type': models.SourceType} + title = forms.CharField(label=_(u"Title"), required=False, validators=[validators.MaxLengthValidator(200)]) - source_type = forms.ChoiceField(label=_(u"Source type"), choices=[], - required=False) + source_type = widgets.ModelChoiceField( + model=models.SourceType, label=_(u"Source type"), choices=[], + required=False) + authors = widgets.ModelJQueryAutocompleteField( + model=models.Author, multiple=True, label=_(u"Authors"), new=True, + long_widget=True, required=False) + associated_url = forms.URLField( + max_length=1000, required=False, + label=_(u"Numerical ressource (web address)")) image = forms.ImageField( label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) associated_file = forms.FileField( - label=_(u"File"), max_length=255, required=False) - associated_url = forms.URLField( - max_length=1000, required=False, - label=_(u"Numerical ressource (web address)")) + label=pgettext(u"File", u"Not directory"), max_length=255, + required=False) reference = forms.CharField( label=_(u"Reference"), validators=[validators.MaxLengthValidator(100)], required=False) @@ -1102,6 +1108,15 @@ class DocumentForm(CustomForm, ManageOldType): FieldType('source_type', models.SourceType), ] + class Meta: + model = models.Document + fields = [ + 'title', 'source_type', 'authors', 'associated_url', 'image', + 'associated_file', 'reference', 'internal_reference', + 'receipt_date', 'creation_date', 'receipt_date_in_documentation', + 'comment', 'description', 'additional_information', 'duplicate' + ] + def clean(self): cleaned_data = self.cleaned_data if not cleaned_data.get('title', None) and \ |