本文整理汇总了Python中plone.event.interfaces.IEvent.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IEvent.providedBy方法的具体用法?Python IEvent.providedBy怎么用?Python IEvent.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.event.interfaces.IEvent
的用法示例。
在下文中一共展示了IEvent.providedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timezone_handler
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def timezone_handler(obj, event):
""" When setting the startDate and endDate, the value of the timezone field
isn't known, so we have to convert those timezone-naive dates into
timezone-aware ones afterwards.
"""
if not IEvent.providedBy(obj):
# don't run me, if i'm not installed
return
timezone = obj.getField('timezone').get(obj)
start_field = obj.getField('startDate')
end_field = obj.getField('endDate')
start = start_field.get(obj)
end = end_field.get(obj)
def make_DT(value, timezone):
return DateTime(
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
timezone)
start = make_DT(start, timezone).toZone('UTC')
end = make_DT(end, timezone).toZone('UTC')
start_field.set(obj, start)
end_field.set(obj, end)
obj.reindexObject()
示例2: EventTypes
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def EventTypes(context):
""" Vocabulary for available event types.
Insane stuff: All types are created temporary and checked if the provide
the IEvent interface. At least, this function is cached forever the Zope
process lives.
"""
# TODO: I'd love to query the factory for types, who's instances are
# implementing a specific interface via the portal_factory API.
portal = getSite()
tmp_folder_id = 'event_types_temp_folder__%s' % random.randint(0, 99999999)
portal.invokeFactory('Folder', tmp_folder_id)
try:
tmp_folder = portal._getOb(tmp_folder_id)
portal_types = getToolByName(portal, 'portal_types')
all_types = portal_types.listTypeInfo(portal)
event_types = []
cnt = 0
for fti in all_types:
if not getattr(fti, 'global_allow', False):
continue
cnt += 1
tmp_id = 'temporary__event_types__%s' % cnt
tmp_obj = None
fti.constructInstance(tmp_folder, tmp_id)
tmp_obj = tmp_folder._getOb(tmp_id)
if tmp_obj:
if IEvent.providedBy(tmp_obj):
event_types.append(fti.id)
finally:
# Delete the tmp_folder again
tmp_folder.__parent__.manage_delObjects([tmp_folder_id])
return SimpleVocabulary.fromValues(event_types)
示例3: ticket_title_generator
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
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
示例4: test_fix_interface_for_event
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def test_fix_interface_for_event(self):
self.obj.portal_type = 'Event'
self.catalog.reindexObject(self.obj)
self.portal.restrictedTraverse('fix_base_classes')()
self.assertTrue(IEvent.providedBy(self.obj))
示例5: test_upgrade_step_1
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def test_upgrade_step_1(self):
_dummy_1 = mkDummyInContext(MockATEvent_1, oid='dummy_1',
context=self.portal,
schema=ATContentTypeSchema)
_dummy_1.title = 'Foo'
_dummy_1.reindexObject()
event = self.portal['dummy_1']
self.assertTrue(not IEvent.providedBy(event))
del event
upgrade_step_1(self.portal)
event = self.portal['dummy_1']
self.assertTrue(IEvent.providedBy(event))
self.assertEqual('', event.recurrence)
self.assertEqual('Foo', event.Title())
示例6: _allDay
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def _allDay(self):
if HAS_PAE:
if IEvent.providedBy(self.context):
acc = IEventAccessor(self.context)
return acc.whole_day or False
if self._all_day is not None:
return bool(self._all_day)
return False
示例7: test_factory
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def test_factory(self):
fti = queryUtility(
IDexterityFTI,
name='Event'
)
factory = fti.factory
new_object = createObject(factory)
self.assertTrue(IEvent.providedBy(new_object))
示例8: set_allDay
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def set_allDay(self, v):
v = bool(v)
if HAS_PAE:
if IEvent.providedBy(self.context):
acc = IEventAccessor(self.context)
acc.whole_day = v
return
self._all_day = v
示例9: data_postprocessing
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def data_postprocessing(obj, event):
"""When setting the startDate and endDate, the value of the timezone field
isn't known, so we have to convert those timezone-naive dates into
timezone-aware ones afterwards.
For whole day events, set start time to 0:00:00 and end time toZone
23:59:59.
"""
if not IEvent.providedBy(obj):
# don't run me, if i'm not installed
return
timezone = obj.getField('timezone').get(obj)
start_field = obj.getField('startDate')
end_field = obj.getField('endDate')
# The previous_timezone is set, when the timezone has changed to another
# value. In this case we need to convert the UTC dt values to the
# previous_timezone, so that we get the datetime values, as the user
# entered them. However, this value might be always set, even when creating
# an event, since ObjectModifiedEvent is called several times when editing.
prev_tz = getattr(obj, 'previous_timezone', None)
if prev_tz: delattr(obj, 'previous_timezone')
def _fix_zone(dt, tz):
if not dt.timezoneNaive():
# The object is edited and the value alreadty stored in UTC on the
# object. In this case we want the value converted to the given
# timezone, in which the user entered the data.
dt = dt.toZone(tz)
return dt
start = _fix_zone(start_field.get(obj), prev_tz and prev_tz or timezone)
end = _fix_zone(end_field.get(obj), prev_tz and prev_tz or timezone)
def make_DT(value, timezone):
return DateTime(
value.year(),
value.month(),
value.day(),
value.hour(),
value.minute(),
value.second(),
timezone)
start = make_DT(start, timezone)
end = make_DT(end, timezone)
if obj.getWholeDay():
start = DateTime('%s 0:00:00 %s' % (start.Date(), timezone))
end = DateTime('%s 23:59:59 %s' % (end.Date(), timezone))
start_field.set(obj, start.toZone('UTC'))
end_field.set(obj, end.toZone('UTC'))
obj.reindexObject()
示例10: test_recurrence_occurrences
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
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]))
示例11: test_implementsInterfaces
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def test_implementsInterfaces(self):
"""Test if an ATEvent object implements all relevant interfaces.
"""
self.assertTrue(IEvent.providedBy(self.obj))
self.assertTrue(IEventRecurrence.providedBy(self.obj))
self.assertTrue(IATEvent.providedBy(self.obj))
self.assertTrue(IATEventRecurrence.providedBy(self.obj))
self.assertTrue(IATEvent_ATCT.providedBy(self.obj))
self.assertTrue(verifyObject(IATEvent_ATCT, self.obj))
示例12: _get_event_url
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def _get_event_url(ticket):
"""Return the URL to an event or event occurrence for a ticket or ticket
occurrence.
"""
url = ticket.absolute_url()
if ITicketOccurrence.providedBy(ticket):
# assumption1: ticketoccurrence id = occurrence id
# assumption2: ticketoccurrence parent = ticket
event = aq_parent(aq_parent(ticket))
if IEvent.providedBy(event):
url = "{}/{}".format(event.absolute_url(), ticket.id)
elif ITicket.providedBy(ticket):
event = aq_parent(ticket)
if IEvent.providedBy(event):
url = event.absolute_url()
return url
示例13: test_recurrence_occurrences_with_range_start_1
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
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]))
示例14: expand_events
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
def expand_events(events, ret_mode,
start=None, end=None,
sort=None, sort_reverse=None):
"""Expand to the recurrence occurrences of a given set of events.
:param events: IEvent based objects or IEventAccessor object wrapper.
:param ret_mode: Return type of search results. These options are
available:
* 2 (objects): Return results as IEvent and/or
IOccurrence objects.
* 3 (accessors): Return results as IEventAccessor
wrapper objects.
Option "1" (brains) is not supported.
:type ret_mode: integer [2|3]
:param start: Date, from which on events should be expanded.
:type start: Python datetime.
:param end: Date, until which events should be expanded.
:type end: Python datetime
:param sort: Object or IEventAccessor Attribute to sort on.
:type sort: string
:param sort_reverse: Change the order of the sorting.
:type sort_reverse: boolean
"""
assert(ret_mode is not RET_MODE_BRAINS)
exp_result = []
for it in events:
obj = it.getObject() if getattr(it, 'getObject', False) else it
if IEventRecurrence.providedBy(obj):
occurrences = [_obj_or_acc(occ, ret_mode) for occ in
IRecurrenceSupport(obj).occurrences(start, end)]
elif IEvent.providedBy(obj):
occurrences = [_obj_or_acc(obj, ret_mode)]
else:
# No IEvent based object. Could come from a collection.
continue
exp_result += occurrences
if sort:
exp_result.sort(key=lambda x: _get_compare_attr(x, sort))
if sort_reverse:
exp_result.reverse()
return exp_result
示例15: test_recurrence_occurrences_with_range_start_and_end
# 需要导入模块: from plone.event.interfaces import IEvent [as 别名]
# 或者: from plone.event.interfaces.IEvent import providedBy [as 别名]
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]))