summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 09:44:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-14 09:44:45 +0200
commiteb58fad63f8f41b275303b3c3e9e5fc75c963d80 (patch)
tree9fb4fcfff8387ac1c91707aab55180d560bf1485 /ishtar_common
parent89e94b9e2e18ce0f4a9572258b85e401463eb0ea (diff)
downloadIshtar-eb58fad63f8f41b275303b3c3e9e5fc75c963d80.tar.bz2
Ishtar-eb58fad63f8f41b275303b3c3e9e5fc75c963d80.zip
Archaeological files: multiple del - redir
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 5be5deafe..973a61228 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -384,6 +384,37 @@ class CustomFormSearch(forms.Form):
self.fields['pk'].widget.user = user
+class LockForm(object):
+ associated_models = {}
+
+ def clean(self):
+ cleaned_data = self.cleaned_data
+ pk_key = None
+ if hasattr(self, "pk_key"):
+ pk_key = self.pk_key
+ elif len(self.associated_models.keys()) == 1:
+ pk_key = list(self.associated_models.keys())[0]
+ if not pk_key:
+ raise NotImplementedError("pk_key must be set")
+ if pk_key not in cleaned_data or not cleaned_data[pk_key]:
+ raise forms.ValidationError(_(u"You should select an item."))
+ model = self.associated_models[pk_key]
+ pks = self.cleaned_data[pk_key]
+ if isinstance(pks, int):
+ pks = [pks]
+ else:
+ pks = pks.split(",")
+ for pk in pks:
+ try:
+ item = model.objects.get(pk=pk)
+ except model.DoesNotExist:
+ raise forms.ValidationError(_("Invalid selection."))
+ if item.locked:
+ raise forms.ValidationError(_("This item is locked "
+ "for edition."))
+ return self.cleaned_data
+
+
class MultiSearchForm(CustomFormSearch):
SEARCH_AND_SELECT = True
pk_key = 'pks'