Fix multi-file upload widget bug
happened when only one file was being uploaded
This commit is contained in:
parent
2d2c94e4d7
commit
8fc3a71e0f
|
@ -24,14 +24,10 @@
|
||||||
Form Widgets
|
Form Widgets
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import, division
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
from deform import widget as dfwidget
|
from deform import widget as dfwidget
|
||||||
from webhelpers2.html import tags, HTML
|
from webhelpers2.html import tags, HTML
|
||||||
|
@ -86,7 +82,7 @@ class PercentInputWidget(dfwidget.TextInputWidget):
|
||||||
# convert "traditional" value to "human-friendly"
|
# convert "traditional" value to "human-friendly"
|
||||||
value = decimal.Decimal(cstruct) * 100
|
value = decimal.Decimal(cstruct) * 100
|
||||||
value = value.quantize(decimal.Decimal('0.001'))
|
value = value.quantize(decimal.Decimal('0.001'))
|
||||||
cstruct = six.text_type(value)
|
cstruct = str(value)
|
||||||
return super(PercentInputWidget, self).serialize(field, cstruct, **kw)
|
return super(PercentInputWidget, self).serialize(field, cstruct, **kw)
|
||||||
|
|
||||||
def deserialize(self, field, pstruct):
|
def deserialize(self, field, pstruct):
|
||||||
|
@ -100,7 +96,7 @@ class PercentInputWidget(dfwidget.TextInputWidget):
|
||||||
raise colander.Invalid(field.schema, "Invalid decimal string: {}".format(pstruct))
|
raise colander.Invalid(field.schema, "Invalid decimal string: {}".format(pstruct))
|
||||||
value = value.quantize(decimal.Decimal('0.00001'))
|
value = value.quantize(decimal.Decimal('0.00001'))
|
||||||
value /= 100
|
value /= 100
|
||||||
return six.text_type(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
class CasesUnitsWidget(dfwidget.Widget):
|
class CasesUnitsWidget(dfwidget.Widget):
|
||||||
|
@ -301,7 +297,7 @@ class MultiFileUploadWidget(dfwidget.FileUploadWidget):
|
||||||
return colander.null
|
return colander.null
|
||||||
|
|
||||||
# TODO: why is this a thing? pstruct == [b'']
|
# TODO: why is this a thing? pstruct == [b'']
|
||||||
if len(pstruct) == 1 and not pstruct[0]:
|
if len(pstruct) == 1 and pstruct[0] == b'':
|
||||||
return colander.null
|
return colander.null
|
||||||
|
|
||||||
files_data = []
|
files_data = []
|
||||||
|
@ -416,7 +412,7 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
|
||||||
model = self.request.rattail_config.get_model()
|
model = self.request.rattail_config.get_model()
|
||||||
customer = Session.query(model.Customer).get(cstruct)
|
customer = Session.query(model.Customer).get(cstruct)
|
||||||
if customer:
|
if customer:
|
||||||
self.field_display = six.text_type(customer)
|
self.field_display = str(customer)
|
||||||
|
|
||||||
return super(CustomerAutocompleteWidget, self).serialize(
|
return super(CustomerAutocompleteWidget, self).serialize(
|
||||||
field, cstruct, **kw)
|
field, cstruct, **kw)
|
||||||
|
@ -469,7 +465,7 @@ class DepartmentWidget(dfwidget.SelectWidget):
|
||||||
model = request.rattail_config.get_model()
|
model = request.rattail_config.get_model()
|
||||||
departments = Session.query(model.Department)\
|
departments = Session.query(model.Department)\
|
||||||
.order_by(model.Department.number)
|
.order_by(model.Department.number)
|
||||||
values = [(dept.uuid, six.text_type(dept))
|
values = [(dept.uuid, str(dept))
|
||||||
for dept in departments]
|
for dept in departments]
|
||||||
if not kwargs.pop('required', True):
|
if not kwargs.pop('required', True):
|
||||||
values.insert(0, ('', "(none)"))
|
values.insert(0, ('', "(none)"))
|
||||||
|
|
Loading…
Reference in a new issue