Back to index

plone3  3.1.7
daterange.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """ Topic:
00020 
00021 """
00022 
00023 __author__  = 'Alec Mitchell'
00024 __docformat__ = 'restructuredtext'
00025 __old_name__ = 'Products.ATContentTypes.types.criteria.ATDateRangeCriterion'
00026 
00027 from Products.CMFCore.permissions import View
00028 from AccessControl import ClassSecurityInfo
00029 
00030 from Products.Archetypes.atapi import Schema
00031 from Products.Archetypes.atapi import DateTimeField
00032 from Products.Archetypes.atapi import CalendarWidget
00033 
00034 from Products.ATContentTypes.criteria import registerCriterion
00035 from Products.ATContentTypes.criteria import DATE_INDICES
00036 from Products.ATContentTypes.interfaces import IATTopicSearchCriterion
00037 from Products.ATContentTypes.permission import ChangeTopics
00038 from Products.ATContentTypes.criteria.base import ATBaseCriterion
00039 from Products.ATContentTypes.criteria.schemata import ATBaseCriterionSchema
00040 
00041 from Products.ATContentTypes import ATCTMessageFactory as _
00042 
00043 RELEVANT_INDICES=list(DATE_INDICES)
00044 RELEVANT_INDICES.remove('DateRangeIndex')
00045 RELEVANT_INDICES = tuple(RELEVANT_INDICES)
00046 
00047 ATDateRangeCriterionSchema = ATBaseCriterionSchema + Schema((
00048     DateTimeField('start',
00049                 required=1,
00050                 mode="rw",
00051                 write_permission=ChangeTopics,
00052                 default=None,
00053                 widget=CalendarWidget(
00054                     label=_(u'label_date_range_criteria_start', default=u'Start Date'),
00055                     description=_(u'help_date_range_criteria_start',
00056                                   default=u'The beginning of the date range to search')
00057                     ),
00058                 ),
00059     DateTimeField('end',
00060                 required=1,
00061                 mode="rw",
00062                 write_permission=ChangeTopics,
00063                 default=None,
00064                 widget=CalendarWidget(
00065                     label=_(u'label_date_range_criteria_end', default=u'End Date'),
00066                     description=_(u'help_date_range_criteria_end',
00067                                   default=u'The ending of the date range to search.')
00068 
00069                     ),
00070                 ),
00071     ))
00072 
00073 class ATDateRangeCriterion(ATBaseCriterion):
00074     """A date range criterion"""
00075 
00076     __implements__ = ATBaseCriterion.__implements__ + (IATTopicSearchCriterion, )
00077     security       = ClassSecurityInfo()
00078     schema         = ATDateRangeCriterionSchema
00079     meta_type      = 'ATDateRangeCriterion'
00080     archetype_name = 'Date Range Criterion'
00081     shortDesc      = 'Date range'
00082 
00083     security.declareProtected(View, 'Value')
00084     def Value(self):
00085         return (self.getStart(), self.getEnd())
00086 
00087     security.declareProtected(View, 'getCriteriaItems')
00088     def getCriteriaItems(self):
00089         result = []
00090 
00091         field = self.Field()
00092         value = self.Value()
00093 
00094         return ( ( field, {'query': value, 'range': 'min:max'} ), )
00095 
00096 registerCriterion(ATDateRangeCriterion, RELEVANT_INDICES)