本文整理汇总了Python中plone.event.interfaces.IEventAccessor.open_end方法的典型用法代码示例。如果您正苦于以下问题:Python IEventAccessor.open_end方法的具体用法?Python IEventAccessor.open_end怎么用?Python IEventAccessor.open_end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.event.interfaces.IEventAccessor
的用法示例。
在下文中一共展示了IEventAccessor.open_end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ical_import
# 需要导入模块: from plone.event.interfaces import IEventAccessor [as 别名]
# 或者: from plone.event.interfaces.IEventAccessor import open_end [as 别名]
def ical_import(container, ics_resource, event_type):
cal = icalendar.Calendar.from_ical(ics_resource)
events = cal.walk('VEVENT')
def _get_prop(prop, item):
ret = None
if prop in item:
ret = safe_unicode(item.decoded(prop))
return ret
def _from_list(ical, prop):
"""For EXDATE and RDATE recurrence component properties, the dates can
be defined within one EXDATE/RDATE line or for each date an individual
line.
In the latter case, icalendar creates a list.
This method handles this case.
TODO: component property parameters like TZID are not used here.
"""
val = prop in ical and ical[prop] or []
if not isinstance(val, list):
val = [val]
#ret = ''
#for item in val:
# ret = ret and '%s\n' % ret or ret # insert linebreak
# ret = '%s%s:%s' % (ret, prop, item.to_ical())
#return ret
# Zip multiple lines into one, since jquery.recurrenceinput.js does
# not support multiple lines here
# https://github.com/collective/jquery.recurrenceinput.js/issues/15
ret = ''
for item in val:
ret = ret and '%s,' % ret or ret # insert linebreak
ret = '%s%s' % (ret, item.to_ical())
return ret and '%s:%s' % (prop, ret) or None
count = 0
for item in events:
start = _get_prop('DTSTART', item)
end = _get_prop('DTEND', item)
if not end:
duration = _get_prop('DURATION', item)
if duration:
end = start + duration
# else: whole day or open end
timezone = getattr(getattr(start, 'tzinfo', None), 'zone', None) or\
base.default_timezone(container)
whole_day = False
open_end = False
if is_date(start) and (is_date(end) or end is None):
# All day / whole day events
# End must be same type as start (RFC5545, 3.8.2.2)
whole_day = True
if end is None:
end = start
if start < end:
# RFC5545 doesn't define clearly, if all day events should have
# a end date one day after the start day at 0:00.
# Internally, we handle all day events with start=0:00,
# end=:23:59:59, so we substract one day here.
end = end - datetime.timedelta(days=1)
start = base.dt_start_of_day(date_to_datetime(start))
end = base.dt_end_of_day(date_to_datetime(end))
elif is_datetime(start) and end is None:
# Open end event, see RFC 5545, 3.6.1
open_end = True
end = base.dt_end_of_day(date_to_datetime(start))
assert(is_datetime(start))
assert(is_datetime(end))
title = _get_prop('SUMMARY', item)
description = _get_prop('DESCRIPTION', item)
location = _get_prop('LOCATION', item)
url = _get_prop('URL', item)
rrule = _get_prop('RRULE', item)
rrule = rrule and 'RRULE:%s' % rrule.to_ical() or ''
rdates = _from_list(item, 'RDATE')
exdates = _from_list(item, 'EXDATE')
rrule = '\n'.join([it for it in [rrule, rdates, exdates] if it])
# TODO: attendee-lists are not decoded properly and contain only
# vCalAddress values
attendees = _get_prop('ATTENDEE', item)
contact = _get_prop('CONTACT', item)
categories = _get_prop('CATEGORIES', item)
if hasattr(categories, '__iter__'):
categories = [safe_unicode(it) for it in categories]
## for sync
#created = _get_prop('CREATED', item)
#modified = _get_prop('LAST-MODIFIED', item)
# TODO: better use plone.api, from which some of the code here is
# copied
#.........这里部分代码省略.........
示例2: ical_import
# 需要导入模块: from plone.event.interfaces import IEventAccessor [as 别名]
# 或者: from plone.event.interfaces.IEventAccessor import open_end [as 别名]
def ical_import(container, ics_resource, event_type):
cal = icalendar.Calendar.from_ical(ics_resource)
events = cal.walk('VEVENT')
def _get_prop(prop, item):
ret = None
if prop in item:
ret = safe_unicode(item.decoded(prop))
return ret
count = 0
for item in events:
start = _get_prop('DTSTART', item)
end = _get_prop('DTEND', item)
if not end:
duration = _get_prop('DURATION', item)
if duration:
end = start + duration
# else: whole day or open end
timezone = getattr(getattr(start, 'tzinfo', None), 'zone', None) or\
base.default_timezone(container)
whole_day = False
open_end = False
if is_date(start) and (is_date(end) or end is None):
# All day / whole day events
# End must be same type as start (RFC5545, 3.8.2.2)
whole_day = True
if end is None: end = start
if start < end:
# RFC5545 doesn't define clearly, if all day events should have
# a end date one day after the start day at 0:00.
# Internally, we handle all day events with start=0:00,
# end=:23:59:59, so we substract one day here.
end = end - datetime.timedelta(days=1)
start = base.dt_start_of_day(date_to_datetime(start))
end = base.dt_end_of_day(date_to_datetime(end))
elif is_datetime(start) and end is None:
# Open end event, see RFC 5545, 3.6.1
open_end = True
end = base.dt_end_of_day(date_to_datetime(start))
assert(is_datetime(start))
assert(is_datetime(end))
title = _get_prop('SUMMARY', item)
description = _get_prop('DESCRIPTION', item)
location = _get_prop('LOCATION', item)
url = _get_prop('URL', item)
rrule = _get_prop('RRULE', item)
rrule = rrule and 'RRULE:%s' % rrule.to_ical() or ''
rdate = _get_prop('RDATE', item)
rrule = rdate and '%s\nRDATE:%s' % (rrule, rdate.to_ical()) or ''
exdate = _get_prop('EXDATE', item)
rrule = exdate and '%s\nEXDATE:%s' % (rrule, exdate.to_ical()) or ''
attendees = _get_prop('ATTENDEE', item)
contact = _get_prop('CONTACT', item)
categories = _get_prop('CATEGORIES', item)
if hasattr(categories, '__iter__'):
categories = [safe_unicode(it) for it in categories]
# for sync
created = _get_prop('CREATED', item)
modified = _get_prop('LAST-MODIFIED', item)
# TODO: better use plone.api, from which some of the code here is
# copied
content_id = str(random.randint(0, 99999999))
# TODO: if AT had the same attrs like IDXEventBase, we could set
# everything within this invokeFactory call.
container.invokeFactory(event_type,
id=content_id,
title=title,
description=description)
content = container[content_id]
event = IEventAccessor(content)
event.start = start
event.end = end
event.timezone = timezone
event.whole_day = whole_day
event.open_end = open_end
event.location = location
event.event_url = url
event.recurrence = rrule
event.attendees = attendees
event.contact_name = contact
event.subjects = categories
notify(ObjectModifiedEvent(content))
# Archetypes specific code
if getattr(content, 'processForm', False):
# Will finish Archetypes content item creation process,
# rename-after-creation and such
content.processForm()
#.........这里部分代码省略.........
示例3: ical_import
# 需要导入模块: from plone.event.interfaces import IEventAccessor [as 别名]
# 或者: from plone.event.interfaces.IEventAccessor import open_end [as 别名]
def ical_import(container, ics_resource, event_type,
sync_strategy=base.SYNC_KEEP_NEWER):
cal = icalendar.Calendar.from_ical(ics_resource)
events = cal.walk('VEVENT')
cat = getToolByName(container, 'portal_catalog')
container_path = '/'.join(container.getPhysicalPath())
def _get_by_sync_uid(uid):
return cat(
sync_uid=uid,
path={'query': container_path, 'depth': 1}
)
def _get_prop(prop, item, default=None):
ret = default
if prop in item:
ret = safe_unicode(item.decoded(prop))
return ret
def _from_list(ical, prop):
"""For EXDATE and RDATE recurrence component properties, the dates can
be defined within one EXDATE/RDATE line or for each date an individual
line.
In the latter case, icalendar creates a list.
This method handles this case.
TODO: component property parameters like TZID are not used here.
"""
val = prop in ical and ical[prop] or []
if not isinstance(val, list):
val = [val]
#ret = ''
#for item in val:
# ret = ret and '%s\n' % ret or ret # insert linebreak
# ret = '%s%s:%s' % (ret, prop, item.to_ical())
#return ret
# Zip multiple lines into one, since jquery.recurrenceinput.js does
# not support multiple lines here
# https://github.com/collective/jquery.recurrenceinput.js/issues/15
ret = ''
for item in val:
ret = ret and '%s,' % ret or ret # insert linebreak
ret = '%s%s' % (ret, item.to_ical())
return ret and '%s:%s' % (prop, ret) or None
count = 0
for item in events:
start = _get_prop('DTSTART', item)
end = _get_prop('DTEND', item)
if not end:
duration = _get_prop('DURATION', item)
if duration:
end = start + duration
# else: whole day or open end
timezone = getattr(getattr(start, 'tzinfo', None), 'zone', None) or\
base.default_timezone(container)
whole_day = False
open_end = False
if is_date(start) and (is_date(end) or end is None):
# All day / whole day events
# End must be same type as start (RFC5545, 3.8.2.2)
whole_day = True
if end is None:
end = start
if start < end:
# RFC5545 doesn't define clearly, if all day events should have
# a end date one day after the start day at 0:00.
# Internally, we handle all day events with start=0:00,
# end=:23:59:59, so we substract one day here.
end = end - datetime.timedelta(days=1)
start = base.dt_start_of_day(date_to_datetime(start))
end = base.dt_end_of_day(date_to_datetime(end))
elif is_datetime(start) and end is None:
# Open end event, see RFC 5545, 3.6.1
open_end = True
end = base.dt_end_of_day(date_to_datetime(start))
assert(is_datetime(start))
assert(is_datetime(end))
title = _get_prop('SUMMARY', item)
description = _get_prop('DESCRIPTION', item)
location = _get_prop('LOCATION', item)
url = _get_prop('URL', item)
rrule = _get_prop('RRULE', item)
rrule = rrule and 'RRULE:%s' % rrule.to_ical() or ''
rdates = _from_list(item, 'RDATE')
exdates = _from_list(item, 'EXDATE')
rrule = '\n'.join([it for it in [rrule, rdates, exdates] if it])
# TODO: attendee-lists are not decoded properly and contain only
# vCalAddress values
attendees = item.get('ATTENDEE', ())
contact = _get_prop('CONTACT', item)
#.........这里部分代码省略.........
示例4: ical_import
# 需要导入模块: from plone.event.interfaces import IEventAccessor [as 别名]
# 或者: from plone.event.interfaces.IEventAccessor import open_end [as 别名]
def ical_import(container, ics_resource, event_type,
sync_strategy=base.SYNC_KEEP_NEWER):
cal = icalendar.Calendar.from_ical(ics_resource)
events = cal.walk('VEVENT')
cat = getToolByName(container, 'portal_catalog')
container_path = '/'.join(container.getPhysicalPath())
def _get_by_sync_uid(uid):
return cat(
sync_uid=uid,
path={'query': container_path, 'depth': 1}
)
def _get_prop(prop, item, default=None):
ret = default
if prop in item:
ret = safe_unicode(item.decoded(prop))
return ret
def _from_list(ical, prop):
"""For EXDATE and RDATE recurrence component properties, the dates can
be defined within one EXDATE/RDATE line or for each date an individual
line.
In the latter case, icalendar creates a list.
This method handles this case.
TODO: component property parameters like TZID are not used here.
"""
val = ical[prop] if prop in ical else []
if not isinstance(val, list):
val = [val]
# Zip multiple lines into one, since jquery.recurrenceinput.js does
# not support multiple lines here
# https://github.com/collective/jquery.recurrenceinput.js/issues/15
ret = ''
for item in val:
ret = '%s,' % ret if ret else ret # insert linebreak
ical_val = item.to_ical()
if six.PY3 and isinstance(ical_val, six.binary_type):
ical_val = ical_val.decode('utf8')
ret = '%s%s' % (ret, ical_val)
return '%s:%s' % (prop, ret) if ret else None
count = 0
for item in events:
start = _get_prop('DTSTART', item)
end = _get_prop('DTEND', item)
if not end:
duration = _get_prop('DURATION', item)
if duration:
end = start + duration
# else: whole day or open end
whole_day = False
open_end = False
if is_date(start) and (is_date(end) or end is None):
# All day / whole day events
# End must be same type as start (RFC5545, 3.8.2.2)
whole_day = True
if end is None:
end = start
if start < end:
# RFC5545 doesn't define clearly, if all day events should have
# a end date one day after the start day at 0:00.
# Internally, we handle all day events with start=0:00,
# end=:23:59:59, so we substract one day here.
end = end - datetime.timedelta(days=1)
start = base.dt_start_of_day(date_to_datetime(start))
end = base.dt_end_of_day(date_to_datetime(end))
elif is_datetime(start) and end is None:
# Open end event, see RFC 5545, 3.6.1
open_end = True
end = base.dt_end_of_day(date_to_datetime(start))
assert(is_datetime(start))
assert(is_datetime(end))
# Set timezone, if not already set
tz = base.default_timezone(container, as_tzinfo=True)
if not getattr(start, 'tzinfo', False):
start = tz.localize(start)
if not getattr(end, 'tzinfo', False):
end = tz.localize(end)
title = _get_prop('SUMMARY', item)
description = _get_prop('DESCRIPTION', item)
location = _get_prop('LOCATION', item)
url = _get_prop('URL', item)
rrule = _get_prop('RRULE', item)
rrule = rrule.to_ical() if rrule else ''
if rrule:
if six.PY3 and isinstance(rrule, six.binary_type):
rrule = rrule.decode('utf8')
rrule = 'RRULE:%s' % rrule
rdates = _from_list(item, 'RDATE')
exdates = _from_list(item, 'EXDATE')
rrule = '\n'.join([it for it in [rrule, rdates, exdates] if it])
#.........这里部分代码省略.........