diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-09-24 16:02:27 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | a21d0649b0e0122fdee368307241c6f938a85822 (patch) | |
tree | 672a8a6e672b978962e9878fd046e9d313875ddd | |
parent | eb039681c8ac7fbab9905b1a3dedc355523ee8ba (diff) | |
download | Ishtar-a21d0649b0e0122fdee368307241c6f938a85822.tar.bz2 Ishtar-a21d0649b0e0122fdee368307241c6f938a85822.zip |
Container: fix parent field on form - prevent recursion on parent location fix
-rw-r--r-- | archaeological_warehouse/forms.py | 5 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 170edce1f..12e9f4949 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -308,6 +308,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): raise forms.ValidationError( _("The parent container is not attached to the same " "warehouse.")) + return self.cleaned_data["parent"] def clean(self): cleaned_data = self.cleaned_data @@ -343,10 +344,14 @@ class ContainerModifyForm(ContainerForm): super(ContainerModifyForm, self).__init__(*args, **kwargs) fields = OrderedDict() idx = self.fields.pop('index') + reordered = False for key, value in self.fields.items(): fields[key] = value if key == 'container_type': fields['index'] = idx + reordered = True + if not reordered: + fields['index'] = idx self.fields = fields def clean(self): diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index d30a90f56..096ff0b6c 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -853,7 +853,8 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem, @classmethod def _change_child_location(cls, parent): - for child in cls.objects.filter(parent=parent).all(): + for child in cls.objects.filter( + parent=parent).exclude(location=parent.location).all(): if child.location != parent.location: child.location = parent.location child.save() |