diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-01-24 13:08:31 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:23 +0100 |
commit | caf88fbf599a490b9dff1bc2668f0e7d62723dc8 (patch) | |
tree | 9bf8aa54baef10982d2919f2bd0c872c5e34fd12 /archaeological_warehouse/forms.py | |
parent | 8d7ed2a8208a1d3422e4827a35fa7d6cb7f59cee (diff) | |
download | Ishtar-caf88fbf599a490b9dff1bc2668f0e7d62723dc8.tar.bz2 Ishtar-caf88fbf599a490b9dff1bc2668f0e7d62723dc8.zip |
Container: prevent parent association to himself
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r-- | archaeological_warehouse/forms.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 110f01c9b..050a62e7d 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -330,11 +330,16 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): container_type_id=cleaned_data.get("container_type"), parent_id=cleaned_data.get("parent") ) + pk = None if 'pk' in cleaned_data and cleaned_data['pk']: - q = q.exclude(pk=int(cleaned_data['pk'])) + pk = int(cleaned_data['pk']) + q = q.exclude(pk=pk) if q.count(): raise forms.ValidationError(_("This reference already exists for " "this warehouse.")) + if pk and pk == int(cleaned_data.get("parent")): + raise forms.ValidationError(_("A container cannot be a parent of " + "himself.")) return cleaned_data def save(self, user): @@ -643,6 +648,10 @@ class QAContainerFormMulti(QAForm): "qaparent"] new_tuples = [] for item in self.items: + if new_values.get("parent_id", None) and int( + new_values["parent_id"]) == item.pk: + raise forms.ValidationError( + _("A container cannot be a parent of himself.")) vals = { "container_type_id": item.container_type_id, "location_id": item.location_id, |