本文整理汇总了Python中plone.event.interfaces.IOccurrence类的典型用法代码示例。如果您正苦于以下问题:Python IOccurrence类的具体用法?Python IOccurrence怎么用?Python IOccurrence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IOccurrence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_generation_context
def _get_generation_context(self, helper_view, pod_template):
result = super(IDocumentGenerationView, self)._get_generation_context(
helper_view, pod_template)
# if pod_template.portal_type == 'ConfigurablePODTemplate':
if IFacetedNavigable.providedBy(self.context):
brains = getDashboardQueryResult(self.context)
result['brains'] = brains
if len(brains) > 0 and brains[0].portal_type == 'Event':
expandevents = expand_events(brains, 2)
events = []
for event in expandevents:
if IOccurrence.providedBy(event):
start = event.start
end = event.end
parent = zope.copy.copy(event.aq_parent.aq_base)
parent.start = start
parent.end = end
req = event.REQUEST
parent.REQUEST = req
parent.occurrence = True
parent.base_event = event.aq_parent
events.append(parent)
else:
events.append(event)
result['brains'] = events
return result
示例2: ticket_title_generator
def ticket_title_generator(obj):
"""Generate a title for the ticket, also using event information.
"""
event = obj
ret = {
'title': obj.title, 'eventtitle': '', 'eventstart': '', 'eventend': ''
}
if ITicketOccurrence.providedBy(event):
event = aq_parent(aq_parent(event))
# Traverse to the Occurrence object
if IATEvent.providedBy(event):
# get the request out of thin air to be able to publishTraverse to
# the transient Occurrence object.
traverser = OccTravAT(event, getRequest())
elif IDXEvent.providedBy(event):
# TODO
traverser = OccTravDX(event, getRequest())
else:
raise NotImplementedError(
u"There is no event occurrence traverser implementation for "
u"this kind of object."
)
try:
event = traverser.publishTraverse(getRequest(), obj.id)
except KeyError:
# Maybe the ticket occurrence isn't valid anymore because the
# event occurence doesn't exist anymore.
# Just ignore that case.
return ret
elif ITicket.providedBy(event):
event = aq_parent(event)
if IEvent.providedBy(event) or IOccurrence.providedBy(event):
acc = IEventAccessor(event)
lstart = ulocalized_time(
DT(acc.start),
long_format=True,
context=event
)
lend = ulocalized_time(
DT(acc.start),
long_format=True,
context=event
)
# XXX: no unicode, store as utf-8 encoded string instead
ret = dict(
title=u'%s - %s (%s - %s)' % (
safe_unicode(acc.title),
safe_unicode(obj.title),
lstart,
lend,
),
eventtitle=acc.title,
eventstart=acc.start,
eventend=acc.end,
)
return ret
示例3: test_recurrence_occurrences_with_range_start_2
def test_recurrence_occurrences_with_range_start_2(self):
# Test with range
rs = datetime.datetime(2011, 11, 16, 11, 0, tzinfo=self.tz)
result = IRecurrenceSupport(self.data).occurrences(range_start=rs)
self.assertEqual(3, len(result))
# Only IOccurrence objects in the result set
self.assertTrue(IOccurrence.providedBy(result[0]))
示例4: test_recurrence_occurrences
def test_recurrence_occurrences(self):
result = IRecurrenceSupport(self.data).occurrences()
self.assertEqual(4, len(result))
# First occurrence is an IEvent object
self.assertTrue(IEvent.providedBy(result[0]))
# Subsequent ones are IOccurrence objects
self.assertTrue(IOccurrence.providedBy(result[1]))
示例5: test_recurrence_occurrences_with_range_start_1
def test_recurrence_occurrences_with_range_start_1(self):
# Test with range
rs = datetime.datetime(2011, 11, 15, 11, 0, tzinfo=self.tz)
result = IRecurrenceSupport(self.data).occurrences(range_start=rs)
self.assertEqual(4, len(result))
# First occurrence is an IEvent object
self.assertTrue(IEvent.providedBy(result[0]))
# Subsequent ones are IOccurrence objects
self.assertTrue(IOccurrence.providedBy(result[1]))
示例6: childsiteForContext
def childsiteForContext(self, item):
"""Returns the childsite UUID for a context object by looking up it's
brain in the catalog.
"""
childsite = ''
if IOccurrence and IOccurrence.providedBy(item):
item = aq_parent(item)
portal = plone.api.portal.get()
cat = getToolByName(self.context, 'portal_catalog')
res = cat(UID=IUUID(item, None), path=portal.getPhysicalPath())
if res:
childsite = res[0].childsite
return childsite
示例7: test_occurrence
def test_occurrence(self):
# start date of self.now_event = 2013-05-05, 10:00.
# recurrence rule = 'RRULE:FREQ=DAILY;COUNT=3;INTERVAL=2'
# Try to traverse to inexistent occurrence
self.assertRaises(
AttributeError,
self.traverser.publishTraverse,
self.request, '2000-01-01')
# Traverse to existent occurrence
item = self.traverser.publishTraverse(self.request, '2013-05-07')
self.assertTrue(IOccurrence.providedBy(item))
self.assertEqual(type(self.now_event), type(item.aq_parent))
示例8: test_occurrence
def test_occurrence(self):
self.at.setRecurrence('RRULE:FREQ=WEEKLY;COUNT=10')
# does not match occurrence date
qdate = datetime.date.today() + datetime.timedelta(days=4)
self.assertRaises(
AttributeError,
self.at_traverser.publishTraverse,
self.layer['request'], str(qdate))
qdatedt = pydt(self.at.start() + 7)
item = self.at_traverser.publishTraverse(self.layer['request'],
str(qdatedt.date()))
self.assertTrue(IOccurrence.providedBy(item))
self.assertTrue(IATEvent.providedBy(item.aq_parent))
示例9: test_recurrence_occurrences_with_range_start_and_end
def test_recurrence_occurrences_with_range_start_and_end(self):
# Test with range
rs = datetime.datetime(2011, 11, 11, 11, 0, tzinfo=self.tz)
re = datetime.datetime(2011, 11, 12, 11, 0, tzinfo=self.tz)
result = IRecurrenceSupport(self.data).occurrences(range_start=rs,
range_end=re)
result = list(result) # cast generator to list
self.assertEqual(2, len(result))
# First occurrence is an IEvent object
self.assertTrue(IEvent.providedBy(result[0]))
# Subsequent ones are IOccurrence objects
self.assertTrue(IOccurrence.providedBy(result[1]))
示例10: test_recurrence
def test_recurrence(self):
tz = pytz.timezone('Europe/Vienna')
duration = datetime.timedelta(days=4)
data = MockEvent()
data.start = datetime.datetime(2011, 11, 11, 11, 00, tzinfo=tz)
data.end = data.start + duration
data.recurrence = 'RRULE:FREQ=DAILY;COUNT=4'
zope.interface.alsoProvides(data, IEvent, IEventRecurrence)
result = IRecurrenceSupport(data).occurrences()
self.assertEqual(4, len(result))
# First occurrence is an IEvent object
self.assertTrue(IEvent.providedBy(result[0]))
# Subsequent ones are IOccurrence objects
self.assertTrue(IOccurrence.providedBy(result[1]))
示例11: test_recurrence
def test_recurrence(self):
tz = pytz.timezone('Europe/Vienna')
duration = timedelta(days=4)
mock = MockEvent()
mock.start = tz.localize(datetime(2011, 11, 11, 11, 0))
mock.end = mock.start + duration
mock.recurrence = 'RRULE:FREQ=DAILY;COUNT=4'
zope.interface.alsoProvides(
mock, IEvent, IEventBasic, IEventRecurrence,
IDXEvent, IDXEventRecurrence)
result = IRecurrenceSupport(mock).occurrences()
result = list(result) # cast generator to list
self.assertEqual(4, len(result))
# First occurrence is an IEvent object
self.assertTrue(IEvent.providedBy(result[0]))
# Subsequent ones are IOccurrence objects
self.assertTrue(IOccurrence.providedBy(result[1]))
示例12: attachments
def attachments(self):
context = aq_inner(self.context)
if IOccurrence.providedBy(context):
# support for related images on event occurrences
context = context.aq_parent
atts = IRelatedMedia(context).related_attachments
_target_blank = api.portal.get_registry_record(
'collective.behavior.relatedmedia.open_attachment_in_new_window')
link_target = _target_blank and 'blank' or 'top'
for att in atts:
att_obj = att.to_object
if att_obj:
yield dict(
url=att_obj.absolute_url(),
title=att_obj.Title(),
size="{:.1f} MB".format(
att_obj.file.getSize() / 1024.0 / 1024.0),
icon=att_obj.getIcon(),
target=link_target,
)
示例13: test_occurrence
def test_occurrence(self):
# start date of self.now_event = 2013-05-05, 10:00.
# recurrence rule = 'RRULE:FREQ=DAILY;COUNT=3;INTERVAL=2'
# Try to traverse to inexistent occurrence
self.assertRaises(
AttributeError,
self.traverser.publishTraverse,
self.request, '2000-01-01')
# Traverse to existent occurrence
item = self.traverser.publishTraverse(self.request, '2013-05-07')
self.assertTrue(IOccurrence.providedBy(item))
self.assertEqual(type(self.now_event), type(item.aq_parent))
# Test attributes of Occurrence
self.assertEqual(item.portal_type, 'Occurrence')
self.assertEqual(item.id, '2013-05-07')
delta = datetime.timedelta(days=2)
self.assertEqual(item.start, self.now + delta)
self.assertEqual(item.end, self.now + delta + self.duration)
示例14: recurrence
def recurrence(self):
if not self.event.recurrence or IOccurrence.providedBy(self.context):
return None
ret = []
for recdef in self.event.recurrence.split():
prop, val = recdef.split(':')
if prop == 'RRULE':
ret.append({
'property': prop,
'value': icalendar.prop.vRecur.from_ical(val)
})
elif prop in ('EXDATE', 'RDATE'):
factory = icalendar.prop.vDDDLists
# localize ex/rdate
# TODO: should better already be localized by event object
tzid = self.event.timezone
if isinstance(tzid, tuple):
tzid = tzid[0]
# get list of datetime values from ical string
try:
dtlist = factory.from_ical(val, timezone=tzid)
except ValueError:
# TODO: caused by a bug in plone.formwidget.recurrence,
# where the recurrencewidget or plone.event fails with
# COUNT=1 and a extra RDATE.
# TODO: REMOVE this workaround, once this failure is
# fixed in recurrence widget.
continue
ret.append({
'property': prop,
'value': dtlist
})
return ret
示例15: is_occurrence
def is_occurrence(self):
return IOccurrence.providedBy(self.context)