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


Python Period.get_time_slot方法代码示例

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


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

示例1: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule.objects.create(frequency="WEEKLY")
        cal = Calendar.objects.create(name="MyCal")
        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end_recurring_period': datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
            'rule': rule,
            'calendar': cal,
        }
        Event.objects.create(**data)
        self.period = Period(
            events=Event.objects.all(),
            start=datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2008, 1, 21, 7, 0, tzinfo=pytz.utc))

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in occurrence_list],
            [
                '2008-01-05 08:00:00+00:00 to 2008-01-05 09:00:00+00:00',
                '2008-01-12 08:00:00+00:00 to 2008-01-12 09:00:00+00:00',
                '2008-01-19 08:00:00+00:00 to 2008-01-19 09:00:00+00:00',
            ]
        )

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [
                (occ_dict["class"], occ_dict["occurrence"].start, occ_dict["occurrence"].end)
                for occ_dict in occurrence_dicts
            ],
            [
                (1,
                 datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc)),
                (1,
                 datetime.datetime(2008, 1, 12, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 12, 9, 0, tzinfo=pytz.utc)),
                (1,
                 datetime.datetime(2008, 1, 19, 8, 0, tzinfo=pytz.utc),
                 datetime.datetime(2008, 1, 19, 9, 0, tzinfo=pytz.utc))
            ])

    def test_has_occurrence(self):
        self.assertTrue(self.period.has_occurrences())
        slot = self.period.get_time_slot(
            datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
            datetime.datetime(2008, 1, 4, 7, 12, tzinfo=pytz.utc))
        self.assertFalse(slot.has_occurrences())
开发者ID:drodger,项目名称:django-scheduler,代码行数:56,代码来源:test_periods.py

示例2: test_occurrences_sub_period_with_TZ

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
    def test_occurrences_sub_period_with_TZ(self):
        start = self.MVD.localize(datetime.datetime(2017, 1, 13))
        end = self.MVD.localize(datetime.datetime(2017, 1, 23))

        period = Period(Event.objects.all(), start, end, tzinfo=self.MVD)

        sub_start = self.MVD.localize(datetime.datetime(2017, 1, 13))
        sub_end = self.MVD.localize(datetime.datetime(2017, 1, 15))
        sub_period = period.get_time_slot(sub_start, sub_end)
        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in sub_period.occurrences],
            ['2017-01-14 22:00:00-03:00 to 2017-01-14 23:00:00-03:00'])
开发者ID:Alcolo47,项目名称:django-scheduler,代码行数:14,代码来源:test_periods.py

示例3: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Calendar(name="MyCal")
        cal.save()
        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
        }
        recurring_event = Event(**data)
        recurring_event.save()
        self.period = Period(events=Event.objects.all(),
                             start=datetime.datetime(2008, 1, 4, 7, 0),
                             end=datetime.datetime(2008, 1, 21, 7, 0))

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        expected = [
            '2008-01-05 08:00:00 to 2008-01-05 09:00:00',
            '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.assertEqual(["%s to %s" % (o.start, o.end) for o in occurrence_list], expected)

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [(occ_dict["class"],
            occ_dict["occurrence"].start,
            occ_dict["occurrence"].end)
            for occ_dict in occurrence_dicts],
            [
                (1,
                 datetime.datetime(2008, 1, 5, 8, 0),
                 datetime.datetime(2008, 1, 5, 9, 0)),
                (1,
                 datetime.datetime(2008, 1, 12, 8, 0),
                 datetime.datetime(2008, 1, 12, 9, 0)),
                (1,
                 datetime.datetime(2008, 1, 19, 8, 0),
                 datetime.datetime(2008, 1, 19, 9, 0))
            ])

    def test_has_occurrence(self):
        self.assert_(self.period.has_occurrences())
        slot = self.period.get_time_slot(datetime.datetime(2008, 1, 4, 7, 0),
                                         datetime.datetime(2008, 1, 4, 7, 12))
        self.failIf(slot.has_occurrences())
开发者ID:macanhhuy,项目名称:django-schedule,代码行数:55,代码来源:test_periods.py

示例4: TestPeriod

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
class TestPeriod(TestCase):
    def setUp(self):
        rule = Rule(frequency="WEEKLY")
        rule.save()
        cal = Room(name="MyCal")
        cal.save()
        data = {
            "title": "Recent Reservation",
            "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,
            "room": cal,
        }
        recurring_reservation = Reservation(**data)
        recurring_reservation.save()
        self.period = Period(
            reservations=Reservation.objects.all(),
            start=datetime.datetime(2008, 1, 4, 7, 0),
            end=datetime.datetime(2008, 1, 21, 7, 0),
        )

    def test_get_occurrences(self):
        occurrence_list = self.period.occurrences
        self.assertEqual(
            ["%s to %s" % (o.start, o.end) for o in occurrence_list],
            [
                "2008-01-05 08:00:00 to 2008-01-05 09:00:00",
                "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",
            ],
        )

    def test_get_occurrence_partials(self):
        occurrence_dicts = self.period.get_occurrence_partials()
        self.assertEqual(
            [
                (occ_dict["class"], occ_dict["occurrence"].start, occ_dict["occurrence"].end)
                for occ_dict in occurrence_dicts
            ],
            [
                (1, datetime.datetime(2008, 1, 5, 8, 0), datetime.datetime(2008, 1, 5, 9, 0)),
                (1, datetime.datetime(2008, 1, 12, 8, 0), datetime.datetime(2008, 1, 12, 9, 0)),
                (1, datetime.datetime(2008, 1, 19, 8, 0), datetime.datetime(2008, 1, 19, 9, 0)),
            ],
        )

    def test_has_occurrence(self):
        self.assert_(self.period.has_occurrences())
        slot = self.period.get_time_slot(datetime.datetime(2008, 1, 4, 7, 0), datetime.datetime(2008, 1, 4, 7, 12))
        self.failIf(slot.has_occurrences())
开发者ID:bjdag1234,项目名称:django-schedule-rooms,代码行数:53,代码来源:test_periods.py

示例5: TestTemplateTags

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
class TestTemplateTags(TestCase):
    def setUp(self):
        self.day = Day(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 0, 0, tzinfo=pytz.utc))
        rule = Rule(frequency="WEEKLY")
        rule.save()
        self.cal = Calendar(name="MyCal", slug="MyCalSlug")
        self.cal.save()
        data = {
            "title": "Recent Event",
            "start": datetime.datetime(2008, 1, 5, 8, 0, tzinfo=pytz.utc),
            "end": datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc),
            "end_recurring_period": datetime.datetime(2008, 5, 5, 0, 0, tzinfo=pytz.utc),
            "rule": rule,
            "calendar": self.cal,
        }
        recurring_event = Event(**data)
        recurring_event.save()
        self.period = Period(
            events=Event.objects.all(),
            start=datetime.datetime(2008, 1, 4, 7, 0, tzinfo=pytz.utc),
            end=datetime.datetime(2008, 1, 21, 7, 0, tzinfo=pytz.utc),
        )

    def test_querystring_for_datetime(self):
        date = datetime.datetime(2008, 1, 1, 0, 0, 0)
        query_string = querystring_for_date(date, autoescape=True)
        self.assertEqual(escape("?year=2008&month=1&day=1&hour=0&minute=0&second=0"), query_string)

    def test_prev_url(self):
        query_string = prev_url("month_calendar", "MyCalSlug", self.day)
        expected = "/calendar/month/MyCalSlug/?year=2008&month=2&day=6&hour=0" "&minute=0&second=0"
        self.assertEqual(query_string, escape(expected))

    def test_next_url(self):
        query_string = next_url("month_calendar", "MyCalSlug", self.day)
        expected = "/calendar/month/MyCalSlug/?year=2008&month=2&day=8&hour=0" "&minute=0&second=0"
        self.assertEqual(query_string, escape(expected))

    def test_create_event_url(self):
        context = {}
        slot = self.period.get_time_slot(
            datetime.datetime(2010, 1, 4, 7, 0, tzinfo=pytz.utc), datetime.datetime(2008, 1, 4, 7, 12, tzinfo=pytz.utc)
        )
        query_string = create_event_url(context, self.cal, slot.start)
        expected = "/event/create/MyCalSlug/?year=2010&month=1&day=4&hour=7" "&minute=0&second=0"
        self.assertEqual(query_string["create_event_url"], escape(expected))
开发者ID:JessAtBlocBoxCo,项目名称:blocbox,代码行数:48,代码来源:test_templatetags.py

示例6: TestTemplateTags

# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import get_time_slot [as 别名]
class TestTemplateTags(TestCase):
    def setUp(self):
        self.day = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year, 2, 7, 0, 0, tzinfo=pytz.utc))
        self.day_out_of_limit = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year + 3, 2, 7, 0, 0, tzinfo=pytz.utc))
        self.day_out_of_limit_lower = Day(events=Event.objects.all(),
                       date=datetime.datetime(datetime.datetime.now().year - 3, 2, 7, 0, 0, tzinfo=pytz.utc))

        rule = Rule(frequency='WEEKLY')
        rule.save()
        self.cal = Calendar(name='MyCal', slug='MyCalSlug')
        self.cal.save()

        data = {
            'title': 'Recent Event',
            'start': datetime.datetime(datetime.datetime.now().year, 1, 5, 8, 0, tzinfo=pytz.utc),
            'end': datetime.datetime(datetime.datetime.now().year, 1, 5, 9, 0, tzinfo=pytz.utc),
            'end_recurring_period': datetime.datetime(datetime.datetime.now().year, 5, 5, 0, 0, tzinfo=pytz.utc),
            'rule': rule,
            'calendar': self.cal,
        }
        recurring_event = Event(**data)
        recurring_event.save()
        self.period = Period(events=Event.objects.all(),
                             start=datetime.datetime(datetime.datetime.now().year, 1, 4, 7, 0, tzinfo=pytz.utc),
                             end=datetime.datetime(datetime.datetime.now().year, 1, 21, 7, 0, tzinfo=pytz.utc))

    def test_querystring_for_datetime(self):
        date = datetime.datetime(datetime.datetime.now().year, 1, 1, 0, 0, 0)
        query_string = querystring_for_date(date, autoescape=True)
        self.assertEqual(escape('?year={0}&month=1&day=1&hour=0&minute=0&second=0'.format(datetime.datetime.now().year)),
            query_string)

    def test_prev_url(self):
        query_string = prev_url('month_calendar', self.cal, self.day)
        url_params = escape('/calendar/month/MyCalSlug/?year={0}&month=2&day=6&hour=0&minute=0&second=0'.format(datetime.datetime.now().year))
        expected = ('<a href="{0}"><span class="glyphicon glyphicon-circle-arrow-left"></span></a>'.format(url_params))
        self.assertEqual(query_string, expected)

    def test_next_url(self):
        query_string = next_url('month_calendar', self.cal, self.day)
        url_params = escape('/calendar/month/MyCalSlug/?year={0}&month=2&day=8&hour=0&minute=0&second=0'.format(datetime.datetime.now().year))
        expected = ('<a href="{0}"><span class="glyphicon glyphicon-circle-arrow-right"></span></a>'.format(url_params))
        self.assertEqual(query_string, expected)

    def test_next_url_upper_limit(self):
        query_string = next_url('month_calendar', self.cal, self.day_out_of_limit)
        self.assertEqual(query_string, '')

    def test_prev_url_lower_limit(self):
        query_string = prev_url('month_calendar', self.cal, self.day_out_of_limit_lower)
        self.assertEqual(query_string, '')

    def test_create_event_url(self):
        context = {}
        slot = self.period.get_time_slot(datetime.datetime(datetime.datetime.now().year, 1, 4, 7, 0, tzinfo=pytz.utc),
                                         datetime.datetime(datetime.datetime.now().year, 1, 4, 7, 12, tzinfo=pytz.utc))
        query_string = create_event_url(context, self.cal, slot.start)
        expected = ('/event/create/MyCalSlug/?year={0}&month=1&day=4&hour=7&minute=0&second=0'.format(datetime.datetime.now().year))
        self.assertEqual(query_string['create_event_url'], escape(expected))
开发者ID:nwaxiomatic,项目名称:django-scheduler,代码行数:63,代码来源:test_templatetags.py


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