Create BOM export form

- Select output format
This commit is contained in:
Oliver Walters 2019-04-13 22:46:26 +10:00
parent 14de111130
commit b58c49e066
4 changed files with 40 additions and 7 deletions

View File

@ -127,7 +127,7 @@ class AjaxCreateView(AjaxMixin, CreateView):
if request.is_ajax():
form = self.form_class(initial=self.get_initial())
return self.renderJsonResponse(request, form=form, data=data, **kwargs)
return self.renderJsonResponse(request, form=form, **kwargs)
else:
return response

View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
from InvenTree.forms import HelperForm
from django import forms
from .models import Part, PartCategory, BomItem
from .models import SupplierPart
@ -16,6 +18,24 @@ class PartImageForm(HelperForm):
]
class BomExportForm(HelperForm):
# TODO - Define these choices somewhere else, and import them here
format_choices = (
('csv', 'CSV'),
('xlsx', 'XLSX'),
('pdf', 'PDF'),
)
# Select export type
format = forms.CharField(label='Format', widget=forms.Select(choices=format_choices), required='true', help_text='Select export format')
class Meta:
model = Part
fields = [
]
class EditPartForm(HelperForm):
class Meta:

View File

@ -1,3 +1,7 @@
Export BOM for {{ part.name }}
Export BOM (Bill of Materials) for {{ part.name }}
{% include "modal_csrf.html" %}
<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
{% csrf_token %}
{% load crispy_forms_tags %}
{% crispy form %}
</form>

View File

@ -15,6 +15,7 @@ from .forms import PartImageForm
from .forms import EditPartForm
from .forms import EditCategoryForm
from .forms import EditBomItemForm
from .forms import BomExportForm
from .forms import EditSupplierPartForm
@ -110,7 +111,7 @@ class PartEdit(AjaxUpdateView):
ajax_form_title = 'Edit Part Properties'
class BomExport(AjaxView):
class BomExport(AjaxUpdateView):
model = Part
form_class = BomExportForm
@ -118,19 +119,26 @@ class BomExport(AjaxView):
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'])
form = self.form_class(instance=part, data=request.POST, files=request.FILES)
return self.renderJsonResponse(request, context={'part': part})
return self.renderJsonResponse(request, form=form, context={'part': part})
def post(self, request, *args, **kwargs):
part = get_object_or_404(Part, pk=self.kwargs['pk'])
form = self.form_class(instance=part, data=request.POST, files=request.FILES)
return self.renderJsonResponse(request, context={'part': part})
export_format = request.POST.get('format', None)
if not export_format:
# TODO
pass
return self.renderJsonResponse(request, form=form, context={'part': part})
def get_data(self):
return {
@ -227,6 +235,7 @@ class BomItemCreate(AjaxCreateView):
template_name = 'part/bom-create.html'
ajax_template_name = 'modal_form.html'
ajax_form_title = 'Create BOM item'
ajax_submit_text = 'Create'
def get_initial(self):
# Look for initial values