diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index a80bfd3dee..596ad57556 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -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 diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index d0ad7571be..294da2f114 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -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: diff --git a/InvenTree/part/templates/part/bom_export.html b/InvenTree/part/templates/part/bom_export.html index 8be56f2dbc..5482284cd7 100644 --- a/InvenTree/part/templates/part/bom_export.html +++ b/InvenTree/part/templates/part/bom_export.html @@ -1,3 +1,7 @@ -Export BOM for {{ part.name }} +Export BOM (Bill of Materials) for {{ part.name }} -{% include "modal_csrf.html" %} \ No newline at end of file +
\ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d7c77947d7..6463352d88 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -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