Added date, datetime and time widgets and templates
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Mar 2015 11:57:31 +0100
changeset 7 51b8d68d9c4d
parent 6 601da9b11b67
child 8 299f3f455f4f
Added date, datetime and time widgets and templates
src/pyams_form/interfaces/form.py
src/pyams_form/widget/__init__.py
src/pyams_form/widget/templates/date-input.pt
src/pyams_form/widget/templates/datetime-input.pt
src/pyams_form/widget/templates/time-input.pt
--- a/src/pyams_form/interfaces/form.py	Wed Mar 11 11:57:04 2015 +0100
+++ b/src/pyams_form/interfaces/form.py	Wed Mar 11 11:57:31 2015 +0100
@@ -17,7 +17,7 @@
 # import interfaces
 from pyams_viewlet.interfaces import IViewletManager
 from pyramid.interfaces import IView
-from z3c.form.interfaces import INPUT_MODE, ISubForm, IWidget, IFormLayer as IBaseFormLayer, ISubmitWidget
+from z3c.form.interfaces import INPUT_MODE, ISubForm, IWidget, IFormLayer as IBaseFormLayer, ISubmitWidget, ITextWidget
 from zope.interface.interfaces import IObjectEvent, ObjectEvent
 from zope.lifecycleevent.interfaces import IObjectCreatedEvent, IObjectModifiedEvent
 from zope.schema.interfaces import IField
@@ -382,7 +382,7 @@
 
 
 #
-# Form buttons widgets
+# Form custom widgets
 #
 
 class IResetWidget(ISubmitWidget):
@@ -393,6 +393,18 @@
     """Close button widget interface"""
 
 
+class IDateWidget(ITextWidget):
+    """Date widget interface"""
+
+
+class IDatetimeWidget(ITextWidget):
+    """Datetime widget interface"""
+
+
+class ITimeWidget(ITextWidget):
+    """Time widget interface"""
+
+
 #
 # Form events
 #
--- a/src/pyams_form/widget/__init__.py	Wed Mar 11 11:57:04 2015 +0100
+++ b/src/pyams_form/widget/__init__.py	Wed Mar 11 11:57:31 2015 +0100
@@ -19,17 +19,19 @@
 import venusian
 
 # import interfaces
-from pyams_form.interfaces.form import IFormLayer, IResetWidget, ICloseWidget
+from pyams_form.interfaces.form import IFormLayer, IResetWidget, ICloseWidget, IDateWidget, IDatetimeWidget, ITimeWidget
 from pyams_form.schema import IResetButton, ICloseButton
 from pyramid.interfaces import IRequest
 from z3c.form.interfaces import INPUT_MODE, IFieldWidget, IButtonAction, IWidgetLayoutTemplate
 from zope.pagetemplate.interfaces import IPageTemplate
+from zope.schema.interfaces import IDate, IDatetime, ITime
 
 # import packages
 from pyams_utils.adapter import adapter_config
 from pyramid.exceptions import ConfigurationError
 from z3c.form.action import Action
 from z3c.form.browser.submit import SubmitWidget
+from z3c.form.browser.text import TextWidget
 from z3c.form.button import ButtonAction
 from z3c.form.widget import FieldWidget, WidgetTemplateFactory, WidgetLayoutFactory
 from zope.interface import implementer_only, directlyProvides, Interface
@@ -195,3 +197,48 @@
         Action.__init__(self, request, field.title)
         CloseWidget.__init__(self, request)
         self.field = field
+
+
+#
+# Date widget
+#
+
+@widgettemplate_config(mode='input', template='templates/date-input.pt', layer=IFormLayer)
+@implementer_only(IDateWidget)
+class DateWidget(TextWidget):
+    """Date widget"""
+
+
+@adapter_config(context=(IDate, IFormLayer), provides=IFieldWidget)
+def DateFieldWidget(field, request):
+    return FieldWidget(field, DateWidget(request))
+
+
+#
+# Datetime widget
+#
+
+@widgettemplate_config(mode='input', template='templates/datetime-input.pt', layer=IFormLayer)
+@implementer_only(IDatetimeWidget)
+class DatetimeWidget(TextWidget):
+    """Datetime widget"""
+
+
+@adapter_config(context=(IDatetime, IFormLayer), provides=IFieldWidget)
+def DatetimeFieldWidget(field, request):
+    return FieldWidget(field, DatetimeWidget(request))
+
+
+#
+# Time widget
+#
+
+@widgettemplate_config(mode='input', template='templates/time-input.pt', layer=IFormLayer)
+@implementer_only(ITimeWidget)
+class TimeWidget(TextWidget):
+    """Time widget"""
+
+
+@adapter_config(context=(ITime, IFormLayer), provides=IFieldWidget)
+def TimeFieldWidget(field, request):
+    return FieldWidget(field, TimeWidget(request))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/date-input.pt	Wed Mar 11 11:57:31 2015 +0100
@@ -0,0 +1,37 @@
+<tal:var i18n:domain="pyams_form">
+	<i class="icon-append fa fa-calendar"></i>
+	<input id="" name="" class="" title="" lang="" disabled=""
+		   readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
+		   style="" value="" type="text"
+		   data-ams-datepicker-format="dd/mm/y"
+			tal:attributes="id view/id;
+							name view/name;
+							class string:${view/klass} datepicker;
+							style view/style;
+							title view/title;
+							lang view/lang;
+							onclick view/onclick;
+							ondblclick view/ondblclick;
+							onmousedown view/onmousedown;
+							onmouseup view/onmouseup;
+							onmouseover view/onmouseover;
+							onmousemove view/onmousemove;
+							onmouseout view/onmouseout;
+							onkeypress view/onkeypress;
+							onkeydown view/onkeydown;
+							onkeyup view/onkeyup;
+							value view/value;
+							disabled view/disabled;
+							tabindex view/tabindex;
+							onfocus view/onfocus;
+							onblur view/onblur;
+							onchange view/onchange;
+							readonly view/readonly;
+							alt view/alt;
+							accesskey view/accesskey;
+							onselect view/onselect;
+							size view/size;
+							maxlength view/maxlength;
+							placeholder view/placeholder;
+							autocapitalize view/autocapitalize;" />
+</tal:var>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/datetime-input.pt	Wed Mar 11 11:57:31 2015 +0100
@@ -0,0 +1,37 @@
+<tal:var i18n:domain="pyams_form">
+	<i class="icon-append fa fa-calendar"></i>
+	<input id="" name="" class="" title="" lang="" disabled=""
+		   readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
+		   style="" value="" type="text"
+		   data-ams-datepicker-format="dd/mm/y"
+			tal:attributes="id view/id;
+							name view/name;
+							class string:${view/klass} datetimepicker;
+							style view/style;
+							title view/title;
+							lang view/lang;
+							onclick view/onclick;
+							ondblclick view/ondblclick;
+							onmousedown view/onmousedown;
+							onmouseup view/onmouseup;
+							onmouseover view/onmouseover;
+							onmousemove view/onmousemove;
+							onmouseout view/onmouseout;
+							onkeypress view/onkeypress;
+							onkeydown view/onkeydown;
+							onkeyup view/onkeyup;
+							value view/value;
+							disabled view/disabled;
+							tabindex view/tabindex;
+							onfocus view/onfocus;
+							onblur view/onblur;
+							onchange view/onchange;
+							readonly view/readonly;
+							alt view/alt;
+							accesskey view/accesskey;
+							onselect view/onselect;
+							size view/size;
+							maxlength view/maxlength;
+							placeholder view/placeholder;
+							autocapitalize view/autocapitalize;" />
+</tal:var>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/time-input.pt	Wed Mar 11 11:57:31 2015 +0100
@@ -0,0 +1,37 @@
+<tal:var i18n:domain="pyams_form">
+	<i class="icon-append fa fa-clock-o"></i>
+	<input id="" name="" class="" title="" lang="" disabled=""
+		   readonly="" alt="" tabindex="" accesskey="" size="" maxlength=""
+		   style="" value="" type="text"
+		   data-ams-datepicker-format="dd/mm/y"
+			tal:attributes="id view/id;
+							name view/name;
+							class string:${view/klass} timepicker;
+							style view/style;
+							title view/title;
+							lang view/lang;
+							onclick view/onclick;
+							ondblclick view/ondblclick;
+							onmousedown view/onmousedown;
+							onmouseup view/onmouseup;
+							onmouseover view/onmouseover;
+							onmousemove view/onmousemove;
+							onmouseout view/onmouseout;
+							onkeypress view/onkeypress;
+							onkeydown view/onkeydown;
+							onkeyup view/onkeyup;
+							value view/value;
+							disabled view/disabled;
+							tabindex view/tabindex;
+							onfocus view/onfocus;
+							onblur view/onblur;
+							onchange view/onchange;
+							readonly view/readonly;
+							alt view/alt;
+							accesskey view/accesskey;
+							onselect view/onselect;
+							size view/size;
+							maxlength view/maxlength;
+							placeholder view/placeholder;
+							autocapitalize view/autocapitalize;" />
+</tal:var>