diff options
Diffstat (limited to 'archaeological_warehouse/forms.py')
| -rw-r--r-- | archaeological_warehouse/forms.py | 45 | 
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)  )  | 
