def __call__(self): plone_utils = getToolByName(self.context, 'plone_utils') if self.request.has_key('collective.interfaces.add'): add = self.request.get('add') if add: iface = getInterface(self.context, add) alsoProvides(self.context, iface) self.context.reindexObject(idxs=["object_provides"]) plone_utils.addPortalMessage( _("interface_added_msg", default='Interface ${name} added.', mapping={'name': add})) else: plone_utils.addPortalMessage(_('Please select an interface.')) elif self.request.has_key('collective.interfaces.remove'): ifaces = self.request.get('ifaces') if ifaces: for iface in ifaces: noLongerProvides(self.context, getInterface(self.context, iface)) self.context.reindexObject(idxs=["object_provides"]) plone_utils.addPortalMessage( _("interfaces_removed_msg", default='${count} interface(s) removed.', mapping={'count': len(ifaces)})) else: plone_utils.addPortalMessage(_('Please select an interface.')) return self._template()
def __call__(self): plone_utils = getToolByName(self.context, "plone_utils") if self.request.has_key("collective.interfaces.add"): add = self.request.get("add") if add: iface = getInterface(self.context, add) alsoProvides(self.context, iface) self.context.reindexObject(idxs=["object_provides"]) plone_utils.addPortalMessage( _("interface_added_msg", default="Interface ${name} added.", mapping={"name": add}) ) else: plone_utils.addPortalMessage(_("Please select an interface.")) elif self.request.has_key("collective.interfaces.remove"): ifaces = self.request.get("ifaces") if ifaces: for iface in ifaces: noLongerProvides(self.context, getInterface(self.context, iface)) self.context.reindexObject(idxs=["object_provides"]) plone_utils.addPortalMessage( _( "interfaces_removed_msg", default="${count} interface(s) removed.", mapping={"count": len(ifaces)}, ) ) else: plone_utils.addPortalMessage(_("Please select an interface.")) return self._template()
def _create_task_instance(self, creation_place, task_id): """ Helper method to use to implement 'create_task'. """ if task_id in creation_place.objectIds(): raise TaskAlreadyExists(task_id) task_portal_type = self.get_task_type() portal_types = api.portal.get_tool('portal_types') type_info = portal_types.getTypeInfo(task_portal_type) task = type_info._constructInstance( container=creation_place, id=task_id, title=self.Title(), schedule_config_UID=self.get_schedule_config().UID(), task_config_UID=self.UID(), ) marker_interfaces = [ getInterface('', i) for i in self.marker_interfaces or [] ] alsoProvides(task, *marker_interfaces) return task
def update_marker_interfaces(task_config, event): """ When the 'marker_interfaces' field is updated, update the interface provided on all the tasks of this task config as well. """ catalog = api.portal.get_tool('portal_catalog') vocname = ITaskConfig.get('marker_interfaces').value_type.vocabularyName interfaces_voc = getUtility(IVocabularyFactory, vocname)(task_config) marker_interfaces = dict([(i, getInterface('', i)) for i in interfaces_voc.by_value]) task_brains = catalog(object_provides=IAutomatedTask.__identifier__, task_config_UID=task_config.UID()) sample_task = task_brains and task_brains[0].getObject() or None # verify if the update is needed do_update = False for interface_name, marker_interface in marker_interfaces.iteritems(): is_provided = marker_interface.providedBy(sample_task) # new interface on the config but not present yet on the tasks => update if interface_name in (task_config.marker_interfaces or []) and not is_provided: do_update = True break # old interface on the tasks no longer present on the config => update elif interface_name not in (task_config.marker_interfaces or []) and is_provided: do_update = True break if do_update: for task_brain in task_brains: task = task_brain.getObject() for marker_interface_name, marker_interface in marker_interfaces.iteritems( ): if marker_interface_name in task_config.marker_interfaces: alsoProvides(task, marker_interface) else: noLongerProvides(task, marker_interface) task.reindexObject(idxs=['object_provides'])
def test_marker_interfaces_update(self): """ When updating the field eventType on an EventConfig, all the existing events should be updated as well to add or remove the marker interfaces in the new values. """ event_config = getattr(self.event_configs, 'rapport-du-college') event = event_config.getLinkedUrbanEvents()[0] inquiry_marker = 'Products.urban.interfaces.IInquiryEvent' inquiry_marker_interface = getInterface('', inquiry_marker) # for now the marker should not be provided on the event self.assertFalse(inquiry_marker_interface.providedBy(event)) # set Inquiry marker and trigger modified zope event event_config.eventType = (inquiry_marker,) notify(ObjectModifiedEvent(event_config)) # now the marker should be provided on the event self.assertTrue(inquiry_marker_interface.providedBy(event)) # remove all the markers event_config.eventType = () notify(ObjectModifiedEvent(event_config)) # the marker should not be provided on the event anymore self.assertFalse(inquiry_marker_interface.providedBy(event))
def _create_task_instance(self, creation_place, task_id): """ Helper method to use to implement 'create_task'. """ if task_id in creation_place.objectIds(): raise TaskAlreadyExists(task_id) task_portal_type = self.get_task_type() portal_types = api.portal.get_tool('portal_types') type_info = portal_types.getTypeInfo(task_portal_type) task = type_info._constructInstance( container=creation_place, id=task_id, title=self.Title(), schedule_config_UID=self.get_schedule_config().UID(), task_config_UID=self.UID(), ) marker_interfaces = [getInterface('', i) for i in self.marker_interfaces or []] alsoProvides(task, *marker_interfaces) return task
def dottedToInterfaces(self, seq): return [getInterface(self.context, dotted) for dotted in seq]
def wrapper(ob, interface): if isinstance(interface, str): interface = getInterface(ob, interface) return f(ob, interface)
def _callFUT(self, *args, **kw): from zope.component.interface import getInterface return getInterface(*args, **kw)