Added HTML widget display template
authorThierry Florac <thierry.florac@onf.fr>
Mon, 18 Jan 2016 17:50:02 +0100
changeset 35 b7e425948ce2
parent 34 e1260ddb493e
child 36 8991b078bd3e
Added HTML widget display template
src/pyams_form/widget/__init__.py
src/pyams_form/widget/templates/html-display.pt
--- a/src/pyams_form/widget/__init__.py	Mon Jan 18 17:48:30 2016 +0100
+++ b/src/pyams_form/widget/__init__.py	Mon Jan 18 17:50:02 2016 +0100
@@ -26,13 +26,14 @@
 from pyams_skin.interfaces.tinymce import ITinyMCEConfiguration
 from pyams_utils.schema import IColorField, IHTMLField, ITextLineListField
 from pyramid.interfaces import IRequest
-from z3c.form.interfaces import INPUT_MODE, IFieldWidget, IButtonAction, IWidgetLayoutTemplate, IDataConverter
+from z3c.form.interfaces import INPUT_MODE, DISPLAY_MODE, IFieldWidget, IButtonAction, IWidgetLayoutTemplate, \
+    IDataConverter
 from zope.pagetemplate.interfaces import IPageTemplate
 from zope.schema.interfaces import IDate, IDatetime, ITime, IChoice
 
 # import packages
 from pyams_utils.adapter import adapter_config
-from pyams_utils.timezone import tztime, gmtime, localgmtime
+from pyams_utils.timezone import tztime, localgmtime
 from pyramid.exceptions import ConfigurationError
 from z3c.form.action import Action
 from z3c.form.browser.select import SelectWidget
@@ -151,8 +152,8 @@
 # Reset button widget and action
 #
 
-@widgettemplate_config(mode='input', template='templates/reset-input.pt', layer=IFormLayer)
-@widgettemplate_config(mode='display', template='templates/reset-display.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/reset-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/reset-display.pt', layer=IFormLayer)
 @implementer_only(IResetWidget)
 class ResetWidget(SubmitWidget):
     """A reset button of a form."""
@@ -182,8 +183,8 @@
 # Close button widget and action
 #
 
-@widgettemplate_config(mode='input', template='templates/close-input.pt', layer=IFormLayer)
-@widgettemplate_config(mode='display', template='templates/close-display.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/close-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/close-display.pt', layer=IFormLayer)
 @implementer_only(ICloseWidget)
 class CloseWidget(SubmitWidget):
     """A dialog close button"""
@@ -213,7 +214,7 @@
 # Date widget
 #
 
-@widgettemplate_config(mode='input', template='templates/date-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/date-input.pt', layer=IFormLayer)
 @implementer_only(IDateWidget)
 class DateWidget(TextWidget):
     """Date widget"""
@@ -241,7 +242,7 @@
         return localgmtime(value)
 
 
-@widgettemplate_config(mode='input', template='templates/datetime-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/datetime-input.pt', layer=IFormLayer)
 @implementer_only(IDatetimeWidget)
 class DatetimeWidget(TextWidget):
     """Datetime widget"""
@@ -256,7 +257,7 @@
 # Time widget
 #
 
-@widgettemplate_config(mode='input', template='templates/time-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/time-input.pt', layer=IFormLayer)
 @implementer_only(ITimeWidget)
 class TimeWidget(TextWidget):
     """Time widget"""
@@ -287,7 +288,7 @@
         return super(ColorDataConverter, self).toFieldValue(value)
 
 
-@widgettemplate_config(mode='input', template='templates/color-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/color-input.pt', layer=IFormLayer)
 @implementer_only(IColorWidget)
 class ColorWidget(TextWidget):
     """Color widget"""
@@ -302,7 +303,8 @@
 # HTML widget
 #
 
-@widgettemplate_config(mode='input', template='templates/html-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/html-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/html-display.pt', layer=IFormLayer)
 @implementer_only(IHTMLWidget)
 class HTMLWidget(TextAreaWidget):
     """HTML editor widget"""
@@ -332,7 +334,7 @@
 # Select2 widget
 #
 
-@widgettemplate_config(mode='input', template='templates/select-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/select-input.pt', layer=IFormLayer)
 @implementer_only(ISelect2Widget)
 class Select2Widget(SelectWidget):
     """Select2 widget"""
@@ -364,8 +366,8 @@
         return value.split('|') if value else None
 
 
-@widgettemplate_config(mode='input', template='templates/textlinelist-input.pt', layer=IFormLayer)
-@widgettemplate_config(mode='display', template='templates/textlinelist-display.pt', layer=IFormLayer)
+@widgettemplate_config(mode=INPUT_MODE, template='templates/textlinelist-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/textlinelist-display.pt', layer=IFormLayer)
 @implementer_only(ITextLineListWidget)
 class TextLineListWidget(TextWidget):
     """Text line list widget"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/html-display.pt	Mon Jan 18 17:50:02 2016 +0100
@@ -0,0 +1,2 @@
+<div class="html_content"
+	 tal:content="structure view/value"></div>