Skip to content

Commit

Permalink
Added new DateSelect field.
Browse files Browse the repository at this point in the history
  • Loading branch information
strichter committed Sep 21, 2007
1 parent 2035870 commit f3b56a8
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGES.txt
@@ -0,0 +1,13 @@
======================
Changes for z3c.schema
======================

2007/09/21 0.2.0:
=================

- Feature: Added ``DateSelect`` field.

2007/06/04 0.1.0:
=================

- Initial release
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages

setup(name='z3c.schema',
version='0.1',
version='0.2',
author = "Zope Community",
author_email = "zope3-dev@zope.org",
description = "Additional schema fields for Zope 3",
Expand Down
35 changes: 35 additions & 0 deletions src/z3c/schema/dateselect/README.txt
@@ -0,0 +1,35 @@
========================
The Date Selection Field
========================

The date selection field was designed to support the UI requirement of
allowing users to select a date using multi-select input fields. The
``DateSelect`` field extends the ``Date`` field merely by a few additional
attributes.

>>> from z3c.schema.dateselect import field

the first attribute is the range of years that will be offered to the user:

>>> birthday = field.DateSelect(
... title=u'Birthday',
... yearRange=range(1920, 2007))

In this case the user will be offered all years from 1920 to 2007.

>>> birthday.yearRange
[1920, ..., 2006]

The second attribute allows you to specify an initial date for the selection:

>>> import datetime
>>> birthday = field.DateSelect(
... title=u'Birthday',
... yearRange=range(1920, 2007),
... initialDate=datetime.date(2000, 1, 1))

>>> birthday.initialDate
datetime.date(2000, 1, 1)

And this is really it. Please read the documentation on the ``Date`` for more
information.
19 changes: 19 additions & 0 deletions src/z3c/schema/dateselect/__init__.py
@@ -0,0 +1,19 @@
##############################################################################
#
# Copyright (c) 2006 Zope Foundation 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.
#
##############################################################################
"""
$Id$
"""

from z3c.schema.dateselect.interfaces import IDateSelect
from z3c.schema.dateselect.field import DateSelect
34 changes: 34 additions & 0 deletions src/z3c/schema/dateselect/field.py
@@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (c) 2006 Zope Foundation 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.
#
##############################################################################
"""Date Selection field implementation
$Id$
"""
__docformat__ = "reStructuredText"
import zope.interface
import zope.schema

from z3c.schema.dateselect import interfaces

class DateSelect(zope.schema.Date):
zope.interface.implements(interfaces.IDateSelect)

yearRange = range(1900, 2100)
initialDate = None # set a date or today is used

def __init__(self, yearRange=None, initialDate=None, **kw):
super(DateSelect, self).__init__(**kw)
self.initialDate = initialDate
if yearRange is not None:
self.yearRange = yearRange
27 changes: 27 additions & 0 deletions src/z3c/schema/dateselect/interfaces.py
@@ -0,0 +1,27 @@
##############################################################################
#
# Copyright (c) 2006 Zope Foundation 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.
#
##############################################################################
"""Date Selection Field interfaces
$Id$
"""
__docformat__ = "reStructuredText"

import zope.schema.interfaces

class IDateSelect(zope.schema.interfaces.IDate):

yearRange = zope.interface.Attribute(u"Year range.")

initialDate = zope.interface.Attribute(
u"Initial date displayed or ``None``. If ``None``, `today()`` is used.")
32 changes: 32 additions & 0 deletions src/z3c/schema/dateselect/tests.py
@@ -0,0 +1,32 @@
##############################################################################
#
# Copyright (c) 2006 Zope Foundation 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.
#
##############################################################################
"""
$Id$
"""
__docformat__ = "reStructuredText"

import unittest
from zope.testing import doctest
from zope.testing.doctestunit import DocFileSuite


def test_suite():
return unittest.TestSuite((
DocFileSuite('README.txt',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,),
))


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

0 comments on commit f3b56a8

Please sign in to comment.