Cleanup for AjaxUpdateView

This commit is contained in:
Oliver Walters 2019-04-16 19:38:29 +10:00
parent 7708ffb069
commit c0dd253137

View File

@ -145,6 +145,20 @@ class AjaxCreateView(AjaxMixin, CreateView):
class AjaxUpdateView(AjaxMixin, UpdateView): 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): def post(self, request, *args, **kwargs):
form = self.form_class(instance=self.get_object(), data=request.POST, files=request.FILES) form = self.form_class(instance=self.get_object(), data=request.POST, files=request.FILES)
@ -165,14 +179,7 @@ class AjaxUpdateView(AjaxMixin, UpdateView):
else: else:
return response 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): class AjaxDeleteView(AjaxMixin, DeleteView):