From 3199862aa12f8eabb4dc5d3485a2e915476a5d99 Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Sat, 4 Jan 2025 02:24:33 -0300 Subject: [PATCH] edit update cannot be blank --- action/views.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/action/views.py b/action/views.py index 8cf0a81..125b656 100644 --- a/action/views.py +++ b/action/views.py @@ -69,6 +69,7 @@ class AddNoteView(View): return redirect(request.META.get('HTTP_REFERER') ) + class UpdateNoteView(UpdateView): model = Note fields = ['description'] @@ -88,10 +89,16 @@ class UpdateNoteView(UpdateView): user=self.request.user, institution=self.request.user.institution, ) - - messages.success(self.request, "Note has been updated.") + messages.success(self.request, "Note has been updated.") return super().form_valid(form) - + + def form_invalid(self, form): + new_description = form.cleaned_data.get('description', '').strip() + if not new_description: + messages.error(self.request, _("Note cannot be empty.")) + super().form_invalid(form) + return redirect(self.get_success_url()) + def get_success_url(self): return self.request.META.get('HTTP_REFERER', reverse_lazy('device:details'))