From 05ed481007604079612aa4b0f1f3bb8d4d35a6e5 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 10 Sep 2019 18:02:50 +0200 Subject: Locks: prevent edit actions --- ishtar_common/forms.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 1f4d50d60..a69c65f0e 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -735,6 +735,14 @@ def get_form_selection( if self._main_key not in cleaned_data \ or not cleaned_data[self._main_key]: raise forms.ValidationError(self._not_selected_error) + + pk = self.cleaned_data[self._main_key] + try: + item = model.objects.get(pk=pk) + except model.DoesNotExist: + raise forms.ValidationError(_("Invalid selection.")) + if hasattr(item, "locked") and item.locked: + raise forms.ValidationError(_("This item is locked for edition.")) return cleaned_data attrs['clean'] = clean attrs['SEARCH_AND_SELECT'] = True -- cgit v1.2.3