本文整理汇总了Python中schedule.models.Event.save方法的典型用法代码示例。如果您正苦于以下问题:Python Event.save方法的具体用法?Python Event.save怎么用?Python Event.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schedule.models.Event
的用法示例。
在下文中一共展示了Event.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOccurrencePool
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
class TestOccurrencePool(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, 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
}
self.recurring_event = Event(**data)
self.recurring_event.save()
def testPeriodFromPool(self):
"""
Test that period initiated with occurrence_pool returns the same occurrences as "straigh" period
in a corner case whereby a period's start date is equal to the occurrence's end date
"""
start = datetime.datetime(2008, 1, 5, 9, 0, tzinfo=pytz.utc)
end = datetime.datetime(2008, 1, 5, 10, 0, tzinfo=pytz.utc)
parent_period = Period(Event.objects.all(), start, end)
period = Period(parent_period.events, start, end, parent_period.get_persisted_occurrences(), parent_period.occurrences)
self.assertEqual(parent_period.occurrences, period.occurrences)
示例2: test_edge_case_events
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [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))
示例3: test_recurring_event_get_occurrences
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [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'])
示例4: TestAwareDay
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
class TestAwareDay(TestCase):
def setUp(self):
self.timezone = pytz.timezone('Europe/Amsterdam')
start = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 20))
end = self.timezone.localize(datetime.datetime(2008, 2, 7, 0, 21))
self.event = Event(
title='One minute long event on january seventh 2008 at 00:20 in Amsterdam.',
start=start,
end=end,
)
self.event.save()
self.day = Day(
events=Event.objects.all(),
date=self.timezone.localize(datetime.datetime(2008, 2, 7, 9, 0)),
tzinfo=self.timezone,
)
def test_day_range(self):
start = datetime.datetime(2008, 2, 6, 23, 0, tzinfo=pytz.utc)
end = datetime.datetime(2008, 2, 7, 23, 0, tzinfo=pytz.utc)
self.assertEqual(start, self.day.start)
self.assertEqual(end, self.day.end)
def test_occurence(self):
self.assertEqual(self.event in [o.event for o in self.day.occurrences], True)
示例5: add_new
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def add_new(self, user):
try:
client = Client.objects.get(pk=self.cleaned_data["client"])
if client.phone:
event_title = "{name} {phone} {id}".format(
name=client.get_full_name(), phone=client.phone, id=client.client_id
)
else:
event_title = "{name} {id}".format(name=client.get_full_name(), id=client.client_id)
event = Event(
start=parser.parse(self.cleaned_data["start_datetime"]),
end=parser.parse(self.cleaned_data["end_datetime"]),
title=event_title,
creator=user,
)
event.save()
appointment = Appointment(
client=client,
venue=Venue.objects.get(pk=self.cleaned_data["venue_id"]),
event=event,
creator=user,
customer=user.userprofile.customer,
)
appointment.save()
return appointment
except Client.DoesNotExist:
return False
示例6: setUp
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
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))
示例7: test_event_get_occurrences_after
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [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)
示例8: test_get_occurrence
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def test_get_occurrence(self):
event = Event(**self.recurring_data)
event.save()
occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
self.assertEqual(occurrence.start, datetime.datetime(2008,1,5,8))
occurrence.save()
occurrence = event.get_occurrence(datetime.datetime(2008, 1, 5, 8, 0))
self.assertTrue(occurrence.pk is not None)
示例9: test_event_get_occurrences
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [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],
[])
示例10: TestEventViews
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
class TestEventViews(LoggedInTestCase):
def setUp(self):
super(TestEventViews, self).setUp()
self.cal = Calendar(
name=random_string(),
slug=random_string(),
)
self.cal.save()
self.event = Event(
start=timezone.now(),
end=timezone.now() + timedelta(weeks=6),
title=random_string(),
calendar=self.cal,
)
self.event.save()
def tearDown(self):
super(TestEventViews, self).tearDown()
try:
self.cal.delete()
self.event.delete()
except:
pass
def test_event_can_be_recurring(self):
rule = Rule(
name=random_string(),
description=random_string(),
frequency='WEEKLY',
)
rule.save()
try:
url = reverse(
'openduty.events.create_or_edit_event',
kwargs = {
'calendar_slug': self.cal.slug,
'event_id': str(self.event.id),
},
)
response = self.client.post(
path = url,
data = {
"start_0": self.event.start.strftime('%Y-%m-%d'),
"start_1": "09:00",
"end_0": self.event.end.strftime('%Y-%m-%d'),
"end_1": "23:00",
"description": "desc",
"rule": str(rule.id),
"oncall": "foo",
"fallback": "bar",
},
)
self.assertEqual(302, response.status_code)
e = Event.objects.get(id=self.event.id)
self.assertEqual(rule, e.rule)
finally:
rule.delete()
示例11: TestOccurrence
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [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)
示例12: create_event
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def create_event(self, user):
start = parser.parse(self.cleaned_data["start_datetime"])
end = parser.parse(self.cleaned_data["end_datetime"])
new_event = Event(
start=start,
end=end,
title=self.cleaned_data["title"],
description=self.cleaned_data["description"],
creator=user,
)
new_event.save()
return new_event
示例13: test_get_escalation_fails_with_no_recurrence_after_event_end
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def test_get_escalation_fails_with_no_recurrence_after_event_end(self):
event = Event(
start = timezone.now() - timedelta(days=2),
end = timezone.now() - timedelta(days=1),
title = '{username},{username}'.format(username=self.username),
calendar = self.cal,
)
event.save()
try:
events = get_escalation_for_service(self.service)
self.assertEqual(0, len(events))
finally:
event.delete()
示例14: test_get_escalation_returns_empty_for_muted_services
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def test_get_escalation_returns_empty_for_muted_services(self):
event = Event(
start = timezone.now() - timedelta(days=1),
end = timezone.now() + timedelta(days=1),
title = '{username},{username}'.format(username=self.username),
calendar = self.cal,
)
event.save()
self.service.notifications_disabled = True
try:
events = get_escalation_for_service(self.service)
self.assertEqual(0, len(events))
finally:
event.delete()
示例15: setUp
# 需要导入模块: from schedule.models import Event [as 别名]
# 或者: from schedule.models.Event import save [as 别名]
def setUp(self):
rule = Rule(frequency = "WEEKLY")
rule.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,
}
recurring_event = Event(**data)
recurring_event.save()
self.month = Month(events=Event.objects.all(),
date=datetime.datetime(2008, 2, 7, 9, 0))