summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 12:06:49 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 12:06:49 +0200
commit53653e8d74e936a89515fbaae77bbbeea578e7f5 (patch)
tree711769ac53ca16b982eab7a5f98239fe748ee802 /archaeological_warehouse/forms.py
parent184c6960f537d315155efeb620d526c0b2022630 (diff)
downloadIshtar-53653e8d74e936a89515fbaae77bbbeea578e7f5.tar.bz2
Ishtar-53653e8d74e936a89515fbaae77bbbeea578e7f5.zip
Containers, Warehouse : multiple del - redirs
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r--archaeological_warehouse/forms.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index facc94467..88a355bad 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -27,7 +27,7 @@ from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
from ishtar_common.models import Person, valid_id, Town, \
- SpatialReferenceSystem, Organization, OrganizationType
+ SpatialReferenceSystem, Organization, valid_ids
from archaeological_operations.models import ArchaeologicalSite
from archaeological_context_records.models import ContextRecord
from archaeological_finds.models import TreatmentType, FindBasket, \
@@ -43,7 +43,7 @@ from bootstrap_datepicker.widgets import DatePicker
from ishtar_common.forms import name_validator, reverse_lazy, \
get_form_selection, ManageOldType, FinalForm, FormSet, \
CustomForm, FieldType, HistorySelect, FormHeader, TableSelect, \
- CustomFormSearch
+ CustomFormSearch, MultiSearchForm, LockForm
from ishtar_common.forms_common import get_town_field
from archaeological_finds.forms import FindMultipleFormSelection, \
SelectFindBasketForm
@@ -110,7 +110,7 @@ class WarehouseSelect(CustomForm, TableSelect):
models.WarehouseType.get_help()
-class WarehouseFormSelection(CustomFormSearch):
+class WarehouseFormSelection(LockForm, CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Warehouse search")
associated_models = {'pk': models.Warehouse}
@@ -122,20 +122,18 @@ class WarehouseFormSelection(CustomFormSearch):
WarehouseSelect, models.Warehouse, gallery=True, map=True),
validators=[valid_id(models.Warehouse)])
- 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."))
- pk = self.cleaned_data["pk"]
- try:
- item = models.Warehouse.objects.get(pk=pk)
- except models.Warehouse.DoesNotExist:
- raise forms.ValidationError(_("Invalid selection."))
- print(item)
- if item.locked:
- raise forms.ValidationError(_("This warehouse is locked for "
- "edition."))
- return self.cleaned_data
+
+class WarehouseFormMultiSelection(LockForm, MultiSearchForm):
+ form_label = _("Warehouse search")
+ associated_models = {'pks': models.Warehouse}
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-warehouse'),
+ WarehouseSelect, models.Warehouse, gallery=True, map=True,
+ multiple_select=True
+ ),
+ validators=[valid_ids(models.Warehouse)])
class WarehouseForm(CustomForm, ManageOldType, forms.Form):
@@ -452,14 +450,23 @@ ContainerFormSelection = get_form_selection(
models.Container, ContainerSelect, 'get-container',
_(u"You should select a container."), new=True,
new_message=_(u"Add a new container"),
- base_form_select=CustomFormSearch
+ base_form_select=(LockForm, CustomFormSearch)
)
MainContainerFormSelection = get_form_selection(
'ContainerFormSelection', _(u"Container search"), 'pk',
models.Container, ContainerSelect, 'get-container',
_(u"You should select a container."), gallery=True, map=True,
- base_form_select = CustomFormSearch
+ base_form_select=CustomFormSearch
+)
+
+
+MainContainerFormMultiSelection = get_form_selection(
+ 'ContainerFormSelection', _(u"Container search"), 'pks',
+ models.Container, ContainerSelect, 'get-container',
+ _(u"You should select a container."), gallery=True, map=True,
+ alt_pk_field="pk",
+ multi=True, base_form_select=(LockForm, MultiSearchForm)
)