From 5941e8e4092468a1f520e45b5bd6295d6f6546e2 Mon Sep 17 00:00:00 2001 From: "francois.ancien" Date: Fri, 20 Jan 2023 11:31:19 +0100 Subject: [PATCH] Correcting a validation check and displaying all errors instead of one by one --- web/views/access.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/views/access.py b/web/views/access.py index 65546493..1233349e 100644 --- a/web/views/access.py +++ b/web/views/access.py @@ -91,17 +91,18 @@ class AccessEditView(CheckerMixin, UpdateView, AjaxViewMixin): def form_valid(self, form): """If access status is Active, only data stewards can edit it""" - if self.object.status == StatusChoices.active and not self.request.user.is_part_of(Groups.DATA_STEWARD.value): + original_object = self.model.objects.get(pk=self.object.id) + if original_object.status == StatusChoices.active and not self.request.user.is_part_of(Groups.DATA_STEWARD.value): form.add_error(None, "Only data stewards can edit active accesses, please contact one") - return super().form_invalid(form) """If the form is valid, check that remark is updated then save the associated model and add to the dataset""" if "access_notes" not in form.changed_data: form.add_error("access_notes", "Changes must be justified. Please update this field") - return super().form_invalid(form) if StatusChoices.active.name in form.data.get("status") and not self.request.user.is_part_of(Groups.DATA_STEWARD.value): form.add_error("status", "Only data stewards are allowed to activate accesses, please contact one") + + if form.errors: return super().form_invalid(form) self.object = form.save(commit=False)