diff options
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 |
commit | 34b80cd9b735aaae35859c972b75c3e9220cc8a4 (patch) | |
tree | 9fb4fcfff8387ac1c91707aab55180d560bf1485 /archaeological_files/forms.py | |
parent | 73ba1638f580f6968126f4939a1f4495710915cb (diff) | |
download | Ishtar-34b80cd9b735aaae35859c972b75c3e9220cc8a4.tar.bz2 Ishtar-34b80cd9b735aaae35859c972b75c3e9220cc8a4.zip |
Archaeological files: multiple del - redir
Diffstat (limited to 'archaeological_files/forms.py')
-rw-r--r-- | archaeological_files/forms.py | 32 |
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")), |