class InterfaceData(object): """returns all properties data """ implements(IDataCollector) logger = getLogger() security = ClassSecurityInformation() def __init__(self, object): self.object = object self.adapted = IMarkerInterfaces(self.object) security.declarePrivate('getData') def getData(self): """returns all important data""" return self.getInterfaceData() security.declarePrivate('getInterfaceData') def getInterfaceData(self): """ Returns a list of directlyProvided interfaces. Example Return: [ 'foo.bar.IDemoInterface', .... ] @return: list @rtype: list """ return self.adapted.getDirectlyProvidedNames() security.declarePrivate('setData') def setData(self, interfacedata, metadata): """ Sets a list of properties on a object. Warning: all currently set properties which are not in the properties-list wille be removed! @param object: Plone-Object to set the properties on @type object: Plone-Object @param properties: list of propertes. See ftw.publisher.sender.extractor for format details. @param type: list @return: None """ self.logger.info('Updating interface data (UID %s)' % (self.object.UID()) ) current_ifaces = set(self.adapted.getDirectlyProvidedNames()) desired_ifaces = set(interfacedata) for iface_dotted in current_ifaces - desired_ifaces: iface = resolve(iface_dotted) noLongerProvides(self.object, iface) for iface_dotted in desired_ifaces - current_ifaces: iface = resolve(iface_dotted) alsoProvides(self.object, iface)
def enablePDF(context): if not IUniversalPublicationExtender.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[IUniversalPublicationExtender]) return True else: return False
def __call__(self, context): self.context = context adapted = IMarkerInterfaces(context) terms = [ SimpleTerm(x, title=x) for x in adapted.getDirectlyProvidedNames()] return SimpleVocabulary(terms)
def enableCounties(context): if not IExtensionCountiesExtender.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[IExtensionCountiesExtender]) return True else: return False
def enableVideoPlaylist(context): if not IVideoPlaylist.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[IVideoPlaylist]) return True else: return False
def remove_marker_interfaces(object, interfaces): ''' Remove given marker interfaces from a given object. ''' from Products.Five.utilities.interfaces import IMarkerInterfaces adapted_to_marker = IMarkerInterfaces(object) remove = adapted_to_marker.dottedToInterfaces(interfaces) adapted_to_marker.update(remove=remove) return True
def add_marker_interfaces(object, interfaces): ''' Add given marker interfaces to a given object. ''' from Products.Five.utilities.interfaces import IMarkerInterfaces adapted_to_marker = IMarkerInterfaces(object) add = adapted_to_marker.dottedToInterfaces(interfaces) adapted_to_marker.update(add=add) return True
def _extractMarkers(self): fragment = self._doc.createDocumentFragment() adapted = IMarkerInterfaces(self.context) for marker_id in adapted.getDirectlyProvidedNames(): node = self._doc.createElement('marker') node.setAttribute('name', marker_id) fragment.appendChild(node) return fragment
def _initMarkers(self, node): markers = [] adapted = IMarkerInterfaces(self.context) for child in node.childNodes: if child.nodeName != 'marker': continue markers.append(str(child.getAttribute('name'))) adapted.update(adapted.dottedToInterfaces(markers))
def object_provides(self): """ Context object_provides """ if not self.adapted: self.adapted = IMarkerInterfaces(self.context) ifaces = self.adapted.getDirectlyProvidedNames() ifaces.extend(self.adapted.getInterfaceNames()) return ifaces
def enableTileFolder(context): context.setLayout('folder_summary_view') if not ITileFolder.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[ITileFolder]) return True else: return False
def __call__(self, deactivate=0): context = aq_inner(self.context) marker_interfaces = IMarkerInterfaces(context) if not deactivate: marker_interfaces.update(add=[IVideoFolder], remove=[]) message = _(u'Video Folder activated') else: marker_interfaces.update(add=[], remove=[IVideoFolder]) message = _(u'Video Folder deactivated') context.plone_utils.addPortalMessage(message) return self.request.response.redirect(context.absolute_url())
def enablePublication(context): publicationInterface = IUniversalPublicationExtender if context.portal_type in ['File']: publicationInterface = IFilePublicationExtender if not publicationInterface.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[publicationInterface]) return True else: return False
def add_interface(ob, *args, **kw): """ Changes the object's workflow state """ err = list() interface_to_add = kw['interface_to_add'] if not interface_to_add: err.append('Please select an interface to add.') if not err: if type(interface_to_add) != list and type(interface_to_add) != tuple: interface_to_add = [interface_to_add] adapted = IMarkerInterfaces(ob) add = adapted.dottedToInterfaces(interface_to_add) adapted.update(add=add, remove=list()) return err
def remove_interface(ob, *args, **kw): """ Changes the object's workflow state """ err = list() interface_to_remove = kw['interface_to_remove'] if not interface_to_remove: err.append('Please select an interface to remove.') if not err: if type(interface_to_remove) != list and \ type(interface_to_remove) != tuple: interface_to_remove = [interface_to_remove] adapted = IMarkerInterfaces(ob) remove = adapted.dottedToInterfaces(interface_to_remove) adapted.update(add=list(), remove=remove) return err
class InterfacesView(ZMIView): """Marker interface view. """ def __init__(self, context, request): super(InterfacesView, self).__init__(context, request) self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url() def __call__(self): return self.index() def _getLinkToInterfaceDetailsView(self, interfaceName): return ( self.context_url + '/views-details.html?iface=%s&type=zope.publisher.interfaces.browser.IBrowserRequest' % interfaceName) def _getNameLinkDicts(self, interfaceNames): return [ dict(name=name, link=self._getLinkToInterfaceDetailsView(name)) for name in interfaceNames ] def getInterfaceNames(self): return self._getNameLinkDicts(self.adapted.getInterfaceNames())
class EditView(object): """Marker interface edit view. """ def __init__(self, context, request): self.context = context self.request = request self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url() def __call__(self, SAVE=None, add=(), remove=()): if SAVE: self.update(add, remove) url = '%s?manage_tabs_message=Changes+applied.' self.request.response.redirect(url % self.request.ACTUAL_URL) return '' return self.index() def _getNameLinkDicts(self, interfaceNames): return [dict(name=name) for name in interfaceNames] def getAvailableInterfaceNames(self): return self._getNameLinkDicts( self.adapted.getAvailableInterfaceNames()) def getDirectlyProvidedNames(self): return self._getNameLinkDicts(self.adapted.getDirectlyProvidedNames()) def getInterfaceNames(self): return self._getNameLinkDicts(self.adapted.getInterfaceNames()) def update(self, add, remove): # this could return errors add = self.adapted.dottedToInterfaces(add) remove = self.adapted.dottedToInterfaces(remove) self.adapted.update(add=add, remove=remove)
def del_marker(obj, interfaces): '''Remove marker-interfaces from an object :param object obj: The object to remove the marker-interface from. :param list interfaces: A list of interfaces (as strings) to delete from the object. :returns: ``None`` Group-types are usually implemented as marker interfaces on a group-folder. This metehod removes (deltes) the marker interfaces from the object. For example:: iFaces = ['gs.group.type.closed.interfaces.IGSClosedGroup'] self.del_marker(self.group, iFaces) ''' adaptedToMarker = IMarkerInterfaces(obj) remove = adaptedToMarker.dottedToInterfaces(interfaces) adaptedToMarker.update(remove=remove)
def add_marker(obj, interfaces): '''Add marker-interfaces to an object :param object obj: The object to add the marker-interface to. :param list interfaces: A list of interfaces (as strings) to add to the object. :returns: ``None`` Group-types are usually implemented as marker interfaces on a group-folder. This metehod adds the marker interfaces to the object. For example:: iFaces = ['gs.group.type.closed.interfaces.IGSClosedGroup'] self.add_marker(self.group, iFaces) It should be assumed that the previous group-settings have been removed by an earlier call to :meth:`gs.group.type.set.UnsetABC.unset`. ''' adaptedToMarker = IMarkerInterfaces(obj) add = adaptedToMarker.dottedToInterfaces(interfaces) adaptedToMarker.update(add=add)
def enableCourse(context): # Set the IExtensionCourseExtender interface on the course collection landing page. if context.portal_type in ['Folder']: default_id = context.getDefaultPage() if default_id in context.objectIds(): context = context[default_id] if context.portal_type not in ['Topic']: return False else: return False if not IExtensionCourseExtender.providedBy(context): adapted = IMarkerInterfaces(context) adapted.update(add=[IExtensionCourseExtender]) return True else: return False
def afterSetUp(self): self.loginAsPortalOwner() self.portal.invokeFactory('Document', 'other-page') other_page = self.portal['other-page'] self.portal.invokeFactory('Document', 'test') self.page = self.portal.test self.page.setTitle('テスト Document') self.page.setSubject(('test', 'document',)) self.page.setExcludeFromNav(True) self.page.setRelatedItems([other_page]) marker_interfaces = IMarkerInterfaces(self.page) marker_interfaces.update( add=marker_interfaces.dottedToInterfaces( (TEST_MARKER_INTERFACE,) )) self.exporter = self.portal.getSiteManager().queryUtility( contentexporter.IContentExporter)
def notifyMemberAreaCreated(self, **args): pm = getToolByName(self, 'portal_membership') member = pm.getAuthenticatedMember() hf = pm.getHomeFolder() if not IHomeFolder.providedBy(hf): adapted = IMarkerInterfaces(hf) interface_to_add = [IHomeFolder.__identifier__] add = adapted.dottedToInterfaces(interface_to_add) adapted.update(add=add, remove=list()) if not member.getProperty('is_expert_author', False): if hf is not None: if not hf.hasProperty('layout'): hf._setProperty('layout', '@@workingarea', 'string') else: hf._updateProperty('layout', '@@workingarea') member.setMemberProperties({'wysiwyg_editor': 'CKeditor'}) if hf is not None: hf.manage_permission( permission_to_manage="Change local roles", roles=['Manager'], acquire=0)
class EditView: """Marker interface edit view. """ def __init__(self, context, request): self.context = context self.request = request self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url() def __call__(self, SAVE=None, add=(), remove=()): if SAVE: self.update(add, remove) self.request.response.redirect(self.request.ACTUAL_URL) return '' return self.index() def _getLinkToInterfaceDetailsView(self, interfaceName): return ( self.context_url + '/views-details.html?iface=%s&type=zope.publisher.interfaces.browser.IBrowserRequest' % interfaceName) def _getNameLinkDicts(self, interfaceNames): return [ dict(name=name, link=self._getLinkToInterfaceDetailsView(name)) for name in interfaceNames ] def getAvailableInterfaceNames(self): return self._getNameLinkDicts( self.adapted.getAvailableInterfaceNames()) def getDirectlyProvidedNames(self): return self._getNameLinkDicts(self.adapted.getDirectlyProvidedNames()) def getInterfaceNames(self): return self._getNameLinkDicts(self.adapted.getInterfaceNames()) def update(self, add, remove): # this could return errors add = self.adapted.dottedToInterfaces(add) remove = self.adapted.dottedToInterfaces(remove) self.adapted.update(add=add, remove=remove)
def __call__(self, deact=0): context = aq_inner(self.context) adapted = IMarkerInterfaces(context) if not deact: adapted.update(add=[IBlog], remove=[]) self.prepare_blog() message = _('Blog enabled correctly') notify(BlogEnabled(context)) IStatusMessage(self.request).add(message) else: adapted.update(add=[], remove=[IBlog]) notify(BlogDisabled(context)) message = _('Blog disabled correctly') IStatusMessage(self.request).add(message) return self.request.response.redirect(context.absolute_url())
class EditView: """Marker interface edit view. """ def __init__(self, context, request): self.context = context self.request = request self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url() def __call__(self, SAVE=None, add=(), remove=()): if SAVE: self.update(add, remove) self.request.response.redirect(self.request.ACTUAL_URL) return '' return self.index() def _getLinkToInterfaceDetailsView(self, interfaceName): return (self.context_url + '/views-details.html?iface=%s&type=zope.publisher.interfaces.browser.IBrowserRequest' % interfaceName) def _getNameLinkDicts(self, interfaceNames): return [dict(name=name, link=self._getLinkToInterfaceDetailsView(name)) for name in interfaceNames] def getAvailableInterfaceNames(self): return self._getNameLinkDicts( self.adapted.getAvailableInterfaceNames()) def getDirectlyProvidedNames(self): return self._getNameLinkDicts(self.adapted.getDirectlyProvidedNames()) def getInterfaceNames(self): return self._getNameLinkDicts(self.adapted.getInterfaceNames()) def update(self, add, remove): # this could return errors add = self.adapted.dottedToInterfaces(add) remove = self.adapted.dottedToInterfaces(remove) self.adapted.update(add=add, remove=remove)
def render(self): cat = getToolByName(self.context, 'portal_catalog') query = dict(portal_type='Folder', Language='en') res = cat(query) log.info('Total no. of folders found: {0}'.format(len(res))) for r in res: if r.getPath().split('/')[2] != 'en': log.warning( "Found a folder with lang EN not under /en: {0}".format( r.getPath())) continue obj = r.getObject() if not ITranslatable.providedBy(obj): log.warning( 'Found a folder that is not translatable, WTF: {0}'.format( r.getPath())) continue ordering = obj.getOrdering() order = ordering.idsInOrder() tm = ITranslationManager(obj) log.info('Handling folder {0}.'.format('/'.join( obj.getPhysicalPath()))) for lang, trans in tm.get_translations().items(): if lang == 'en': continue # Copy "Exclude from navigation", section images and related sites trans.exclude_from_nav = obj.exclude_from_nav IRelatedSites(trans).related_sites_links = IRelatedSites( obj).related_sites_links ISectionImage(trans).section_image = ISectionImage( obj).section_image # Copy over marker interfaces ifaces_to_add = IMarkerInterfaces( obj).getDirectlyProvidedNames() if len(ifaces_to_add): t_ifaces = IMarkerInterfaces(trans) add = t_ifaces.dottedToInterfaces(ifaces_to_add) t_ifaces.update(add=add, remove=list()) # handle the default page settings prop = 'default_page' propval = aq_base(obj).getProperty(prop, None) if propval: # get translation of default-page, if it exists (since the id might be different!) default_page = getattr(obj, propval, None) t_default_page = default_page and ITranslationManager( default_page).get_translation(lang) if not t_default_page: continue # check if marker interfaces need to be copied dp_ifaces_to_add = IMarkerInterfaces( default_page).getDirectlyProvidedNames() if len(dp_ifaces_to_add): t_dp_ifaces = IMarkerInterfaces(t_default_page) add = t_dp_ifaces.dottedToInterfaces(dp_ifaces_to_add) t_dp_ifaces.update(add=add, remove=list()) if aq_base(trans).hasProperty(prop): trans._delProperty(prop) trans._setProperty(id=prop, value=t_default_page.id, type="string") # now set the correct order t_ordering = trans.getOrdering() t_order = t_ordering.idsInOrder() for i in range(len(order)): if order[i] in t_order: t_ordering.moveObjectToPosition(order[i], i, suppress_events=True) if t_order != t_ordering.idsInOrder(): trans.reindexObject() log.info('Now, fix FOP languages') results = cat(portal_type="osha.hwccontent.focalpoint", Language='all') fopcnt = 0 for res in results: fop = res.getObject() if fop.Language() != '': fop.setLanguage('') fop.reindexObject() fopcnt += 1 log.info('Reset the language on {0} FOPs'.format(fopcnt)) return "ok"
def __init__(self, object): self.object = object self.adapted = IMarkerInterfaces(self.object)
def availableInterfaces(self): items = [(x.lower(), x) for x \ in IMarkerInterfaces(self.context).getAvailableInterfaceNames()] items.sort() return [x[1] for x in items]
def __init__(self, context, request): super(InterfacesView, self).__init__(context, request) self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url()
def __init__(self, context, request): self.context = context self.request = request self.adapted = IMarkerInterfaces(context) self.context_url = self.context.absolute_url()
def render(self): cat = getToolByName(self.context, 'portal_catalog') query = dict(portal_type='Folder', Language='en') res = cat(query) log.info('Total no. of folders found: {0}'.format(len(res))) for r in res: if r.getPath().split('/')[2] != 'en': log.warning("Found a folder with lang EN not under /en: {0}".format( r.getPath())) continue obj = r.getObject() if not ITranslatable.providedBy(obj): log.warning('Found a folder that is not translatable, WTF: {0}'.format( r.getPath())) continue ordering = obj.getOrdering() order = ordering.idsInOrder() tm = ITranslationManager(obj) log.info('Handling folder {0}.'.format('/'.join(obj.getPhysicalPath()))) for lang, trans in tm.get_translations().items(): if lang == 'en': continue # Copy "Exclude from navigation", section images and related sites trans.exclude_from_nav = obj.exclude_from_nav IRelatedSites(trans).related_sites_links = IRelatedSites(obj).related_sites_links ISectionImage(trans).section_image = ISectionImage(obj).section_image # Copy over marker interfaces ifaces_to_add = IMarkerInterfaces(obj).getDirectlyProvidedNames() if len(ifaces_to_add): t_ifaces = IMarkerInterfaces(trans) add = t_ifaces.dottedToInterfaces(ifaces_to_add) t_ifaces.update(add=add, remove=list()) # handle the default page settings prop = 'default_page' propval = aq_base(obj).getProperty(prop, None) if propval: # get translation of default-page, if it exists (since the id might be different!) default_page = getattr(obj, propval, None) t_default_page = default_page and ITranslationManager(default_page).get_translation(lang) if not t_default_page: continue # check if marker interfaces need to be copied dp_ifaces_to_add = IMarkerInterfaces(default_page).getDirectlyProvidedNames() if len(dp_ifaces_to_add): t_dp_ifaces = IMarkerInterfaces(t_default_page) add = t_dp_ifaces.dottedToInterfaces(dp_ifaces_to_add) t_dp_ifaces.update(add=add, remove=list()) if aq_base(trans).hasProperty(prop): trans._delProperty(prop) trans._setProperty(id=prop, value=t_default_page.id, type="string") # now set the correct order t_ordering = trans.getOrdering() t_order = t_ordering.idsInOrder() for i in range(len(order)): if order[i] in t_order: t_ordering.moveObjectToPosition( order[i], i, suppress_events=True) if t_order != t_ordering.idsInOrder(): trans.reindexObject() log.info('Now, fix FOP languages') results = cat(portal_type="osha.hwccontent.focalpoint", Language='all') fopcnt = 0 for res in results: fop = res.getObject() if fop.Language() != '': fop.setLanguage('') fop.reindexObject() fopcnt += 1 log.info('Reset the language on {0} FOPs'.format(fopcnt)) return "ok"
class ContentTypeLookUp(object): """ Lookup for context in portal_relations content-types """ implements(IContentTypeLookUp) def __init__(self, context): self.context = context self.adapted = None self._ctypes = None self._types_and_interfaces = None @property def ctypes(self): """ Types """ if self._ctypes: return self._ctypes tool = queryAdapter(self.context, IToolAccessor) if not tool: return [] self._ctypes = [doc for doc in tool.types(proxy=False)] return self._ctypes @property def portal_type(self): """ Context portal_type """ return getattr(self.context, 'portal_type', '') @property def object_provides(self): """ Context object_provides """ if not self.adapted: self.adapted = IMarkerInterfaces(self.context) ifaces = self.adapted.getDirectlyProvidedNames() ifaces.extend(self.adapted.getInterfaceNames()) return ifaces @property def types_and_interfaces(self): """ Types and interfaces logic from every field """ if self._types_and_interfaces: return self._types_and_interfaces self._types_and_interfaces = [] for doc in self.ctypes: ct_type = doc.getField('ct_type').getAccessor(doc)() ct_interface = doc.getField('ct_interface').getAccessor(doc)() self._types_and_interfaces.append((ct_type, ct_interface, doc)) return self._types_and_interfaces @property def tuple_types(self): """ Types """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if not ct_type: continue if not ct_interface: continue res[(ct_interface, ct_type)] = doc return res @property def portal_types_only(self): """ Only portal_types """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if ct_interface: continue if not ct_type: continue res[ct_type] = doc return res @property def interfaces_only(self): """ Only interfaces """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if ct_type: continue if not ct_interface: continue res[ct_interface] = doc return res def __call__(self, inverse_interface_check=False): """ Return ContentType object from portal_relation or None """ object_provides = self.object_provides # Search for full mapping tuple_types = self.tuple_types ptype = self.portal_type if tuple_types: for iface in object_provides: if (iface, ptype) in tuple_types: return tuple_types[(iface, ptype)] # Fallback to portal_type only portal_types = self.portal_types_only if ptype in self.portal_types_only: return portal_types[ptype] # Fallback to interfaces only interfaces = self.interfaces_only if interfaces: if inverse_interface_check: object_provides.reverse() for iface in object_provides: if iface in interfaces: return interfaces[iface] return None
class ContentTypeLookUp(object): """ Lookup for context in portal_relations content-types """ implements(IContentTypeLookUp) def __init__(self, context): self.context = context self.adapted = None self._ctypes = None self._types_and_interfaces = None @property def ctypes(self): """ Types """ if self._ctypes: return self._ctypes tool = queryAdapter(self.context, IToolAccessor) if not tool: return [] self._ctypes = [doc for doc in tool.types(proxy=False)] return self._ctypes @property def portal_type(self): """ Context portal_type """ request = getRequest() if request: if '++add++' in request.URL: types_tool = getToolByName(getSite(), 'portal_types') add_view_url = request.steps[-1].split('++add++')[-1] portal_type = types_tool[add_view_url].factory return portal_type return getattr(self.context, 'portal_type', '') @property def object_provides(self): """ Context object_provides """ if not self.adapted: self.adapted = IMarkerInterfaces(self.context) ifaces = self.adapted.getDirectlyProvidedNames() ifaces.extend(self.adapted.getInterfaceNames()) return ifaces @property def types_and_interfaces(self): """ Types and interfaces logic from every field """ if self._types_and_interfaces: return self._types_and_interfaces self._types_and_interfaces = [] for doc in self.ctypes: ct_type = doc.getField('ct_type').getAccessor(doc)() ct_interface = doc.getField('ct_interface').getAccessor(doc)() self._types_and_interfaces.append((ct_type, ct_interface, doc)) return self._types_and_interfaces @property def tuple_types(self): """ Types """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if not ct_type: continue if not ct_interface: continue res[(ct_interface, ct_type)] = doc return res @property def portal_types_only(self): """ Only portal_types """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if ct_interface: continue if not ct_type: continue res[ct_type] = doc return res @property def interfaces_only(self): """ Only interfaces """ res = {} for ct_type, ct_interface, doc in self.types_and_interfaces: if ct_type: continue if not ct_interface: continue res[ct_interface] = doc return res def __call__(self, **kwargs): """ Return ContentType object from portal_relation or None """ object_provides = self.object_provides # Search for full mapping tuple_types = self.tuple_types ptype = self.portal_type if tuple_types: for iface in object_provides: if (iface, ptype) in tuple_types: return tuple_types[(iface, ptype)] # Fallback to portal_type only portal_types = self.portal_types_only if ptype in self.portal_types_only: return portal_types[ptype] # Fallback to interfaces only interfaces = self.interfaces_only if interfaces: for iface in object_provides: if iface in interfaces: return interfaces[iface] return None