mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Bugfix: Turns out 'prefix' and 'suffix' were protected fields!
This commit is contained in:
parent
08d177e55f
commit
498ad4162c
@ -8,7 +8,7 @@ from __future__ import unicode_literals
|
||||
from django import forms
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Layout, Field
|
||||
from crispy_forms.bootstrap import PrependedAppendedText
|
||||
from crispy_forms.bootstrap import PrependedText, AppendedText, PrependedAppendedText
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
@ -16,9 +16,9 @@ class HelperForm(forms.ModelForm):
|
||||
""" Provides simple integration of crispy_forms extension. """
|
||||
|
||||
# Custom field decorations can be specified here, per form class
|
||||
prefix = {}
|
||||
suffix = {}
|
||||
placeholder = {}
|
||||
field_prefix = {}
|
||||
field_suffix = {}
|
||||
field_placeholder = {}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(forms.ModelForm, self).__init__(*args, **kwargs)
|
||||
@ -37,18 +37,18 @@ class HelperForm(forms.ModelForm):
|
||||
layouts = []
|
||||
|
||||
for field in self.fields:
|
||||
prefix = self.prefix.get(field, None)
|
||||
suffix = self.suffix.get(field, None)
|
||||
placeholder = self.placeholder.get(field, '')
|
||||
prefix = self.field_prefix.get(field, None)
|
||||
suffix = self.field_suffix.get(field, None)
|
||||
placeholder = self.field_placeholder.get(field, '')
|
||||
|
||||
# Look for font-awesome icons
|
||||
if prefix and prefix.startswith('fa-'):
|
||||
prefix = "<span class='fas {fa}'></span>".format(fa=prefix)
|
||||
prefix = r"<i class='fas {fa}'/>".format(fa=prefix)
|
||||
|
||||
if suffix and suffix.startswith('fa-'):
|
||||
suffix = "<span class='fas {fa}'></span>".format(fa=suffix)
|
||||
suffix = r"<i class='fas {fa}'/>".format(fa=suffix)
|
||||
|
||||
if prefix or suffix or placeholder:
|
||||
if prefix and suffix:
|
||||
layouts.append(
|
||||
Field(
|
||||
PrependedAppendedText(
|
||||
@ -60,8 +60,30 @@ class HelperForm(forms.ModelForm):
|
||||
)
|
||||
)
|
||||
|
||||
elif prefix:
|
||||
layouts.append(
|
||||
Field(
|
||||
PrependedText(
|
||||
field,
|
||||
prefix,
|
||||
placeholder=placeholder
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
elif suffix:
|
||||
layouts.append(
|
||||
Field(
|
||||
AppendedText(
|
||||
field,
|
||||
suffix,
|
||||
placeholder=placeholder
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
else:
|
||||
layouts.append(Field(field))
|
||||
layouts.append(Field(field, placeholder=placeholder))
|
||||
|
||||
self.helper.layout = Layout(*layouts)
|
||||
|
||||
|
@ -93,12 +93,12 @@ class EditPurchaseOrderForm(HelperForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
self.prefix = {
|
||||
self.field_prefix = {
|
||||
'reference': 'PO',
|
||||
'link': 'fa-link',
|
||||
}
|
||||
|
||||
self.placeholder = {
|
||||
self.field_placeholder = {
|
||||
'reference': _('Enter purchase order number'),
|
||||
}
|
||||
|
||||
@ -120,12 +120,12 @@ class EditSalesOrderForm(HelperForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
self.prefix = {
|
||||
self.field_prefix = {
|
||||
'reference': 'SO',
|
||||
'link': 'fa-link',
|
||||
}
|
||||
|
||||
self.placeholder = {
|
||||
self.field_placeholder = {
|
||||
'reference': _('Enter sales order number'),
|
||||
}
|
||||
|
||||
|
@ -108,11 +108,11 @@ class SerializeStockForm(HelperForm):
|
||||
else:
|
||||
sn = str(sn)
|
||||
|
||||
self.prefix = {
|
||||
self.field_prefix = {
|
||||
'serial_numbers': 'fa-hashtag',
|
||||
}
|
||||
|
||||
self.placeholder = {
|
||||
self.field_placeholder = {
|
||||
'serial_numbers': sn
|
||||
}
|
||||
|
||||
|
@ -717,7 +717,7 @@ class StockItemEdit(AjaxUpdateView):
|
||||
query = query.filter(part=item.part.id)
|
||||
form.fields['supplier_part'].queryset = query
|
||||
|
||||
if not item.part.trackable:
|
||||
if not item.part.trackable or not item.serialized:
|
||||
form.fields.pop('serial')
|
||||
|
||||
return form
|
||||
|
Loading…
Reference in New Issue
Block a user