mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-13 18:43:08 +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 = [
|
fields = [
|
||||||
'value'
|
'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'))
|
form.add_error('value', _('Supplied value must be a boolean'))
|
||||||
|
|
||||||
|
|
||||||
class FileUploadWizardView(SessionWizardView):
|
class MultiStepFormView(SessionWizardView):
|
||||||
# file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'file_uploads'))
|
""" Setup basic methods of multi-step form
|
||||||
form_list = [
|
|
||||||
forms.UploadFile,
|
form_list: list of forms
|
||||||
forms.MatchField,
|
form_steps_description: description for each form
|
||||||
forms.MatchPart,
|
"""
|
||||||
]
|
|
||||||
|
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',
|
'line',
|
||||||
'item',
|
'item',
|
||||||
'quantity']
|
'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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block heading %}
|
{% block heading %}
|
||||||
|
{% trans "Upload File for Purchase Order" %}
|
||||||
{{ wizard.form.media }}
|
{{ wizard.form.media }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block details %}
|
{% 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 %}
|
<form action="" method="post">{% csrf_token %}
|
||||||
<table>
|
<table>
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
{{ wizard.management_form }}
|
{{ wizard.management_form }}
|
||||||
{% if wizard.form.forms %}
|
{% if wizard.form.forms %}
|
||||||
{{ wizard.form.management_form }}
|
{{ wizard.form.management_form }}
|
||||||
{% for form in wizard.form.forms %}
|
{% for form in wizard.form.forms %}
|
||||||
{{ form }}
|
{% crispy form %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ wizard.form }}
|
{% crispy wizard.form %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
{% if wizard.steps.prev %}
|
{% 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 %}
|
{% endif %}
|
||||||
<input type="submit" value="{% trans "submit" %}"/>
|
<button type="submit" class="save btn btn-default">{% trans "Submit" %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -28,7 +28,7 @@ from stock.models import StockItem, StockLocation
|
|||||||
from part.models import Part
|
from part.models import Part
|
||||||
|
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from common.views import FileUploadWizardView
|
from common.views import MultiStepFormView
|
||||||
|
|
||||||
from . import forms as order_forms
|
from . import forms as order_forms
|
||||||
|
|
||||||
@ -566,10 +566,21 @@ class SalesOrderShip(AjaxUpdateView):
|
|||||||
return self.renderJsonResponse(request, form, data, context)
|
return self.renderJsonResponse(request, form, data, context)
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderUpload(FileUploadWizardView):
|
class PurchaseOrderUpload(MultiStepFormView):
|
||||||
''' Upload File Wizard View '''
|
''' 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"
|
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):
|
def get_context_data(self, form, **kwargs):
|
||||||
context = super().get_context_data(form=form, **kwargs)
|
context = super().get_context_data(form=form, **kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user