当前位置: 首页>>代码示例>>Python>>正文


Python Event.get_occurrences方法代码示例

本文整理汇总了Python中schedule.models.Event.get_occurrences方法的典型用法代码示例。如果您正苦于以下问题:Python Event.get_occurrences方法的具体用法?Python Event.get_occurrences怎么用?Python Event.get_occurrences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在schedule.models.Event的用法示例。


在下文中一共展示了Event.get_occurrences方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_edge_case_events

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
    def test_edge_case_events(self):
        cal = Calendar(name="MyCal")
        cal.save()
        data_1 = {
            'title': 'Edge case event test one',
            'start': datetime.datetime(2013, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        data_2 = {
            'title': 'Edge case event test two',
            'start': datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc),
            'calendar': cal
        }
        event_one = Event(**data_1)
        event_two = Event(**data_2)
        event_one.save()
        event_two.save()
        occurrences_two = event_two.get_occurrences(datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))
        self.assertEqual(1, len(occurrences_two))

        occurrences_one = event_one.get_occurrences(datetime.datetime(2013, 1, 5, 9, 0, tzinfo=pytz.utc),
                                                    datetime.datetime(2013, 1, 5, 12, 0, tzinfo=pytz.utc))
        self.assertEqual(0, len(occurrences_one))
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:28,代码来源:test_event.py

示例2: test_recurring_event_get_occurrences

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
 def test_recurring_event_get_occurrences(self):
     recurring_event = Event(**self.recurring_data)
     recurring_event.save()
     occurrences = recurring_event.get_occurrences(start=datetime.datetime(2008, 1, 12, 0, 0),
                                 end=datetime.datetime(2008, 1, 20, 0, 0))
     self.assertEquals(["%s to %s" %(o.start, o.end) for o in occurrences],
         ['2008-01-12 08:00:00 to 2008-01-12 09:00:00', '2008-01-19 08:00:00 to 2008-01-19 09:00:00'])
开发者ID:schacon,项目名称:django-schedule,代码行数:9,代码来源:tests.py

示例3: test_event_get_occurrences

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
    def test_event_get_occurrences(self):
        event= Event(**self.data)
        event.save()
        occurrences = event.get_occurrences(start=datetime.datetime(2008, 1, 12, 0, 0),
                                    end=datetime.datetime(2008, 1, 20, 0, 0))

        self.assertEquals(["%s to %s" %(o.start, o.end) for o in occurrences],
            [])
开发者ID:schacon,项目名称:django-schedule,代码行数:10,代码来源:tests.py

示例4: test_event_get_occurrences_after

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
 def test_event_get_occurrences_after(self):
     recurring_event=Event(**self.recurring_data)
     recurring_event.save()
     occurrences = recurring_event.get_occurrences(start=datetime.datetime(2008, 1, 5),
         end = datetime.datetime(2008, 1, 6))
     occurrence = occurrences[0]
     occurrence2 = recurring_event.occurrences_after(datetime.datetime(2008,1,5)).next()
     self.assertEqual(occurrence, occurrence2)
开发者ID:CKiilu,项目名称:django-schedule,代码行数:10,代码来源:test_models.py

示例5: test_recurring_event_get_occurrences

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
 def test_recurring_event_get_occurrences(self):
     recurring_event = Event(**self.recurring_data)
     start = datetime.datetime(2008, 1, 12, 0, 0)
     end = datetime.datetime(2008, 1, 20, 0, 0)
     occurrences = recurring_event.get_occurrences(start=start, end=end)
     expected = [
         '2008-01-12 08:00:00 to 2008-01-12 09:00:00',
         '2008-01-19 08:00:00 to 2008-01-19 09:00:00',
     ]
     self.assertEquals(["%s to %s" % (o.start, o.end) for o in occurrences], expected)
开发者ID:macanhhuy,项目名称:django-schedule,代码行数:12,代码来源:test_models.py

示例6: TestOccurrence

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
class TestOccurrence(TestCase):
    def setUp(self):
        rule = Rule(frequency = "WEEKLY")
        rule.save()
        self.recurring_data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'rule': rule,
               }
        self.data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
               }
        self.recurring_event = Event(**self.recurring_data)
        self.recurring_event.save()
        self.start = datetime.datetime(2008, 1, 12, 0, 0)
        self.end = datetime.datetime(2008, 1, 27, 0, 0)
    
    def test_presisted_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        persisted_occurrence = occurrences[0]
        persisted_occurrence.save()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[0].pk)
        self.assertFalse(occurrences[1].pk)
    
    def test_moved_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        moved_occurrence = occurrences[1]
        moved_occurrence.move(moved_occurrence.start+datetime.timedelta(hours=2),
                              moved_occurrence.end+datetime.timedelta(hours=2))
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[1].moved)
    
    def test_cancelled_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        cancelled_occurrence = occurrences[2]
        cancelled_occurrence.cancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[2].cancelled)
        cancelled_occurrence.uncancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertFalse(occurrences[2].cancelled)
开发者ID:RockHoward,项目名称:django-schedule,代码行数:56,代码来源:test_models.py

示例7: make_occurrences

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
 def make_occurrences(self, rule):
     cal = Calendar.objects.get(name="MyCal")
     recurring_data = {
             'title': 'Recent Event',
             'start': datetime.datetime(2010, 1, 1, 8, 0),
             'end': datetime.datetime(2010, 1, 1, 9, 0),
             'end_recurring_period' : datetime.datetime(2010, 2, 1, 0, 0),
             'rule': rule,
             'calendar': cal
            }
     recurring_event = Event(**recurring_data)
     occurrences = recurring_event.get_occurrences(start=datetime.datetime(2010, 1, 1, 0, 0),
                                 end=datetime.datetime(2010, 2, 1, 0, 0))
     return [o.start.day for o in occurrences]
开发者ID:ATOM49,项目名称:django-voip,代码行数:16,代码来源:test_rule.py

示例8: TestOccurrence

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
class TestOccurrence(TestCase):
    def setUp(self):
        rule = Rule(frequency = "WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        self.recurring_data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        self.data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'calendar': cal
               }
        self.recurring_event = Event(**self.recurring_data)
        self.recurring_event.save()
        self.start = datetime.datetime(2008, 1, 12, 0, 0)
        self.end = datetime.datetime(2008, 1, 27, 0, 0)

    def test_presisted_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        persisted_occurrence = occurrences[0]
        persisted_occurrence.save()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[0].pk)
        self.assertFalse(occurrences[1].pk)

    def test_moved_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        moved_occurrence = occurrences[1]
        span_pre = (moved_occurrence.start, moved_occurrence.end)
        span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
        # check has_occurrence on both periods
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertTrue(period_pre.has_occurrences())
        self.assertFalse(period_post.has_occurrences())
        # move occurrence
        moved_occurrence.move(moved_occurrence.start+datetime.timedelta(hours=2),
                              moved_occurrence.end+datetime.timedelta(hours=2))
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[1].moved)
        # check has_occurrence on both periods (the result should be reversed)
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertFalse(period_pre.has_occurrences())
        self.assertTrue(period_post.has_occurrences())

    def test_cancelled_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        cancelled_occurrence = occurrences[2]
        cancelled_occurrence.cancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[2].cancelled)
        cancelled_occurrence.uncancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertFalse(occurrences[2].cancelled)
开发者ID:CKiilu,项目名称:django-schedule,代码行数:73,代码来源:test_models.py

示例9: TestOccurrence

# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import get_occurrences [as 别名]
class TestOccurrence(TestCase):
    def setUp(self):
        rule = Rule(frequency = "WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        self.recurring_data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'rule': rule,
                'calendar': cal
               }
        self.data = {
                'title': 'Recent Event',
                'start': datetime.datetime(2008, 1, 5, 8, 0),
                'end': datetime.datetime(2008, 1, 5, 9, 0),
                'end_recurring_period' : datetime.datetime(2008, 5, 5, 0, 0),
                'calendar': cal
               }
        self.recurring_event = Event(**self.recurring_data)
        self.recurring_event.save()
        self.start = datetime.datetime(2008, 1, 12, 0, 0)
        self.end = datetime.datetime(2008, 1, 27, 0, 0)

    def test_presisted_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        persisted_occurrence = occurrences[0]
        persisted_occurrence.save()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[0].pk)
        self.assertFalse(occurrences[1].pk)

    def test_moved_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        moved_occurrence = occurrences[1]
        span_pre = (moved_occurrence.start, moved_occurrence.end)
        span_post = [x + datetime.timedelta(hours=2) for x in span_pre]
        # check has_occurrence on both periods
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertTrue(period_pre.has_occurrences())
        self.assertFalse(period_post.has_occurrences())
        # move occurrence
        moved_occurrence.move(moved_occurrence.start+datetime.timedelta(hours=2),
                              moved_occurrence.end+datetime.timedelta(hours=2))
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[1].moved)
        # check has_occurrence on both periods (the result should be reversed)
        period_pre = Period([self.recurring_event], span_pre[0], span_pre[1])
        period_post = Period([self.recurring_event], span_post[0], span_post[1])
        self.assertFalse(period_pre.has_occurrences())
        self.assertTrue(period_post.has_occurrences())
        # trigger bug discovered by gautamadude - modifying recurring event
        # breaks link between a persistent occurrence and the occurrence chain
        # leaving an "orphaned" occurrence
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(len(occurrences) == 3)
        self.recurring_event.start = datetime.datetime(2008, 1, 5, 8, 15)
        self.recurring_event.save()
        occurrences_later = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertEquals(len(occurrences_later), len(occurrences))

    def test_cancelled_occurrences(self):
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        cancelled_occurrence = occurrences[2]
        cancelled_occurrence.cancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(occurrences[2].cancelled)
        cancelled_occurrence.uncancel()
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertFalse(occurrences[2].cancelled)
        # trigger bug discovered by gautamadude
        occurrences = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertTrue(len(occurrences) == 3)
        self.recurring_event.start = datetime.datetime(2008, 1, 5, 8, 15)
        self.recurring_event.save()
        occurrences_later = self.recurring_event.get_occurrences(start=self.start,
                                    end=self.end)
        self.assertEquals(len(occurrences_later), len(occurrences))
开发者ID:ATOM49,项目名称:django-voip,代码行数:93,代码来源:test_models.py


注:本文中的schedule.models.Event.get_occurrences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。