From c0dd253137f62e3e68f41907fd6ba1753dd6fd45 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 16 Apr 2019 19:38:29 +1000 Subject: [PATCH] Cleanup for AjaxUpdateView --- InvenTree/InvenTree/views.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index e013bed133..33f4b5780a 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -145,6 +145,20 @@ class AjaxCreateView(AjaxMixin, CreateView): class AjaxUpdateView(AjaxMixin, UpdateView): + """ An 'AJAXified' UpdateView for updating an object in the db + - Returns form in JSON format (for delivery to a modal window) + - Handles repeated form validation (via AJAX) until the form is valid + """ + + def get(self, request, *args, **kwargs): + if request.is_ajax(): + form = self.form_class(instance=self.get_object()) + + return self.renderJsonResponse(request, form) + + else: + return super(UpdateView, self).post(request, *args, **kwargs) + def post(self, request, *args, **kwargs): form = self.form_class(instance=self.get_object(), data=request.POST, files=request.FILES) @@ -165,14 +179,7 @@ class AjaxUpdateView(AjaxMixin, UpdateView): else: return response - def get(self, request, *args, **kwargs): - if request.is_ajax(): - form = self.form_class(instance=self.get_object()) - return self.renderJsonResponse(request, form) - - else: - return super(UpdateView, self).post(request, *args, **kwargs) class AjaxDeleteView(AjaxMixin, DeleteView):