summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/forms.py
diff options
context:
space:
mode:
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
commit8896cb7dc9d760e4b3769b72c6af83b8a0b81eda (patch)
tree9bf8aa54baef10982d2919f2bd0c872c5e34fd12 /archaeological_warehouse/forms.py
parent9ec4e271f9285fb7cd8d735c859decaa9c0d2673 (diff)
downloadIshtar-8896cb7dc9d760e4b3769b72c6af83b8a0b81eda.tar.bz2
Ishtar-8896cb7dc9d760e4b3769b72c6af83b8a0b81eda.zip
Container: prevent parent association to himself
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r--archaeological_warehouse/forms.py11
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,