Sure. As I said earlier, we are happy to accept patches :)


I've written simple path that, at last, causes DateDisplayWidget
doesn't raise exceptions and has minimalistic locale aware date
formatting (according to docs about time module and strftime
function with %x and %X).
I've added overrides.zcml that redefines DateDisplayWidget
and DatetimeDisplayWidget.

File textwidgets.py should be placed in Five/form/
and overrides.zcml in Five/ (possibly there should be
rather include of Five/form/overrides.zcml)

I'm not sure if it is suitable to Five philosophy (especially overrides)
so comments are welcome.


Another idea of being locale aware with DateDisplay widgets
is similiar to one used in CalZope from Nuxeo.Use translation
to get proper (locale aware) date formats. But I'm not sure
where such translations should be defined and what are
'short', 'medium', 'long' and 'full' formats used
by getFormatter in Zope3. I mean something like:

msgid = _('YYYY-MM-DD')
res = translate(msgid, context=self.request, default=msgid)
return renderElement("span", contents=escape(res),
                        cssClass=self.cssClass)

--
Maciej Wisniowski
<configure xmlns="http://namespaces.zope.org/zope";
           xmlns:browser="http://namespaces.zope.org/browser";>

    <view
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      for="zope.schema.interfaces.IDate"
      provides="zope.app.form.interfaces.IDisplayWidget"
      factory=".form.textwidgets.DateDisplayWidget"
      permission="zope.Public"
      />
      
    <view
      type="zope.publisher.interfaces.browser.IBrowserRequest"
      for="zope.schema.interfaces.IDatetime"
      provides="zope.app.form.interfaces.IDisplayWidget"
      factory=".form.textwidgets.DatetimeDisplayWidget"
      permission="zope.Public"
      />

</configure>
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Five-compatible version of DateDisplayWidget.
   This version omits reference to request.locale and uses
   standard date formatting function strftime.
"""
from zope.app.form.browser.widget import renderElement
#from zope.app.i18n import ZopeMessageFactory as _

from zope.app.form.browser.textwidgets import DateDisplayWidget, escape

class DateDisplayWidget(DateDisplayWidget):
    """Date display widget.

    The `cssClass` and `displayStyle` attributes may be set to control
    the formatting of the value.

    `displayStyle` must be one of 'full', 'long', 'medium', 'short',
    or None ('' is accepted an an alternative to None to support
    provision of a value from ZCML).

    """

    def __call__(self):
        if self._renderedValueSet():
            content = self._data
        else:
            content = self.context.default
        if content == self.context.missing_value:
            return ""

        # there should be format conversion dependent by locale 
        # and self.displayStyle
        format = '%x'
        if self._category=='dateTime':
            format = '%x %X'
        content = content.strftime(format)
        return renderElement("span", 
                             contents=escape(content),
                             cssClass=self.cssClass)


class DatetimeDisplayWidget(DateDisplayWidget):
    """Datetime display widget.

    The `cssClass` and `displayStyle` attributes may be set to control
    the formatting of the value.

    `displayStyle` must be one of 'full', 'long', 'medium', 'short',
    or None ('' is accepted an an alternative to None to support
    provision of a value from ZCML).

    """

    cssClass = "dateTime"

    _category = "dateTime"
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to