Updated data converters
authorThierry Florac <tflorac@ulthar.net>
Tue, 08 Oct 2019 17:14:12 +0200
changeset 480 b55212e53cdb
parent 479 ec9b65ea4c08
child 481 b523fbdb0081
Updated data converters
src/pyams_default_theme/shared/form/widget.py
--- a/src/pyams_default_theme/shared/form/widget.py	Mon Oct 07 14:02:36 2019 +0200
+++ b/src/pyams_default_theme/shared/form/widget.py	Tue Oct 08 17:14:12 2019 +0200
@@ -18,13 +18,11 @@
 from pyams_content.shared.form.interfaces import IFormFieldDataConverter
 from pyams_skin.layer import IPyAMSUserLayer
 from pyams_utils.adapter import ContextRequestAdapter, adapter_config
-from pyams_utils.date import SH_DATE_FORMAT, format_date
+from pyams_utils.date import EXT_DATE_FORMAT, format_date
 
 
 __docformat__ = 'restructuredtext'
 
-from pyams_default_theme import _
-
 
 @adapter_config(context=(IBool, IPyAMSUserLayer), provides=IFieldWidget)
 def BooleanFieldWidget(field, request):
@@ -36,23 +34,25 @@
     """Boolean field user data converter"""
 
     def convert(self, value):
-        return self.request.localizer.translate(_("yes") if value else _("no"))
+        return self.context.description if value else '--'
 
 
 @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)
+    @staticmethod
+    def convert(value):
+        return format_date(value, EXT_DATE_FORMAT) if value else '--'
 
 
 @adapter_config(context=(IDecimal, IPyAMSUserLayer), provides=IFormFieldDataConverter)
 class DecimalFieldDataConverter(ContextRequestAdapter):
     """Decimal field user data converter"""
 
-    def convert(self, value):
-        return str(value)
+    @staticmethod
+    def convert(value):
+        return str(value) if value else '--'
 
 
 @adapter_config(context=(IList, IPyAMSUserLayer), provides=IFormFieldDataConverter)
@@ -61,4 +61,4 @@
 
     @staticmethod
     def convert(value):
-        return ', '.join(value) if value is not None else '--'
+        return ' / '.join(value) if value is not None else '--'