mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Allow better passthrough of context variables for non-form views
This commit is contained in:
parent
0cc59540ef
commit
14de111130
@ -65,9 +65,7 @@ class AjaxMixin(object):
|
||||
else:
|
||||
return self.template_name
|
||||
|
||||
def renderJsonResponse(self, request, form, data={}):
|
||||
|
||||
context = {}
|
||||
def renderJsonResponse(self, request, form=None, data={}, context={}):
|
||||
|
||||
if form:
|
||||
context['form'] = form
|
||||
@ -97,7 +95,7 @@ class AjaxView(AjaxMixin, View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
return self.renderJsonResponse(request, None)
|
||||
return self.renderJsonResponse(request, **kwargs)
|
||||
|
||||
|
||||
class AjaxCreateView(AjaxMixin, CreateView):
|
||||
@ -117,7 +115,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
||||
|
||||
data['url'] = obj.get_absolute_url()
|
||||
|
||||
return self.renderJsonResponse(request, form, data)
|
||||
return self.renderJsonResponse(request, form=form, data=data, **kwargs)
|
||||
|
||||
else:
|
||||
return super(CreateView, self).post(request, *args, **kwargs)
|
||||
@ -129,7 +127,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
|
||||
if request.is_ajax():
|
||||
form = self.form_class(initial=self.get_initial())
|
||||
|
||||
return self.renderJsonResponse(request, form)
|
||||
return self.renderJsonResponse(request, form=form, data=data, **kwargs)
|
||||
|
||||
else:
|
||||
return response
|
||||
|
@ -113,18 +113,24 @@ class PartEdit(AjaxUpdateView):
|
||||
class BomExport(AjaxView):
|
||||
|
||||
model = Part
|
||||
form_class = BomExportForm
|
||||
template_name = 'part/bom_export.html'
|
||||
#ajax_template_name = 'modal_form.html'
|
||||
ajax_form_title = 'Export Bill of Materials'
|
||||
ajax_submit_text = 'Export'
|
||||
context_object_name = 'part'
|
||||
fields = []
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
||||
|
||||
return self.renderJsonResponse(request, context={'part': part})
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
part = get_object_or_404(Part, pk=self.kwargs['pk'])
|
||||
|
||||
return self.renderJsonResponse(request, None)
|
||||
|
||||
return self.renderJsonResponse(request, context={'part': part})
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user