From ced826479a1ce9b7b231376ce55dba0632d8df89 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 5 Jan 2021 17:18:33 +0100 Subject: Document: add publishing year --- ishtar_common/forms_common.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ishtar_common/forms_common.py') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 127791dd1..e15a4ef23 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -35,6 +35,7 @@ from django.core import validators from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist from django.core.files import File +from django.core.validators import MaxValueValidator, MinValueValidator from django.forms.formsets import formset_factory from django.forms.models import BaseModelFormSet, BaseFormSet from django.shortcuts import reverse @@ -1266,6 +1267,10 @@ class AddDocumentTagForm(AddGenericForm): form_label = _("Document tag") +def max_value_current_year(value): + return MaxValueValidator(datetime.date.today().year)(value) + + class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): form_label = _("Documentation") form_admin_name = _("Document - General") @@ -1319,6 +1324,10 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): tips=models.get_publisher_label, associated_model=models.Organization), validators=[models.valid_id(models.Organization)], required=False) + publishing_year = forms.IntegerField( + label=_("Year of publication"), + validators=[MinValueValidator(1000), max_value_current_year], + required=False) licenses = widgets.Select2MultipleField( label=_("Licenses"), required=False, model=models.LicenseType) tags = widgets.Select2MultipleField( @@ -1401,7 +1410,8 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): 'image', 'associated_file', 'associated_url', 'tags', 'authors', 'receipt_date', 'receipt_date_in_documentation', 'creation_date', - 'publisher', 'language', 'isbn', 'issn', 'licenses', + 'publisher', 'publishing_year', + 'language', 'isbn', 'issn', 'licenses', 'source', 'source_free_input', 'source_page_range', 'container_id', "container_ref_id", 'comment', 'description', 'additional_information', 'duplicate' @@ -1626,6 +1636,7 @@ class DocumentSelect(HistorySelect): tips=models.get_publisher_label, associated_model=models.Organization), validators=[models.valid_id(models.Organization)]) + publishing_year = forms.IntegerField(label=_("Year of publication")) language = forms.ChoiceField(label=_("Language"), choices=[]) isbn = forms.CharField(label=_("ISBN")) issn = forms.CharField(label=_("ISSN")) -- cgit v1.2.3