From 34b80cd9b735aaae35859c972b75c3e9220cc8a4 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 14 Sep 2019 09:44:45 +0200 Subject: Archaeological files: multiple del - redir --- archaeological_files/forms.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'archaeological_files/forms.py') 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")), -- cgit v1.2.3