summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-06-11 15:13:09 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:20 +0100
commita8a99c748ba13ef394ff9006f0e192f320c459f1 (patch)
tree93f1e26e1f53c65bebfdbd69e10b3bde0dec4918
parent4ea9e96c0644b0986b1cf9d6b833f5bc3a175e94 (diff)
downloadIshtar-a8a99c748ba13ef394ff9006f0e192f320c459f1.tar.bz2
Ishtar-a8a99c748ba13ef394ff9006f0e192f320c459f1.zip
Container: bulk update
-rw-r--r--archaeological_finds/models_finds.py4
-rw-r--r--archaeological_warehouse/forms.py64
-rw-r--r--archaeological_warehouse/models.py6
-rw-r--r--archaeological_warehouse/urls.py8
-rw-r--r--archaeological_warehouse/views.py7
-rw-r--r--ishtar_common/forms.py3
6 files changed, 86 insertions, 6 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 1f0734df1..16287016b 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1428,11 +1428,11 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,
QA_EDIT = QuickAction(
url="find-qa-bulk-update", icon_class="fa fa-pencil",
- text=_(u"Bulk update"), target="many",
+ text=_("Bulk update"), target="many",
rights=['change_find', 'change_own_find'])
QA_LOCK = QuickAction(
url="find-qa-lock", icon_class="fa fa-lock",
- text=_(u"Lock/Unlock"), target="many",
+ text=_("Lock/Unlock"), target="many",
rights=['change_find', 'change_own_find']
)
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 ""
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index e130671a3..97fa38c88 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -694,12 +694,16 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem,
),
}
+ QA_EDIT = QuickAction(
+ url="container-qa-bulk-update", icon_class="fa fa-pencil",
+ text=_("Bulk update"), target="many",
+ rights=['change_container', 'change_own_container'])
QA_LOCK = QuickAction(
url="container-qa-lock", icon_class="fa fa-lock",
text=_("Lock/Unlock"), target="many",
rights=['change_container', 'change_own_container']
)
- QUICK_ACTIONS = [QA_LOCK]
+ QUICK_ACTIONS = [QA_EDIT, QA_LOCK]
objects = UUIDModelManager()
diff --git a/archaeological_warehouse/urls.py b/archaeological_warehouse/urls.py
index 14c957a26..c1b589315 100644
--- a/archaeological_warehouse/urls.py
+++ b/archaeological_warehouse/urls.py
@@ -104,6 +104,14 @@ urlpatterns = [
url(r'container-delete/(?P<pk>.+)/$',
views.container_delete, name='delete-container'),
+ url(r'^container-qa-bulk-update/(?P<pks>[0-9-]+)?/$',
+ check_rights(['change_container', 'change_own_container'])(
+ views.QAContainerForm.as_view()),
+ name='container-qa-bulk-update'),
+ url(r'^container-qa-bulk-update/(?P<pks>[0-9-]+)?/confirm/$',
+ check_rights(['change_container', 'change_own_container'])(
+ views.QAContainerForm.as_view()),
+ name='container-qa-bulk-update-confirm', kwargs={"confirm": True}),
url(r'^container-qa-lock/(?P<pks>[0-9-]+)?/$',
views.QAContainerLockView.as_view(), name='container-qa-lock',
kwargs={"model": models.Container}),
diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py
index 354ad4af1..d02b1d51e 100644
--- a/archaeological_warehouse/views.py
+++ b/archaeological_warehouse/views.py
@@ -33,7 +33,7 @@ from ishtar_common.forms import FinalForm
from ishtar_common.views import QABaseLockView, wizard_is_available, \
merge_action, ManualMergeMixin, ManualMergeItemsMixin, IshtarMixin, \
- LoginRequiredMixin
+ LoginRequiredMixin, QAItemEditForm
from ishtar_common.views_item import get_item, show_item, new_qa_item, \
revert_item
from archaeological_finds.views import treatment_add
@@ -294,3 +294,8 @@ def reset_wizards(request):
(ContainerDeletionWizard, 'container_deletion'),
):
wizard_class.session_reset(request, url_name)
+
+
+class QAContainerForm(QAItemEditForm):
+ model = models.Container
+ form_class = forms.QAContainerFormMulti
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 939563334..66b5c3796 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -969,6 +969,7 @@ class QAForm(CustomForm, ManageOldType):
MULTI = False
SINGLE_FIELDS = []
REPLACE_FIELDS = []
+ PREFIX= "qa_"
def __init__(self, *args, **kwargs):
self.items = kwargs.pop('items')
@@ -1017,7 +1018,7 @@ class QAForm(CustomForm, ManageOldType):
value = self.cleaned_data[base_key]
if not value:
return
- key = base_key[len("qa_"):]
+ key = base_key[len(self.PREFIX):]
field = item._meta.get_field(key)
if getattr(field, 'related_model', None):
is_list = isinstance(value, (list, tuple))