summaryrefslogtreecommitdiff
path: root/archaeological_files/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 09:44:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 09:44:45 +0200
commiteb58fad63f8f41b275303b3c3e9e5fc75c963d80 (patch)
tree9fb4fcfff8387ac1c91707aab55180d560bf1485 /archaeological_files/forms.py
parent89e94b9e2e18ce0f4a9572258b85e401463eb0ea (diff)
downloadIshtar-eb58fad63f8f41b275303b3c3e9e5fc75c963d80.tar.bz2
Ishtar-eb58fad63f8f41b275303b3c3e9e5fc75c963d80.zip
Archaeological files: multiple del - redir
Diffstat (limited to 'archaeological_files/forms.py')
-rw-r--r--archaeological_files/forms.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 640e2cab1..4d8ab749a 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -30,14 +30,15 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from ishtar_common.models import Person, Organization, \
- valid_id, Department, person_type_pks_lazy, \
+ valid_id, valid_ids, Department, person_type_pks_lazy, \
person_type_pk_lazy, organization_type_pks_lazy
from archaeological_operations.models import ActType, AdministrativeAct, \
OperationType
from . import models
from ishtar_common.forms import FinalForm, get_now, reverse_lazy, TableSelect, \
- ManageOldType, CustomForm, FieldType, IshtarForm, HistorySelect
+ ManageOldType, CustomForm, FieldType, IshtarForm, HistorySelect, \
+ MultiSearchForm, LockForm, CustomFormSearch
from ishtar_common.forms_common import get_town_field
from archaeological_operations.forms import AdministrativeActForm, \
AdministrativeActOpeFormSelection, SLICING, AdministrativeActModifForm, \
@@ -123,7 +124,7 @@ class FileSelect(HistorySelect):
('', '--')] + list(settings.ISHTAR_DPTS)
-class FileFormSelection(forms.Form):
+class FileFormSelection(LockForm, CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Archaeological file search")
associated_models = {'pk': models.File}
@@ -136,18 +137,19 @@ class FileFormSelection(forms.Form):
source_full=reverse_lazy('get-file-full')),
validators=[valid_id(models.File)])
- 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 a file."))
- pk = self.cleaned_data["pk"]
- try:
- file = models.File.objects.get(pk=pk)
- except models.File.DoesNotExist:
- raise forms.ValidationError(_("Invalid selection."))
- if file.locked:
- raise forms.ValidationError(_("This file is locked for edition."))
- return self.cleaned_data
+
+class FileFormMultiSelection(LockForm, MultiSearchForm):
+ form_label = _("Archaeological file search")
+ associated_models = {'pks': models.File}
+
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-file'),
+ FileSelect, models.File,
+ multiple_select=True,
+ source_full=reverse_lazy('get-file-full')),
+ validators=[valid_ids(models.File)])
DATE_SOURCE = (('creation', _(u"Creation date")),