[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - configure.zcml:1.5 widget.py:1.24
Tres Seaver
tseaver@zope.com
Wed, 26 Mar 2003 06:29:24 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv26373/src/zope/app/browser/form
Modified Files:
configure.zcml widget.py
Log Message:
- Add a widget for editing date/time fields (class, tests, configuration).
=== Zope3/src/zope/app/browser/form/configure.zcml 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/form/configure.zcml:1.4 Tue Mar 25 06:42:42 2003
+++ Zope3/src/zope/app/browser/form/configure.zcml Wed Mar 26 06:28:53 2003
@@ -57,6 +57,14 @@
<browser:page
permission="zope.Public"
allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+ for="zope.schema.interfaces.IDatetime"
+ name="edit"
+ class="zope.app.browser.form.widget.DatetimeWidget"
+ />
+
+ <browser:page
+ permission="zope.Public"
+ allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
for="zope.schema.interfaces.IBool"
name="edit"
class="zope.app.browser.form.widget.CheckBoxWidget"
=== Zope3/src/zope/app/browser/form/widget.py 1.23 => 1.24 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.23 Tue Mar 25 15:39:45 2003
+++ Zope3/src/zope/app/browser/form/widget.py Wed Mar 26 06:28:53 2003
@@ -20,12 +20,15 @@
import sys
from types import ListType, TupleType
ListTypes = (ListType, TupleType)
+from datetime import datetime
from zope.proxy.introspection import removeAllProxies
from zope.publisher.browser import BrowserView
from zope.app.interfaces.browser.form import IBrowserWidget
from zope.app.form.widget import Widget
from zope.app.interfaces.form import ConversionError, WidgetInputError
from zope.app.interfaces.form import MissingInputError
+from zope.app.datetimeutils import parseDatetimetz
+from zope.app.datetimeutils import DateTimeError
from zope.schema.interfaces import ValidationError
from zope.component import getService
@@ -311,6 +314,17 @@
return float(value)
except ValueError, v:
raise ConversionError("Invalid floating point data", v)
+
+class DatetimeWidget(TextWidget):
+ """Datetime entry widget."""
+ displayWidth = 20
+
+ def _convert(self, value):
+ if value:
+ try:
+ return parseDatetimetz(value)
+ except (DateTimeError, ValueError, IndexError), v:
+ raise ConversionError("Invalid datetime data", v)
class TextAreaWidget(PossiblyEmptyMeansMissing, BrowserWidget):
"""Textarea widget."""