Fix multi-file upload widget bug

happened when only one file was being uploaded
This commit is contained in:
Lance Edgar 2023-02-10 12:40:23 -06:00
parent 2d2c94e4d7
commit 8fc3a71e0f

View file

@ -24,14 +24,10 @@
Form Widgets
"""
from __future__ import unicode_literals, absolute_import, division
import json
import datetime
import decimal
import six
import colander
from deform import widget as dfwidget
from webhelpers2.html import tags, HTML
@ -86,7 +82,7 @@ class PercentInputWidget(dfwidget.TextInputWidget):
# convert "traditional" value to "human-friendly"
value = decimal.Decimal(cstruct) * 100
value = value.quantize(decimal.Decimal('0.001'))
cstruct = six.text_type(value)
cstruct = str(value)
return super(PercentInputWidget, self).serialize(field, cstruct, **kw)
def deserialize(self, field, pstruct):
@ -100,7 +96,7 @@ class PercentInputWidget(dfwidget.TextInputWidget):
raise colander.Invalid(field.schema, "Invalid decimal string: {}".format(pstruct))
value = value.quantize(decimal.Decimal('0.00001'))
value /= 100
return six.text_type(value)
return str(value)
class CasesUnitsWidget(dfwidget.Widget):
@ -301,7 +297,7 @@ class MultiFileUploadWidget(dfwidget.FileUploadWidget):
return colander.null
# 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
files_data = []
@ -416,7 +412,7 @@ class CustomerAutocompleteWidget(JQueryAutocompleteWidget):
model = self.request.rattail_config.get_model()
customer = Session.query(model.Customer).get(cstruct)
if customer:
self.field_display = six.text_type(customer)
self.field_display = str(customer)
return super(CustomerAutocompleteWidget, self).serialize(
field, cstruct, **kw)
@ -469,7 +465,7 @@ class DepartmentWidget(dfwidget.SelectWidget):
model = request.rattail_config.get_model()
departments = Session.query(model.Department)\
.order_by(model.Department.number)
values = [(dept.uuid, six.text_type(dept))
values = [(dept.uuid, str(dept))
for dept in departments]
if not kwargs.pop('required', True):
values.insert(0, ('', "(none)"))