mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added step description and crispy form tag
This commit is contained in:
parent
b847604f15
commit
373898d43e
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
@ -9,29 +9,32 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
{% trans "Upload File for Purchase Order" %}
|
||||
{{ wizard.form.media }}
|
||||
{% endblock %}
|
||||
|
||||
{% block details %}
|
||||
|
||||
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
|
||||
<p>{% trans "Step" %} {{ wizard.steps.step1 }} {% trans "of" %} {{ wizard.steps.count }}
|
||||
{% if description %}- {{ description }}{% endif %}</p>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<table>
|
||||
{% 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 %}
|
||||
</table>
|
||||
{% if wizard.steps.prev %}
|
||||
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "first step" %}</button>
|
||||
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
|
||||
|
||||
<button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}" class="save btn btn-default">{% trans "Previous Step" %}</button>
|
||||
{% endif %}
|
||||
<input type="submit" value="{% trans "submit" %}"/>
|
||||
<button type="submit" class="save btn btn-default">{% trans "Submit" %}</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user