summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-04 16:41:41 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-12 09:57:24 +0200
commit5a52b18c2cd4fcde86cefb84f90b4bd0df7be5a3 (patch)
tree735cd414c9dd45334a08f5e8c93224257548aa53 /ishtar_common/forms_common.py
parenta54278d6d09645e5d9e6b310b7d58d7aa3f80f4d (diff)
downloadIshtar-5a52b18c2cd4fcde86cefb84f90b4bd0df7be5a3.tar.bz2
Ishtar-5a52b18c2cd4fcde86cefb84f90b4bd0df7be5a3.zip
Rebase migrations
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py72
1 files changed, 54 insertions, 18 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 854fe2a71..0473d19b6 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1052,27 +1052,35 @@ def get_image_help():
'height': settings.IMAGE_MAX_SIZE[1]}
-######################
-# Sources management #
-######################
-class SourceForm(CustomForm, ManageOldType):
+#######################
+# Document management #
+#######################
+
+
+class DocumentForm(CustomForm, ManageOldType):
form_label = _(u"Documentation informations")
- form_admin_name = _("Source - General")
+ form_admin_name = _("Document - General")
file_upload = True
associated_models = {'source_type': models.SourceType}
- title = forms.CharField(label=_(u"Title"),
+ title = forms.CharField(label=_(u"Title"), required=False,
validators=[validators.MaxLengthValidator(200)])
- source_type = forms.ChoiceField(label=_(u"Source type"), choices=[])
+ source_type = forms.ChoiceField(label=_(u"Source type"), choices=[],
+ required=False)
+ 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)"))
reference = forms.CharField(
label=_(u"Reference"),
validators=[validators.MaxLengthValidator(100)], required=False)
internal_reference = forms.CharField(
label=_(u"Internal reference"),
validators=[validators.MaxLengthValidator(100)], required=False)
- associated_url = forms.URLField(
- max_length=1000, required=False,
- label=_(u"Numerical ressource (web address)"))
receipt_date = forms.DateField(label=_(u"Receipt date"), required=False,
widget=DatePicker)
creation_date = forms.DateField(label=_(u"Creation date"), required=False,
@@ -1089,16 +1097,24 @@ class SourceForm(CustomForm, ManageOldType):
required=False)
duplicate = forms.BooleanField(label=_(u"Has a duplicate"),
required=False)
- image = forms.ImageField(
- label=_(u"Image"), help_text=mark_safe(get_image_help()),
- max_length=255, required=False, widget=widgets.ImageFileInput())
TYPES = [
FieldType('source_type', models.SourceType),
]
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ if not cleaned_data.get('title', None) and \
+ not cleaned_data.get('image', None) and \
+ not cleaned_data.get('associated_file', None) and \
+ not cleaned_data.get('associated_url', None):
+ raise forms.ValidationError(_(u"You should at least fill one of "
+ u"this field: title, url, image or "
+ u"file."))
+ return cleaned_data
+
-class SourceSelect(TableSelect):
+class DocumentSelect(TableSelect):
search_vector = forms.CharField(label=_(u"Full text search"),
widget=widgets.SearchWidget)
authors = forms.IntegerField(
@@ -1118,10 +1134,30 @@ class SourceSelect(TableSelect):
label=_(u"Additional informations"))
duplicate = forms.NullBooleanField(label=_(u"Has a duplicate"))
- def __init__(self, *args, **kwargs):
- super(SourceSelect, self).__init__(*args, **kwargs)
- self.fields['source_type'].choices = models.SourceType.get_types()
- self.fields['source_type'].help_text = models.SourceType.get_help()
+ TYPES = [
+ FieldType('source_type', models.SourceType),
+ ]
+
+
+class DocumentFormSelection(forms.Form):
+ SEARCH_AND_SELECT = True
+ form_label = _(u"Document search")
+ associated_models = {'pk': models.Document}
+ currents = {'pk': models.Document}
+
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-document'), DocumentSelect,
+ models.Document,
+ ),
+ validators=[models.valid_id(models.Document)])
+
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ if 'pk' not in cleaned_data or not cleaned_data['pk']:
+ raise forms.ValidationError(_(u"You should select an item."))
+ return cleaned_data
class SourceDeletionForm(FinalForm):