Ignore:
Timestamp:
13 Apr 2012, 16:17:26 (13 years ago)
Author:
uli
Message:

Provide a new schema field for formatted dates (not a formlib field).

Location:
main/waeup.kofa/trunk/src/waeup/kofa/schema
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/schema/field.py

    r7263 r8146  
    1919"""
    2020from zope.interface import implements
    21 from zope.schema import TextLine
     21from zope.schema import TextLine, Date
    2222from zope.schema.interfaces import (
    2323    ITextLine, IBaseVocabulary, ISource, IContextSourceBinder, InvalidValue,)
    2424from zope.schema.vocabulary import (
    2525    SimpleVocabulary, getVocabularyRegistry, VocabularyRegistryError)
     26from waeup.kofa.schema.interfaces import IFormattedDate
    2627
    2728class CustomizableErrorMsg(object):
     
    125126            raise InvalidValue(value)
    126127        return
     128
     129class FormattedDate(Date):
     130    """A date field that supports additional formatting attributes.
     131
     132    Stores extra attributes (see below). To make use of these
     133    attributes in forms, you have to provide widgets that read them
     134    and use them in their operations, for instance the
     135    `waeup.kofa.widgets.datewidget.FormattedDateWidget`.
     136
     137    Extra attributes are as follows:
     138
     139    `date_format`
     140      additional attribute to describe desired date format. Must be a
     141      string that can be fed to strftime/strptime functions.
     142
     143    `show_year`
     144      boolean indicating whether some kind of year selection should
     145      be used with this instance.
     146    """
     147    implements(IFormattedDate)
     148    date_format = '%Y-%m-%d'
     149    show_year = False
     150    def __init__(self, date_format='%Y-%m-%d', show_year=False, *args, **kw):
     151        self.date_format = date_format
     152        self.show_year = show_year
     153        return super(FormattedDate, self).__init__(*args, **kw)
Note: See TracChangeset for help on using the changeset viewer.