From 373898d43e777f1d33c1644b6b53498f54e57c1a Mon Sep 17 00:00:00 2001 From: eeintech Date: Tue, 4 May 2021 10:28:00 -0400 Subject: [PATCH] Added step description and crispy form tag --- InvenTree/common/forms.py | 15 ---------- InvenTree/common/views.py | 29 ++++++++++++++----- InvenTree/order/forms.py | 15 ++++++++++ .../order/templates/order/po_upload.html | 15 ++++++---- InvenTree/order/views.py | 17 +++++++++-- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/InvenTree/common/forms.py b/InvenTree/common/forms.py index 0ca98ad76a..f4ff082019 100644 --- a/InvenTree/common/forms.py +++ b/InvenTree/common/forms.py @@ -23,18 +23,3 @@ class SettingEditForm(HelperForm): fields = [ 'value' ] - - -class UploadFile(forms.Form): - ''' Step 1 ''' - first_name = forms.CharField(max_length=100) - - -class MatchField(forms.Form): - ''' Step 2 ''' - last_name = forms.CharField(max_length=100) - - -class MatchPart(forms.Form): - ''' Step 3 ''' - age = forms.IntegerField() diff --git a/InvenTree/common/views.py b/InvenTree/common/views.py index f25760990e..056cbec32b 100644 --- a/InvenTree/common/views.py +++ b/InvenTree/common/views.py @@ -105,10 +105,25 @@ class SettingEdit(AjaxUpdateView): form.add_error('value', _('Supplied value must be a boolean')) -class FileUploadWizardView(SessionWizardView): - # file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'file_uploads')) - form_list = [ - forms.UploadFile, - forms.MatchField, - forms.MatchPart, - ] +class MultiStepFormView(SessionWizardView): + """ Setup basic methods of multi-step form + + form_list: list of forms + form_steps_description: description for each form + """ + + form_list = [] + form_steps_description = [] + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + # Get description + try: + description = self.form_steps_description[int(self.steps.current)] + except IndexError: + description = '' + # Add description to form steps + context.update({'description': description}) + + return context + \ No newline at end of file diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 4c9caf3b53..b5b1aa2c96 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -284,3 +284,18 @@ class EditSalesOrderAllocationForm(HelperForm): 'line', 'item', 'quantity'] + + +class UploadFile(forms.Form): + ''' Step 1 ''' + first_name = forms.CharField(max_length=100) + + +class MatchField(forms.Form): + ''' Step 2 ''' + last_name = forms.CharField(max_length=100) + + +class MatchPart(forms.Form): + ''' Step 3 ''' + age = forms.IntegerField() \ No newline at end of file diff --git a/InvenTree/order/templates/order/po_upload.html b/InvenTree/order/templates/order/po_upload.html index b221800d3c..8563b70ff5 100644 --- a/InvenTree/order/templates/order/po_upload.html +++ b/InvenTree/order/templates/order/po_upload.html @@ -9,29 +9,32 @@ {% endblock %} {% block heading %} +{% trans "Upload File for Purchase Order" %} {{ wizard.form.media }} {% endblock %} {% block details %} -

Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}

+

{% trans "Step" %} {{ wizard.steps.step1 }} {% trans "of" %} {{ wizard.steps.count }} +{% if description %}- {{ description }}{% endif %}

{% csrf_token %} +{% load crispy_forms_tags %} {{ wizard.management_form }} {% if wizard.form.forms %} {{ wizard.form.management_form }} {% for form in wizard.form.forms %} - {{ form }} + {% crispy form %} {% endfor %} {% else %} - {{ wizard.form }} + {% crispy wizard.form %} {% endif %}
{% if wizard.steps.prev %} - - + + {% endif %} - +
{% endblock %} diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index d221f7bc02..92f5d54c33 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -28,7 +28,7 @@ from stock.models import StockItem, StockLocation from part.models import Part from common.models import InvenTreeSetting -from common.views import FileUploadWizardView +from common.views import MultiStepFormView from . import forms as order_forms @@ -566,10 +566,21 @@ class SalesOrderShip(AjaxUpdateView): return self.renderJsonResponse(request, form, data, context) -class PurchaseOrderUpload(FileUploadWizardView): - ''' Upload File Wizard View ''' +class PurchaseOrderUpload(MultiStepFormView): + ''' PurchaseOrder: Upload file and match to parts, using multi-Step form ''' + form_list = [ + order_forms.UploadFile, + order_forms.MatchField, + order_forms.MatchPart, + ] + form_steps_description = [ + _("Upload File"), + _("Select Fields"), + _("Select Parts"), + ] template_name = "order/po_upload.html" + # file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'file_uploads')) def get_context_data(self, form, **kwargs): context = super().get_context_data(form=form, **kwargs)