Upload the selected BOM file

This commit is contained in:
Oliver Walters 2019-07-02 19:07:59 +10:00
parent 802255c62d
commit 4008a9fb45
4 changed files with 11 additions and 44 deletions

View File

@ -1,25 +0,0 @@
{% extends "modal_form.html" %}
{% block pre_form_content %}
<h4>Step 1 of 3 - Select BOM File</h4>
{{ block.super }}
<p>Select a BOM file to upload for:<br>
<b>{{ part.name }} - <i>{{ part.description }}</i></b>
</p>
<p>The BOM file must contain the required named columns as provided in the <a href="/part/bom_template/">BOM Upload Template</a></a></p>
<b>Notes:</b>
<ul>
<li>Supported file formats: <i>.csv, .tsv, .xls, .xlsx</li>
<li>Maximum of 1000 lines per BOM</li>
</ul>
{% endblock %}
{% block form_data %}
<input type='hidden' name='form_step' value='select_file'/>
{% endblock %}

View File

@ -8,7 +8,9 @@
<h4>Upload Bill of Materials</h4>
<hr>
<p>The BOM file must contain the required named columns as provided in the <a href="/part/bom_template/">BOM Upload Template</a></a></p>
<div class='alert alert-info alert-block'>
<p>The BOM file must contain the required named columns as provided in the <a href="/part/bom_template/">BOM Upload Template</a></a></p>
</div>
<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
{% csrf_token %}

View File

@ -27,7 +27,7 @@ part_detail_urls = [
url(r'^make-variant/', views.MakePartVariant.as_view(), name='make-part-variant'),
url(r'^pricing/', views.PartPricing.as_view(), name='part-pricing'),
url(r'^bom-upload/?', views.BomUpload.as_view(template_name='part/bom_upload/upload_file.html'), name='upload-bom'),
url(r'^bom-upload/?', views.BomUpload.as_view(), name='upload-bom'),
url(r'^variants/?', views.PartDetail.as_view(template_name='part/variants.html'), name='part-variants'),
url(r'^stock/?', views.PartDetail.as_view(template_name='part/stock.html'), name='part-stock'),

View File

@ -647,7 +647,7 @@ class BomUpload(FormView):
During these steps, data are passed between the server/client as JSON objects.
"""
template_name = 'part/bom_upload/select_file.html'
template_name='part/bom_upload/upload_file.html'
def get_success_url(self):
part = self.get_object()
@ -715,16 +715,9 @@ class BomUpload(FormView):
for k, v in errors.items():
self.form.errors[k] = v
data = {
'form_valid': False
}
ctx = {}
if bom_file_valid:
if 0 and bom_file_valid:
# BOM file is valid? Proceed to the next step!
form = part_forms.BomUploadSelectFields
self.ajax_template_name = 'part/bom_upload/select_fields.html'
# Provide context to the next form
ctx = {
@ -734,8 +727,9 @@ class BomUpload(FormView):
}
else:
form = self.form
form.errors['bom_file'] = [_('no errors')]
return self.renderJsonResponse(self.request, form, data=data, context=ctx)
return self.render_to_response(self.get_context_data(form=form))
def handleFieldSelection(self):
""" Handle the output of the field selection form.
@ -855,7 +849,7 @@ class BomUpload(FormView):
self.request = request
self.part = get_object_or_404(Part, pk=self.kwargs['pk'])
self.form = self.get_form()
self.form = self.get_form(self.get_form_class())
# Did the user POST a file named bom_file?
@ -866,11 +860,7 @@ class BomUpload(FormView):
elif form_step == 'select_fields':
return self.handleFieldSelection()
data = {
'form_valid': False,
}
return self.renderJsonResponse(request, self.form, data=data)
return self.render_to_response(self.get_context_data(form=self.form))
class BomUploadTemplate(AjaxView):