Merge pull request #805 from SchrodingersGat/form-candy

Form candy
This commit is contained in:
Oliver 2020-05-14 21:56:55 +10:00 committed by GitHub
commit 5b5b848a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from __future__ import unicode_literals
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout
from django.contrib.auth.models import User
@ -19,6 +20,16 @@ class HelperForm(forms.ModelForm):
self.helper.form_tag = False
"""
Create a default 'layout' for this form.
Ref: https://django-crispy-forms.readthedocs.io/en/latest/layouts.html
This is required to do fancy things later (like adding PrependedText, etc).
Simply create a 'blank' layout for each available field.
"""
self.helper.layout = Layout(*self.fields.keys())
class DeleteForm(forms.Form):
""" Generic deletion form which provides simple user confirmation

View File

@ -341,7 +341,7 @@ if DEBUG:
print("STATIC_ROOT:", STATIC_ROOT)
# crispy forms use the bootstrap templates
CRISPY_TEMPLATE_PACK = 'bootstrap'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# Use database transactions when importing / exporting data
IMPORT_EXPORT_USE_TRANSACTIONS = True

View File

@ -8,6 +8,9 @@ from __future__ import unicode_literals
from django import forms
from django.utils.translation import ugettext as _
from crispy_forms.layout import Field, Layout
from crispy_forms.bootstrap import PrependedText
from mptt.fields import TreeNodeChoiceField
from InvenTree.forms import HelperForm
@ -88,6 +91,23 @@ class ReceivePurchaseOrderForm(HelperForm):
class EditPurchaseOrderForm(HelperForm):
""" Form for editing a PurchaseOrder object """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# TODO - Refactor this?
self.helper.layout = Layout(
Field(PrependedText(
'reference',
'PO',
placeholder=_("Purchase Order")
)),
Field('supplier'),
Field('supplier_reference'),
Field('description'),
Field('link'),
)
class Meta:
model = PurchaseOrder
fields = [
@ -102,6 +122,23 @@ class EditPurchaseOrderForm(HelperForm):
class EditSalesOrderForm(HelperForm):
""" Form for editing a SalesOrder object """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# TODO - Refactor?
self.helper.layout = Layout(
Field(PrependedText(
'reference',
'SO',
placeholder=_("Sales Order")
)),
Field('customer'),
Field('customer_reference'),
Field('description'),
Field('link'),
)
class Meta:
model = SalesOrder
fields = [