# HG changeset patch # User Thierry Florac # Date 1570189028 -7200 # Node ID 893cf20888186abeb5a33f9a188836f6d81985e1 # Parent e4b68da720e25f53be112f4292f78b23d0cc643e Added widget adapter for decimal fields diff -r e4b68da720e2 -r 893cf2088818 src/pyams_form/widget/__init__.py --- a/src/pyams_form/widget/__init__.py Fri Oct 04 12:54:42 2019 +0200 +++ b/src/pyams_form/widget/__init__.py Fri Oct 04 13:37:08 2019 +0200 @@ -36,7 +36,7 @@ from zope.pagetemplate.interfaces import IPageTemplate from zope.schema.fieldproperty import FieldProperty from zope.schema.interfaces import IBytes, IChoice, IDate, IDatetime, IFloat, IInt, IList, ISet, \ - ITime, ITuple + ITime, ITuple, IDecimal from pyams_form.interfaces.form import IActionWidget, ICloseWidget, IColorWidget, IDateWidget, \ IDatetimeWidget, IFloatWidget, IFormLayer, IHTMLWidget, IIntegerWidget, IJSONDictWidget, \ @@ -348,7 +348,7 @@ try: return locale.atoi(value) except ValueError: - raise FormatterValidationError(self.errorMessage, value) + raise FormatterValidationError(self.error_message, value) @widgettemplate_config(mode=INPUT_MODE, template='templates/integer-input.pt', layer=IFormLayer) @@ -362,13 +362,12 @@ allow_negative = True if (self.field.min is not None) and (self.field.min >= 0): allow_negative = False - rules = {'pattern': '{}[\d{}]+{}'.format('\{}?'.format(conv.get('negative_sign', '-')) - if (allow_negative and - (conv.get('n_sign_posn') in SIGN_BEFORE_VALUE)) else '', - conv.get('thousands_sep', ''), - '\{}?'.format(conv.get('negative_sign', '-')) - if (allow_negative and - (conv.get('n_sign_posn') in SIGN_AFTER_VALUE)) else '')} + rules = {'pattern': '{}[\d{}]+{}'.format( + '\{}?'.format(conv.get('negative_sign', '-')) + if (allow_negative and (conv.get('n_sign_posn') in SIGN_BEFORE_VALUE)) else '', + conv.get('thousands_sep', ''), + '\{}?'.format(conv.get('negative_sign', '-')) + if (allow_negative and (conv.get('n_sign_posn') in SIGN_AFTER_VALUE)) else '')} return json.dumps(rules) @@ -414,18 +413,18 @@ allow_negative = True if (self.field.min is not None) and (self.field.min >= 0): allow_negative = False - rules = {'pattern': '{}[\d{}]+{}?\d*{}'.format('\{}?'.format(conv.get('negative_sign', '-')) - if (allow_negative and - (conv.get('n_sign_posn') in SIGN_BEFORE_VALUE)) else '', - conv.get('thousands_sep', ''), - conv.get('decimal_point', '\.'), - '\{}?'.format(conv.get('negative_sign', '-')) - if (allow_negative and - (conv.get('n_sign_posn') in SIGN_AFTER_VALUE)) else '')} + rules = {'pattern': '{}[\d{}]+{}?\d*{}'.format( + '\{}?'.format(conv.get('negative_sign', '-')) + if (allow_negative and (conv.get('n_sign_posn') in SIGN_BEFORE_VALUE)) else '', + conv.get('thousands_sep', ''), + conv.get('decimal_point', '\.'), + '\{}?'.format(conv.get('negative_sign', '-')) + if (allow_negative and (conv.get('n_sign_posn') in SIGN_AFTER_VALUE)) else '')} return json.dumps(rules) @adapter_config(context=(IFloat, IFormLayer), provides=IFieldWidget) +@adapter_config(context=(IDecimal, IFormLayer), provides=IFieldWidget) def FloatFieldWidget(field, request): return FieldWidget(field, FloatWidget(request))