class ISelfPopulatingExtent(IExtent): """An extent that knows how to create it's own initial population.""" populated = schema.Bool( title=_("Populated"), description=_( "Flag indicating whether self-population has been performed."), readonly=True, ) def populate(): """Populate the extent based on the current content of the database.
def value(self, value): if not isinstance(value, datetime.datetime): raise ValueError( _('This index only indexes timezone-aware datetimes.')) if value.tzinfo is None: value = datetime.datetime( value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, pytz.utc) value = value.astimezone(pytz.utc) return super(DateTimeNormalizer, self).value(value)
def all(value, index): """Normalize a query value for an "all_of" search; return the value for query""" def minimum(value, index, exclude=False): """normalize a query value for minimum of a range; return the value for query""" def maximum(value, index, exclude=False): """normalize a query value for maximum of a range; return the value for query""" resolution_vocabulary = SimpleVocabulary( [SimpleTerm(i, t, t) for i, t in enumerate( (_('day'), _('hour'), _('minute'), _('second'), _('microsecond')))]) # 0 1 2 3 4 class IDateTimeNormalizer(INormalizer): resolution = schema.Choice( vocabulary=resolution_vocabulary, title=_('Resolution'), default=2, required=True) class ICallableWrapper(zope.index.interfaces.IInjection, zope.index.interfaces.IIndexSearch, zope.index.interfaces.IStatistics, IIndexValues):
def value(self, value): if not isinstance(value, datetime.datetime) or value.tzinfo is None: raise ValueError( _('This index only indexes timezone-aware datetimes.')) return set_resolution(value, self.resolution)
class IDateTimeNormalizer(INormalizer): resolution = schema.Choice(vocabulary=resolution_vocabulary, title=_('Resolution'), default=2, required=True)
def all(value, index): """Normalize a query value for an "all_of" search; return the value for query""" def minimum(value, index, exclude=False): """normalize a query value for minimum of a range; return the value for query""" def maximum(value, index, exclude=False): """normalize a query value for maximum of a range; return the value for query""" resolution_vocabulary = SimpleVocabulary([ SimpleTerm(i, t, t) for i, t in enumerate((_('day'), _('hour'), _('minute'), _('second'), _('microsecond'))) ]) # 0 1 2 3 4 class IDateTimeNormalizer(INormalizer): resolution = schema.Choice(vocabulary=resolution_vocabulary, title=_('Resolution'), default=2, required=True) class ICallableWrapper(zope.index.interfaces.IInjection, zope.index.interfaces.IIndexSearch, zope.index.interfaces.IStatistics, IIndexValues):