src/pyams_default_theme/shared/form/widget.py
changeset 477 bf471dbff9b0
parent 470 3219fd0a7366
child 480 b55212e53cdb
--- a/src/pyams_default_theme/shared/form/widget.py	Mon Oct 07 13:44:25 2019 +0200
+++ b/src/pyams_default_theme/shared/form/widget.py	Mon Oct 07 13:45:40 2019 +0200
@@ -13,11 +13,12 @@
 from z3c.form.browser.checkbox import SingleCheckBoxWidget
 from z3c.form.interfaces import IFieldWidget
 from z3c.form.widget import FieldWidget
-from zope.schema.interfaces import IBool, IList
+from zope.schema.interfaces import IBool, IDate, IDecimal, IList
 
 from pyams_content.shared.form.interfaces import IFormFieldDataConverter
 from pyams_skin.layer import IPyAMSUserLayer
-from pyams_utils.adapter import adapter_config, ContextRequestAdapter
+from pyams_utils.adapter import ContextRequestAdapter, adapter_config
+from pyams_utils.date import SH_DATE_FORMAT, format_date
 
 
 __docformat__ = 'restructuredtext'
@@ -38,6 +39,22 @@
         return self.request.localizer.translate(_("yes") if value else _("no"))
 
 
+@adapter_config(context=(IDate, IPyAMSUserLayer), provides=IFormFieldDataConverter)
+class DateFieldDataConverter(ContextRequestAdapter):
+    """Date field user data converter"""
+
+    def convert(self, value):
+        return format_date(value, SH_DATE_FORMAT)
+
+
+@adapter_config(context=(IDecimal, IPyAMSUserLayer), provides=IFormFieldDataConverter)
+class DecimalFieldDataConverter(ContextRequestAdapter):
+    """Decimal field user data converter"""
+
+    def convert(self, value):
+        return str(value)
+
+
 @adapter_config(context=(IList, IPyAMSUserLayer), provides=IFormFieldDataConverter)
 class ListFieldDataConverter(ContextRequestAdapter):
     """List field user data converter"""