summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 10:48:39 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 10:48:39 +0200
commit166c5c7ea1a433f8e901bfc04a8b0c75fde1c207 (patch)
tree693c0fb95c2fcd330a2fbad4224274ea30347451 /archaeological_finds/forms.py
parenteb58fad63f8f41b275303b3c3e9e5fc75c963d80 (diff)
downloadIshtar-166c5c7ea1a433f8e901bfc04a8b0c75fde1c207.tar.bz2
Ishtar-166c5c7ea1a433f8e901bfc04a8b0c75fde1c207.zip
Find - treatments: multi del - redirects
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r--archaeological_finds/forms.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index a08821d85..628b08161 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -38,6 +38,7 @@ from archaeological_finds.forms_treatments import TreatmentSelect, \
AdministrativeActTreatmentForm, TreatmentFormFileChoice, \
TreatmentDeletionForm, TreatmentFileSelect, TreatmentFileFormSelection, \
TreatmentFileForm, TreatmentFileModifyForm, TreatmentFileDeletionForm, \
+ TreatmentFileFormSelectionMultiple, \
AdministrativeActTreatmentFormSelection, \
AdministrativeActTreatmentModifForm, \
AdministrativeActTreatmentFileForm, \
@@ -54,7 +55,7 @@ from ishtar_common import widgets
from ishtar_common.forms import CustomForm, CustomFormSearch, FormSet, \
FloatField, reverse_lazy, TableSelect, get_now, FinalForm, \
ManageOldType, FieldType, IshtarForm, FormHeader, QAForm, HistorySelect, \
- MultiSearchForm
+ MultiSearchForm, LockForm
from ishtar_common.forms_common import get_town_field
from ishtar_common.models import valid_id, valid_ids, get_current_profile, \
SpatialReferenceSystem, Area, OperationType, IshtarUser
@@ -1234,7 +1235,7 @@ class FindSelectWarehouseModule(FindSelect):
container__reference = forms.CharField(label=_(u"Current container ref."))
-class FindFormSelection(CustomFormSearch):
+class FindFormSelection(LockForm, CustomFormSearch):
SEARCH_AND_SELECT = True
form_label = _("Find search")
associated_models = {'pk': models.Find}
@@ -1250,21 +1251,21 @@ class FindFormSelection(CustomFormSearch):
source_full=reverse_lazy('get-find-full')),
validators=[valid_id(models.Find)])
- def clean(self):
- pk = self.cleaned_data[self.pk_key]
- if "," in str(pk):
- pks = [k.strip() for k in pk.split(',')]
- else:
- pks = [pk]
- for pk in pks:
- try:
- find = models.Find.objects.get(pk=pk)
- except models.Find.DoesNotExist:
- raise forms.ValidationError(_("Invalid selection."))
- if find.locked:
- raise forms.ValidationError(
- _("This find is locked for edition."))
- return self.cleaned_data
+
+class FindFormMultiSelection(LockForm, MultiSearchForm):
+ form_label = _("Find search")
+ associated_models = {'pks': models.Find}
+ pk_key = 'pks'
+
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-find'),
+ FindSelect, models.Find,
+ gallery=True, map=True,
+ multiple_select=True,
+ source_full=reverse_lazy('get-find-full')),
+ validators=[valid_ids(models.Find)])
class FindFormSelectionWarehouseModule(FindFormSelection):
@@ -1279,7 +1280,21 @@ class FindFormSelectionWarehouseModule(FindFormSelection):
extra_form_modals = ["warehouse", "container"]
+class FindFormMultiSelectionWarehouseModule(FindFormMultiSelection):
+ pk = forms.CharField(
+ label="", required=False,
+ widget=widgets.DataTable(
+ reverse_lazy('get-find'),
+ FindSelectWarehouseModule, models.Find,
+ gallery=True, map=True,
+ multiple_select=True,
+ source_full=reverse_lazy('get-find-full')),
+ validators=[valid_ids(models.Find)])
+
+
class MultipleFindFormSelection(forms.Form):
+ # used for basket management
+ # TODO: could probably use FindFormMultiSelection
form_label = _("Find search")
associated_models = {'pk': models.Find}
currents = {'pk': models.Find}
@@ -1295,6 +1310,8 @@ class MultipleFindFormSelection(forms.Form):
class MultipleFindFormSelectionWarehouseModule(MultipleFindFormSelection):
+ # used for basket management
+ # TODO: could probably use FindFormMultiSelectionWarehouse
pk = forms.IntegerField(
label="", required=False,
widget=widgets.DataTable(
@@ -1456,6 +1473,7 @@ class UpstreamFindFormSelection(MultiSearchForm, FindFormSelection):
form_label = _(u"Upstream finds")
current_model = models.Find
pk_key = 'resulting_pk'
+ associated_models = {"resulting_pk": models.Find}
pk = forms.CharField(
label="", required=False,
@@ -1467,10 +1485,6 @@ class UpstreamFindFormSelection(MultiSearchForm, FindFormSelection):
source_full=reverse_lazy('get-find-full')),
validators=[valid_ids(current_model)])
- def __init__(self, *args, **kwargs):
- super(UpstreamFindFormSelection, self).__init__(*args, **kwargs)
- self.fields['pk'].required = True
- self.fields['resulting_pk'] = self.fields.pop('pk')
class SingleUpstreamFindFormSelection(UpstreamFindFormSelection):