当前位置: 首页>>代码示例>>Python>>正文


Python IAnnotations.providedBy方法代码示例

本文整理汇总了Python中zope.annotation.interfaces.IAnnotations.providedBy方法的典型用法代码示例。如果您正苦于以下问题:Python IAnnotations.providedBy方法的具体用法?Python IAnnotations.providedBy怎么用?Python IAnnotations.providedBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.annotation.interfaces.IAnnotations的用法示例。


在下文中一共展示了IAnnotations.providedBy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: localPortletAssignmentMappingAdapter

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
def localPortletAssignmentMappingAdapter(context, manager):
    """When adapting (context, manager), get an IPortletAssignmentMapping
    by finding one in the object's annotations. The container will be created
    if necessary.
    """
    if IAnnotations.providedBy(context):
        annotations = context
    else:
        annotations = queryAdapter(context, IAnnotations)
    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
    if local is None:
        local = annotations[CONTEXT_ASSIGNMENT_KEY] = OOBTree()
    portlets = local.get(manager.__name__, None)
    if portlets is None or not IMultiSearchPortletAssignmentMapping.providedBy(
            portlets):
        if portlets is not None:
            old_items = portlets.items()
        else:
            old_items = []
        portlets = local[manager.__name__] = MultiSearchPortletAssignmentMapping(
            manager=manager.__name__,
            category=CONTEXT_CATEGORY)
        # Inline migration.  Might be good in an upgrade step.
        for key, value in old_items:
            portlets[key] = value

    return portlets
开发者ID:zestsoftware,项目名称:collective.multisearch,代码行数:29,代码来源:manager.py

示例2: __init__

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
    def __init__(self, tile):
        self.tile = tile
        self.tileType = queryUtility(ITileType, name=tile.__name__)

        self.context = getMultiAdapter(
            (tile.context, tile.request, tile), ITileDataContext)
        self.storage = getMultiAdapter(
            (self.context, tile.request, tile), ITileDataStorage)

        if IAnnotations.providedBy(self.storage):
            self.key = '.'.join([ANNOTATIONS_KEY_PREFIX, str(tile.id)])
        else:
            self.key = str(tile.id)
开发者ID:plone,项目名称:plone.tiles,代码行数:15,代码来源:data.py

示例3: localPortletAssignmentMappingAdapter

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
def localPortletAssignmentMappingAdapter(context, manager):
    """When adapting (context, manager), get an IPortletAssignmentMapping
    by finding one in the object's annotations. The container will be created
    if necessary.
    """
    if IAnnotations.providedBy(context):
        annotations = context
    else:
        annotations = queryAdapter(context, IAnnotations)
    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
    if local is None:
        local = annotations[CONTEXT_ASSIGNMENT_KEY] = OOBTree()
    portlets = local.get(manager.__name__, None)
    if portlets is None:
        portlets = local[manager.__name__] = PortletAssignmentMapping(manager=manager.__name__,
                                                                      category=CONTEXT_CATEGORY)
    return portlets
开发者ID:plone,项目名称:plone.portlets,代码行数:19,代码来源:assignable.py

示例4: _getBlacklist

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
 def _getBlacklist(self, create=False):
     if IAnnotations.providedBy(self.context):
         annotations = self.context
     else:
         annotations = queryAdapter(self.context, IAnnotations)
     local = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY, None)
     if local is None:
         if create:
             local = annotations[CONTEXT_BLACKLIST_STATUS_KEY] = PersistentDict()
         else:
             return None
     blacklist = local.get(self.manager.__name__, None)
     if blacklist is None:
         if create:
             blacklist = local[self.manager.__name__] = PersistentDict()
         else:
             return None
     return blacklist
开发者ID:plone,项目名称:plone.portlets,代码行数:20,代码来源:assignable.py

示例5: getPortlets

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
    def getPortlets(self):
        """Work out which portlets to display, returning a list of dicts
        describing assignments to render.
        """

        if IPortletContext.providedBy(self.context):
            pcontext = self.context
        else:
            pcontext = queryAdapter(self.context, IPortletContext)

        if pcontext is None:
            return []

        # Holds a list of (category, key, assignment).
        categories = []

        # Keeps track of the blacklisting status for global categores
        # (user, group, content type). The status is either True (blocked)
        # or False (not blocked).
        blacklisted = {}

        # This is the name of the manager (column) we're rendering
        manager = self.storage.__name__

        # 1. Fetch blacklisting status for each global category

        # First, find out which categories we will need to determine
        # blacklist status for

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        # Then walk the content hierarchy to find out what blacklist status
        # was assigned. Note that the blacklist is tri-state; if it's None it
        # means no assertion has been made (i.e. the category has neither been
        # whitelisted or blacklisted by this object or any parent). The first
        # item to give either a blacklisted (True) or whitelisted (False)
        # value for a given item will set the appropriate value. Parents of
        # this item that also set a black- or white-list value will then be
        # ignored.

        # Whilst walking the hierarchy, we also collect parent portlets,
        # until we hit the first block.

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False

        while current is not None and currentpc is not None:
            if ILocalPortletAssignable.providedBy(current):
                assignable = current
            else:
                assignable = queryAdapter(current, ILocalPortletAssignable)

            if assignable is not None:
                if IAnnotations.providedBy(assignable):
                    annotations = assignable
                else:
                    annotations = queryAdapter(assignable, IAnnotations)

                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])

                lpam = getMultiAdapter((assignable, self.storage), ILocalPortletAssignmentManager)
                if lpam.getBlacklistStatus(CONTEXT_CATEGORY):
                    parentsBlocked = True
                for cat, cat_status in blacklisted.items():
                    local_status = lpam.getBlacklistStatus(cat)
                    if local_status is not None:
                        blacklistFetched.add(cat)
                        if cat_status is None:
                            blacklisted[cat] = local_status

            # We can abort if parents are blocked and we've fetched all
            # blacklist statuses

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break

            # Check the parent - if there is no parent, we will stop
            current = currentpc.getParent()
            if current is not None:
                if IPortletContext.providedBy(current):
                    currentpc = current
                else:
                    currentpc = queryAdapter(current, IPortletContext)

        # Get all global mappings for non-blacklisted categories

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((category, key, a, ))
#.........这里部分代码省略.........
开发者ID:plone,项目名称:plone.portlets,代码行数:103,代码来源:retriever.py

示例6: getPortlets

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import providedBy [as 别名]
    def getPortlets(self):

        portal_state = getMultiAdapter((self.context, self.context.REQUEST), name=u'plone_portal_state')
        portal = portal_state.portal()
        pcontext = IPortletContext(self.context, None)
        if pcontext is None:
            return []

        categories = [] 

        blacklisted = {}

        manager = self.storage.__name__

        for category, key in pcontext.globalPortletCategories(False):
            blacklisted[category] = None

        current = self.context
        currentpc = pcontext
        blacklistFetched = set()
        parentsBlocked = False
        
        while current is not None and currentpc is not None:
            if ILocalPortletAssignable.providedBy(current):
                assignable = current
            else:
                assignable = queryAdapter(current, ILocalPortletAssignable)

            if assignable is not None:
                if IAnnotations.providedBy(assignable):
                    annotations = assignable
                else:
                    annotations = queryAdapter(assignable, IAnnotations)
                
                if not parentsBlocked:
                    local = annotations.get(CONTEXT_ASSIGNMENT_KEY, None)
                    if local is not None:
                        localManager = local.get(manager, None)
                        if localManager is not None:
                            categories.extend([(CONTEXT_CATEGORY, currentpc.uid, a) for a in localManager.values()])

                blacklistStatus = annotations.get(CONTEXT_BLACKLIST_STATUS_KEY, {}).get(manager, None)
                if blacklistStatus is not None:
                    for cat, status in blacklistStatus.items():
                        if cat == CONTEXT_CATEGORY:
                            if not parentsBlocked and status == True:
                                parentsBlocked = True
                        else: # global portlet categories
                            if blacklisted.get(cat, False) is None:
                                blacklisted[cat] = status
                            if status is not None:
                                blacklistFetched.add(cat)

            if parentsBlocked and len(blacklistFetched) == len(blacklisted):
                break
            current = currentpc.getParent()
            if current is not None:
                if IPortletContext.providedBy(current):
                    currentpc = current
                else:
                    currentpc = queryAdapter(current, IPortletContext)

        for category, key in pcontext.globalPortletCategories(False):
            if not blacklisted[category]:
                mapping = self.storage.get(category, None)
                if mapping is not None:
                    for a in mapping.get(key, {}).values():
                        categories.append((category, key, a,))

        managerUtility = getUtility(IPortletManager, manager, portal)

        here_url = '/'.join(aq_inner(self.context).getPhysicalPath())

        assignments = []
        for category, key, assignment in categories:
            assigned = ISolgemaPortletAssignment(assignment)
            portletHash = hashPortletInfo(dict(manager=manager, category=category, key=key, name =assignment.__name__,))
            if not getattr(assigned, 'stopUrls', False) or len([stopUrl for stopUrl in getattr(assigned, 'stopUrls', []) if stopUrl in here_url])==0:
                assignments.append({'category'    : category,
                                    'key'         : key,
                                    'name'        : assignment.__name__,
                                    'assignment'  : assignment,
                                    'hash'        : hashPortletInfo(dict(manager=manager, category=category, key=key, name =assignment.__name__,)),
                                    'stopUrls'    : ISolgemaPortletAssignment(assignment).stopUrls,
                                    })
        
        if hasattr(managerUtility, 'listAllManagedPortlets'):
            hashlist = managerUtility.listAllManagedPortlets
            assignments.sort(lambda a,b:cmp(hashlist.count(a['hash'])>0 and hashlist.index(a['hash']) or 0, hashlist.count(b['hash'])>0 and hashlist.index(b['hash']) or 0))

        return assignments
开发者ID:afrepues,项目名称:Solgema.PortletsManager,代码行数:93,代码来源:retriever.py


注:本文中的zope.annotation.interfaces.IAnnotations.providedBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。