本文整理汇总了Python中schedule.periods.Period.classify_occurrence方法的典型用法代码示例。如果您正苦于以下问题:Python Period.classify_occurrence方法的具体用法?Python Period.classify_occurrence怎么用?Python Period.classify_occurrence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类schedule.periods.Period
的用法示例。
在下文中一共展示了Period.classify_occurrence方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: json_events
# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import classify_occurrence [as 别名]
def json_events(request):
ret = ''
if request.user.is_authenticated():
pcal = get_personal_calendar(request.user)
start = request.GET['start']
end = request.GET['end']
allowed_objects = set([])
perms = ['viewer', 'manager', 'creator']
ao = {}
for p in perms:
ao[p] = get_user_calendars(request.user, [p])
allowed_objects = allowed_objects.union(set(ao[p]))
for obj in allowed_objects:
evt = EventRelation.objects.get_events_for_object(
obj.content_object)
if obj.pk == pcal.pk or obj in ao['manager']:
manager = True
else:
manager = False
if obj.pk == pcal.pk or obj in ao['creator']:
creator = True
else:
creator = False
period = Period(events=evt, start=datetime.datetime.fromtimestamp(
float(start)), end=datetime.datetime.fromtimestamp(float(end)))
occurrences = []
for o in period.occurrences:
if period.classify_occurrence(o):
o.calendar_id = obj.pk
o.calendar_name = obj.calendar.name
if o.event.calendar_id == obj.calendar.pk:
o.manager = manager
o.creator = creator
else:
o.manager = False
o.creator = False
if o.id:
o.details = EventDetails.objects.get_eventdetails_for_object(
o)
else:
o.details = EventDetails.objects.get_eventdetails_for_object(
o.event)
if o.details.privacy == 2 and request.user != obj.owner: # Private event
continue
else:
occurrences.append(o)
if len(occurrences):
ret += '"' + obj.calendar.slug + '": ' + \
jsondump_occurences(occurrences, request.user) + ','
ret = ret[:-1]
ret = '{' + ret + '}'
# json_data = simplejson.dumps(ret)
return HttpResponse(ret)
示例2: month_cal
# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import classify_occurrence [as 别名]
def month_cal(context, year, month):
request = context['request']
ret = []
if request.user.is_authenticated():
evt = EventRelation.objects.get_events_for_object(request.user)
period = Period(events=evt, start=datetime.datetime(year, month, 1),
end=datetime.datetime(year, month, 30))
occurrences = []
for o in period.occurrences:
if period.classify_occurrence(o):
occurrences.append(o)
first_day_of_month = datetime.date(year, month, 1)
last_day_of_month = get_last_day_of_month(year, month)
first_day_of_calendar = first_day_of_month - \
datetime.timedelta(first_day_of_month.weekday())
last_day_of_calendar = last_day_of_month + \
datetime.timedelta(7 - last_day_of_month.weekday())
month_cal = []
week = []
week_headers = []
i = 0
day = first_day_of_calendar
while day <= last_day_of_calendar:
if i < 7:
week_headers.append(day)
cal_day = {}
cal_day['day'] = day
cal_day['event'] = False
for occ in ret:
if day >= occ.start.date() and day <= occ.end.date():
cal_day['event'] = True
if day.month == month:
cal_day['in_month'] = True
else:
cal_day['in_month'] = False
week.append(cal_day)
if day.weekday() == 6:
month_cal.append(week)
week = []
i += 1
day += datetime.timedelta(1)
return {'calendar': month_cal, 'headers': week_headers}
示例3: get_events_for_object
# 需要导入模块: from schedule.periods import Period [as 别名]
# 或者: from schedule.periods.Period import classify_occurrence [as 别名]
def get_events_for_object(obj, start_date, end_date):
occurrences = []
evt = EventRelation.objects.get_events_for_object(obj)
period = Period(events=evt, start=start_date, end=end_date)
for o in period.occurrences:
if period.classify_occurrence(o):
if o.id:
o.details = EventDetails.objects.get_eventdetails_for_object(o)
else:
o.details = EventDetails.objects.get_eventdetails_for_object(
o.event)
occurrences.append(o)
events_list = []
for occ in occurrences:
ed = {}
if occ.start.time().__str__() == '00:00:00' and occ.end.time().__str__() == '00:00:00':
ed['allday'] = True
else:
ed['allday'] = False
ed['title'] = occ.title
ed['start'] = occ.start
ed['end'] = occ.end
ed['status'] = get_date_status(
occ.start) # 'overdue', 'today' , 'tomorrow' or ''
ed['description'] = occ.description
ed['author'] = User.objects.get(
pk=occ.event.creator_id).get_full_name()
if occ.details.bgcolor:
ed['backgroundColor'] = occ.details.bgcolor
elif occ.details.category:
ed['backgroundColor'] = occ.details.category.bgcolor
ed['category'] = occ.details.category.name
else:
ed['backgroundColor'] = False
ed['category'] = ''
events_list.append(ed)
return events_list