def test_catalog(self): start = datetime.now(local_timezone) self.add_published_agenda_item( self.root, 'weekend', 'Agenda Item', start, start + timedelta(60)) # make sure it does not raise self.assertNotEqual( ICatalogingAttributes(self.root.weekend.get_viewable()).timestamp_ranges(), []) start_index = datetime_to_unixtimestamp(start) end_index = datetime_to_unixtimestamp(start + timedelta(30)) catalog = getUtility(ICatalogService) brains = catalog( {'timestamp_ranges': {'query': [start_index, end_index]}}) self.assertEqual( [b.getPath() for b in brains], ['/root/weekend/0']) start_index = datetime_to_unixtimestamp(start - timedelta(30)) end_index = datetime_to_unixtimestamp(start - timedelta(20)) brains = catalog( {'timestamp_ranges': {'query': [start_index, end_index]}}) self.assertEqual( [b.getPath() for b in brains], [])
def _get_items_by_date_range( self, start, end, meta_types=None, public_only=True, filter_items=True): query = self._prepare_query(meta_types, public_only=public_only) query['timestamp_ranges'] = { 'query': [ datetimeutils.datetime_to_unixtimestamp(start), datetimeutils.datetime_to_unixtimestamp(end)]} return self._query_items(query, filter_items=filter_items)
def test_catalog(self): dt = datetime(2010, 9, 10, 10, 0) # every two weeks occurrence = AgendaItemOccurrence( timezone_name='Europe/Amsterdam', start_datetime=dt, end_datetime=dt + relativedelta(hours=+2), recurrence='FREQ=WEEKLY;INTERVAL=2;BYDAY=FR', end_recurrence_datetime=dt + relativedelta(months=+1)) # last for one month recurrence = occurrence.get_rrule() self.assertNotEquals(recurrence, None) factory = self.root.manage_addProduct['silva.app.news'] factory.manage_addAgendaItem('event', 'Event') version = self.root.event.get_editable() version.set_occurrences([occurrence]) self.root.event.set_unapproved_version_publication_datetime(DateTime()) self.root.event.approve_version() catalog = getUtility(ICatalogService) tz = get_timezone('Europe/Amsterdam') start = datetime_to_unixtimestamp( datetime(2010, 9, 10, 0, 0, tzinfo=tz)) end = datetime_to_unixtimestamp( datetime(2010, 9, 10, 23, 59, tzinfo=tz)) def search(): return map(lambda x: x.getObject(), catalog({'timestamp_ranges': [start, end]})) self.assertEquals([version], search()) start = datetime_to_unixtimestamp( datetime(2010, 9, 24, 10, 0, tzinfo=tz)) end = datetime_to_unixtimestamp( datetime(2010, 9, 24, 12, 0, tzinfo=tz)) self.assertEquals([version], search()) start = datetime_to_unixtimestamp( datetime(2010, 10, 8, 11, 0, tzinfo=tz)) end = datetime_to_unixtimestamp( datetime(2010, 10, 8, 13, 0, tzinfo=tz)) self.assertEquals([version], search())
def sort_index(self): dt = self.get_start_datetime() if dt: return datetime_to_unixtimestamp(dt) return None