Simplify AjaxDeleteView

This commit is contained in:
Oliver Walters 2019-04-28 10:41:54 +10:00
parent 72ff25e0c1
commit ff068de16d

View File

@ -227,39 +227,33 @@ class AjaxDeleteView(AjaxMixin, DeleteView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
html_response = super(DeleteView, self).get(request, *args, **kwargs) super(DeleteView, self).get(request, *args, **kwargs)
if request.is_ajax(): data = {
'id': self.get_object().id,
data = {'id': self.get_object().id,
'delete': False, 'delete': False,
'title': self.ajax_form_title, 'title': self.ajax_form_title,
'html_data': render_to_string(self.ajax_template_name, 'html_data': render_to_string(
self.ajax_template_name,
self.get_context_data(), self.get_context_data(),
request=request) request=request)
} }
return JsonResponse(data) return JsonResponse(data)
else:
return html_response
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if request.is_ajax():
obj = self.get_object() obj = self.get_object()
pk = obj.id pk = obj.id
obj.delete() obj.delete()
data = {'id': pk, data = {
'delete': True} 'id': pk,
'delete': True
}
return self.renderJsonResponse(request, data=data) return self.renderJsonResponse(request, data=data)
else:
return super(DeleteView, self).post(request, *args, **kwargs)
class IndexView(TemplateView): class IndexView(TemplateView):
""" View for InvenTree index page """ """ View for InvenTree index page """