Fixed bugs in Inventree/views.py

- Need to pass request.FILES to the form! (duh!) 
 - Prevent form data from being saved twice
This commit is contained in:
Oliver 2018-05-03 23:40:27 +10:00
parent 68cf6919a7
commit bc716e25f7
4 changed files with 15 additions and 6 deletions

View File

@ -105,9 +105,9 @@ class AjaxView(AjaxMixin, View):
class AjaxCreateView(AjaxMixin, CreateView):
def post(self, request, *args, **kwargs):
form = self.form_class(data=request.POST, files=request.FILES)
if request.is_ajax():
form = self.form_class(request.POST)
data = {'form_valid': form.is_valid()}
@ -141,8 +141,9 @@ class AjaxUpdateView(AjaxMixin, UpdateView):
def post(self, request, *args, **kwargs):
form = self.form_class(instance=self.get_object(), data=request.POST, files=request.FILES)
if request.is_ajax():
form = self.form_class(request.POST, instance=self.get_object())
data = {'form_valid': form.is_valid()}
@ -152,10 +153,10 @@ class AjaxUpdateView(AjaxMixin, UpdateView):
data['pk'] = obj.id
data['url'] = obj.get_absolute_url()
return self.renderJsonResponse(request, form, data)
response = self.renderJsonResponse(request, form, data)
return response
else:
response = super(UpdateView, self).post(request, *args, **kwargs)
return response
def get(self, request, *args, **kwargs):
@ -168,7 +169,7 @@ class AjaxUpdateView(AjaxMixin, UpdateView):
return self.renderJsonResponse(request, form)
else:
return response
return super(UpdateView, self).post(request, *args, **kwargs)
class AjaxDeleteView(AjaxMixin, DeleteView):

View File

@ -92,7 +92,7 @@
launchModalForm("#modal-form",
"{% url 'part-edit' part.id %}",
{
reload: true
reload: true,
});
});

View File

@ -89,6 +89,9 @@
$("#part-thumb").click(function() {
launchModalForm("#modal-form",
"{% url 'part-image' part.id %}",
{
reload: true
}
);
});
{% endblock %}

View File

@ -96,6 +96,11 @@ class PartImage(AjaxUpdateView):
ajax_form_title = 'Upload Part Image'
form_class = PartImageForm
def get_data(self):
return {
'success': 'Updated part image',
}
class PartEdit(AjaxUpdateView):
model = Part