diff options
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r-- | archaeological_warehouse/forms.py | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 125adb2b5..9c39c61c5 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -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, DocumentItemSelect, FormHeader, TableSelect, \ - CustomFormSearch, MultiSearchForm, LockForm + CustomFormSearch, MultiSearchForm, LockForm, QAForm from ishtar_common.forms_common import get_town_field, MergeForm, ManualMerge,\ MergeIntoForm from archaeological_finds.forms import FindMultipleFormSelection, \ @@ -547,3 +547,65 @@ class FindPackagingFormSelection(FindMultipleFormSelection): class ContainerDeletionForm(FinalForm): confirm_msg = _("Would you like to delete this container?") confirm_end_msg = _("Would you like to delete this container?") + + +class QAContainerFormMulti(QAForm): + PREFIX = "qa" + form_admin_name = _("Container - Quick action - Modify") + form_slug = "container-quickaction-modify" + base_models = ['qaparent', 'qacontainer_type', 'qalocation'] + associated_models = { + 'qaparent': models.Container, + 'qacontainer_type': models.ContainerType, + 'qalocation': models.Warehouse, + } + + MULTI = True + REPLACE_FIELDS = [ + "qaparent", + "qacontainer_type", + "qalocation" + ] + + HEADERS = { + "qalocation": FormHeader(_("Warehouse")), + } + + SINGLE_FIELDS = [] + qacontainer_type = forms.ChoiceField(label=_("Container type"), + required=False, choices=[]) + qalocation = forms.IntegerField( + label=_("Location"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-warehouse'), + associated_model=models.Warehouse), + validators=[valid_id(models.Warehouse)], required=False) + qaparent = forms.IntegerField( + label=_("Parent"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-container'), + dynamic_limit=['qalocation'], + associated_model=models.Container), + validators=[valid_id(models.Container)], required=False) + + TYPES = [ + FieldType('qacontainer_type', models.ContainerType), + ] + + def __init__(self, *args, **kwargs): + super(QAContainerFormMulti, self).__init__(*args, **kwargs) + locations = set([item.location_id for item in self.items]) + if len(locations) == 1: + self.fields["qalocation"].initial = locations.pop() + + def _get_qalocation(self, value): + try: + return models.Warehouse.objects.get(pk=value).name + except models.Warehouse.DoesNotExist: + return "" + + def _get_qaparent(self, value): + try: + return models.Container.objects.get(pk=value).cached_label + except models.Container.DoesNotExist: + return "" |