Change minute_step in Archetypes DateTimeWidget

Sometimes you need minutes which could not be divided by 5 which Plone doesn’t select you by default. You don’t need to rewrite core components in Archetypes DateTimeWidget to change this.

Prerequisites

You need your own BrowserLayer (a skin or theme product) or a contenttype with at least one marker interface to customize on.

Howto

Create a file called datecomponents.py in your browser directory with following content:

from plone.app.form.widgets import datecomponents

class DateComponents(datecomponents.DateComponents):

    def result(self, date=None, use_ampm=False, starting_year=None,
                     ending_year=None, future_years=None, minute_step=5):

        # Change minute steps to 1
        return super(DateComponents, self).result(date, use_ampm,
                                                  starting_year, ending_year,
                                                  future_years, 1)

… and register it for you browserlayer (replace IThemeSpecific by your layer interface) or for a type you want to customize its widget (replace for=’*’ with your types interface), thats it.

<!-- customize datecomponents -->
<include package="plone.app.form" />

<browser:page
    name="date_components_support"
    for="*"
    permission="zope2.View"
    class=".datecomponents.DateComponents"
    allowed_interface="plone.app.form.widgets.interfaces.IDateComponents"
    layer=".interfaces.IThemeSpecific"
    />

Comments

comments powered by Disqus