本文整理汇总了Python中schedule.periods.Month类的典型用法代码示例。如果您正苦于以下问题:Python Month类的具体用法?Python Month怎么用?Python Month使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Month类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_years_before_1900
def test_years_before_1900(self):
d = datetime.date(year=1899, month=1, day=1)
m = Month([], d)
try:
m.name()
except ValueError as value_error:
self.fail(value_error)
示例2: monthly_schedule
def monthly_schedule(request, year, month):
if int(year) > 2037 or int(year) < 1970 or int(month) < 1 or int(month) > 12:
raise Http404
MonthlyScheduleFormset = formset_factory(wraps(MonthlyScheduleForm)(partial(MonthlyScheduleForm, days=monthrange(int(year), int(month))[1])), extra=0)
initial_data = []
for barber in Barber.objects.all():
data = {}
calendar = Calendar.objects.get_or_create(name='barber_schedule')[0]
month_period = Month(calendar.events.get_for_object(barber), datetime(int(year), int(month), 1))
for day_period in month_period.get_days():
if day_period.has_occurrences():
data['day_{}'.format(day_period.start.day)] = True
initial_data.append(data)
if request.method == 'POST':
formset = MonthlyScheduleFormset(request.POST, initial=initial_data)
if formset.is_valid():
for form, barber in zip(formset, Barber.objects.all()):
for day in form.changed_data:
if not form.cleaned_data[day]:
calendar = Calendar.objects.get(name='barber_schedule')
events = calendar.events.get_for_object(barber)
period = Day(events, datetime(int(year), int(month), int(day[4:])))
if period.has_occurrences():
for occurrence in period.get_occurrences():
Event.objects.get(id=occurrence.event_id).delete()
else:
calendar = Calendar.objects.get_or_create(name='barber_schedule')[0]
event = Event(
start=make_aware(datetime(int(year), int(month), int(day[4:]), settings.DAY_START)),
end=make_aware(datetime(int(year), int(month), int(day[4:]), settings.DAY_END))
)
event.save()
calendar.events.add(event)
relation = EventRelation.objects.create_relation(event, barber)
relation.save()
else:
formset = MonthlyScheduleFormset(initial=initial_data)
context = dict(
admin.site.each_context(request),
days=range(1, monthrange(int(year), int(month))[1] + 1),
first_weekday=monthrange(int(year), int(month))[0],
barbers=zip(Barber.objects.all(), formset),
formset=formset,
prev_date=(datetime(int(year), int(month), 1) - timedelta(days=1)),
current_date=datetime.now(),
next_date=(datetime(int(year), int(month), monthrange(int(year), int(month))[1]) + timedelta(days=1)),
)
if request.method == 'POST':
return redirect(reverse('admin:monthly_schedule', kwargs={'year': year, 'month': month}), context)
else:
return render(request, 'admin/monthly_schedule.html', context)
示例3: TestMonth
class TestMonth(TestCase):
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))
def test_get_weeks(self):
weeks = self.month.get_weeks()
self.assertEqual([(week.start,week.end) for week in weeks],
[
(datetime.datetime(2008, 1, 27, 0, 0),
datetime.datetime(2008, 2, 3, 0, 0)),
(datetime.datetime(2008, 2, 3, 0, 0),
datetime.datetime(2008, 2, 10, 0, 0)),
(datetime.datetime(2008, 2, 10, 0, 0),
datetime.datetime(2008, 2, 17, 0, 0)),
(datetime.datetime(2008, 2, 17, 0, 0),
datetime.datetime(2008, 2, 24, 0, 0)),
(datetime.datetime(2008, 2, 24, 0, 0),
datetime.datetime(2008, 3, 2, 0, 0))
])
def test_get_days(self):
weeks = self.month.get_weeks()
week = weeks[0]
days = week.get_days()
self.assertEqual(
[
(len(day.occurrences), day.start,day.end) for day in days
],
[
(0, datetime.datetime(2008, 1, 27, 0, 0),
datetime.datetime(2008, 1, 28, 0, 0)),
(0, datetime.datetime(2008, 1, 28, 0, 0),
datetime.datetime(2008, 1, 29, 0, 0)),
(0, datetime.datetime(2008, 1, 29, 0, 0),
datetime.datetime(2008, 1, 30, 0, 0)),
(0, datetime.datetime(2008, 1, 30, 0, 0),
datetime.datetime(2008, 1, 31, 0, 0)),
(0, datetime.datetime(2008, 1, 31, 0, 0),
datetime.datetime(2008, 2, 1, 0, 0)),
(0, datetime.datetime(2008, 2, 1, 0, 0),
datetime.datetime(2008, 2, 2, 0, 0)),
(1, datetime.datetime(2008, 2, 2, 0, 0),
datetime.datetime(2008, 2, 3, 0, 0))]
)
示例4: test_get_values
def test_get_values(self):
self.client.login(username='admin', password='pa55w0rd')
date = datetime.datetime(2015, 6, 1)
resp = self.client.get(reverse('admin:monthly_schedule', kwargs={'year': date.year, 'month': date.month}))
formset = resp.context['formset']
self.assertEqual(len(formset), Barber.objects.all().count())
for form, barber in zip(formset, Barber.objects.all()):
month = Month(self.calendar.events.get_for_object(barber), date=date)
self.assertEqual(len(form.visible_fields()), len(list(month.get_days())))
self.assertEqual(len(form.changed_data), len(month.get_occurrences()))
for day, occ in zip(form.changed_data, month.cached_get_sorted_occurrences()):
self.assertEqual(int(day[4:]), occ.end.day)
示例5: month_table
def month_table(context, calendar, month, size="regular", shift=None):
if shift:
if shift == -1:
month = Month(calendar.events.all(), month.prev())
if shift == 1:
month = Month(calendar.events.all(), month.next())
if size == "small":
context['day_names'] = weekday_abbrs
else:
context['day_names'] = weekday_names
context['calendar'] = calendar
context['month'] = month
context['size'] = size
return context
示例6: setUp
def setUp(self):
rule = Rule.objects.create(frequency="WEEKLY")
cal = Calendar.objects.create(name="MyCal")
Event.objects.create(
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.month = Month(events=Event.objects.all(),
date=datetime.datetime(2008, 2, 7, 9, 0, tzinfo=pytz.utc))
示例7: TestMonth
class TestMonth(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.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
def test_get_weeks(self):
weeks = self.month.get_weeks()
self.assertEqual(
[(week.start, week.end) for week in weeks],
[
(datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)),
(datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 10, 0, 0)),
(datetime.datetime(2008, 2, 10, 0, 0), datetime.datetime(2008, 2, 17, 0, 0)),
(datetime.datetime(2008, 2, 17, 0, 0), datetime.datetime(2008, 2, 24, 0, 0)),
(datetime.datetime(2008, 2, 24, 0, 0), datetime.datetime(2008, 3, 2, 0, 0)),
],
)
def test_get_days(self):
weeks = self.month.get_weeks()
week = weeks[0]
days = week.get_days()
self.assertEqual(
[(len(day.occurrences), day.start, day.end) for day in days],
[
(0, datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 1, 28, 0, 0)),
(0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)),
(0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)),
(0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)),
(0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)),
(0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)),
(1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)),
],
)
def test_month_convenience_functions(self):
self.assertEqual(self.month.prev_month(), datetime.datetime(2008, 1, 1, 0, 0))
self.assertEqual(self.month.next_month(), datetime.datetime(2008, 3, 1, 0, 0))
self.assertEqual(self.month.current_year(), datetime.datetime(2008, 1, 1, 0, 0))
self.assertEqual(self.month.prev_year(), datetime.datetime(2007, 1, 1, 0, 0))
self.assertEqual(self.month.next_year(), datetime.datetime(2009, 1, 1, 0, 0))
示例8: setUp
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))
示例9: setUp
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.month = Month(events=Event.objects.all(),
date=datetime.datetime(2008, 2, 7, 9, 0, tzinfo=pytz.utc))
示例10: setUp
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.month = Month(reservations=Reservation.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
示例11: setUp
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.month = Month(events=Event.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
示例12: TestMonth
class TestMonth(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
}
recurring_event = Event(**data)
recurring_event.save()
self.month = Month(events=Event.objects.all(),
date=datetime.datetime(2008, 2, 7, 9, 0, tzinfo=pytz.utc))
def test_get_weeks(self):
weeks = self.month.get_weeks()
actuals = [(week.start, week.end) for week in weeks]
if settings.FIRST_DAY_OF_WEEK == 0:
expecteds = [
(datetime.datetime(2008, 1, 27, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 3, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 3, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 10, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 10, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 17, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 17, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 24, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 24, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 3, 2, 0, 0, tzinfo=pytz.utc))
]
else:
expecteds = [
(datetime.datetime(2008, 1, 28, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 4, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 4, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 11, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 11, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 18, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 18, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 25, 0, 0, tzinfo=pytz.utc)),
(datetime.datetime(2008, 2, 25, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 3, 3, 0, 0, tzinfo=pytz.utc))
]
for actual, expected in zip(actuals, expecteds):
self.assertEqual(actual, expected)
def test_get_days(self):
weeks = self.month.get_weeks()
week = list(weeks)[0]
days = week.get_days()
actuals = [(len(day.occurrences), day.start,day.end) for day in days]
if settings.FIRST_DAY_OF_WEEK == 0:
expecteds = [
(
0,
datetime.datetime(2008, 1, 27, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 1, 28, 0, 0, tzinfo=pytz.utc)
),
(
0,
datetime.datetime(2008, 1, 28, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 1, 29, 0, 0, tzinfo=pytz.utc)
),
(
0,
datetime.datetime(2008, 1, 29, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 1, 30, 0, 0, tzinfo=pytz.utc)
),
(
0,
datetime.datetime(2008, 1, 30, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 1, 31, 0, 0, tzinfo=pytz.utc)
),
(
0,
datetime.datetime(2008, 1, 31, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 1, 0, 0, tzinfo=pytz.utc)
),
(
0,
datetime.datetime(2008, 2, 1, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 2, 0, 0, tzinfo=pytz.utc)
),
(
1,
datetime.datetime(2008, 2, 2, 0, 0, tzinfo=pytz.utc),
datetime.datetime(2008, 2, 3, 0, 0, tzinfo=pytz.utc)
),
]
else:
#.........这里部分代码省略.........
示例13: TestMonth
class TestMonth(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.month = Month(reservations=Reservation.objects.all(), date=datetime.datetime(2008, 2, 7, 9, 0))
def test_get_weeks(self):
weeks = self.month.get_weeks()
actuals = [(week.start, week.end) for week in weeks]
if FIRST_DAY_OF_WEEK == 0:
expecteds = [
(datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)),
(datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 10, 0, 0)),
(datetime.datetime(2008, 2, 10, 0, 0), datetime.datetime(2008, 2, 17, 0, 0)),
(datetime.datetime(2008, 2, 17, 0, 0), datetime.datetime(2008, 2, 24, 0, 0)),
(datetime.datetime(2008, 2, 24, 0, 0), datetime.datetime(2008, 3, 2, 0, 0)),
]
else:
expecteds = [
(datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)),
(datetime.datetime(2008, 2, 4, 0, 0), datetime.datetime(2008, 2, 11, 0, 0)),
(datetime.datetime(2008, 2, 11, 0, 0), datetime.datetime(2008, 2, 18, 0, 0)),
(datetime.datetime(2008, 2, 18, 0, 0), datetime.datetime(2008, 2, 25, 0, 0)),
(datetime.datetime(2008, 2, 25, 0, 0), datetime.datetime(2008, 3, 3, 0, 0)),
]
for actual, expected in zip(actuals, expecteds):
self.assertEqual(actual, expected)
def test_get_days(self):
weeks = self.month.get_weeks()
week = list(weeks)[0]
days = week.get_days()
actuals = [(len(day.occurrences), day.start, day.end) for day in days]
if FIRST_DAY_OF_WEEK == 0:
expecteds = [
(0, datetime.datetime(2008, 1, 27, 0, 0), datetime.datetime(2008, 1, 28, 0, 0)),
(0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)),
(0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)),
(0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)),
(0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)),
(0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)),
(1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)),
]
else:
expecteds = [
(0, datetime.datetime(2008, 1, 28, 0, 0), datetime.datetime(2008, 1, 29, 0, 0)),
(0, datetime.datetime(2008, 1, 29, 0, 0), datetime.datetime(2008, 1, 30, 0, 0)),
(0, datetime.datetime(2008, 1, 30, 0, 0), datetime.datetime(2008, 1, 31, 0, 0)),
(0, datetime.datetime(2008, 1, 31, 0, 0), datetime.datetime(2008, 2, 1, 0, 0)),
(0, datetime.datetime(2008, 2, 1, 0, 0), datetime.datetime(2008, 2, 2, 0, 0)),
(1, datetime.datetime(2008, 2, 2, 0, 0), datetime.datetime(2008, 2, 3, 0, 0)),
(0, datetime.datetime(2008, 2, 3, 0, 0), datetime.datetime(2008, 2, 4, 0, 0)),
]
for actual, expected in zip(actuals, expecteds):
self.assertEqual(actual, expected)
def test_month_convenience_functions(self):
self.assertEqual(self.month.prev_month().start, datetime.datetime(2008, 1, 1, 0, 0))
self.assertEqual(self.month.next_month().start, datetime.datetime(2008, 3, 1, 0, 0))
self.assertEqual(self.month.current_year().start, datetime.datetime(2008, 1, 1, 0, 0))
self.assertEqual(self.month.prev_year().start, datetime.datetime(2007, 1, 1, 0, 0))
self.assertEqual(self.month.next_year().start, datetime.datetime(2009, 1, 1, 0, 0))