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


Python IAnnotations.keys方法代码示例

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


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

示例1: test_annotation_basic_standard_lifecycle

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
    def test_annotation_basic_standard_lifecycle(self):
        # life cycle for a standard item.
        annotations = IAnnotations(self.portal)
        dummy = IDummy(self.portal)
        self.assertIsNone(dummy.field1)
        self.assertIsNone(dummy.field2)

        annotations = IAnnotations(self.portal)
        self.assertNotIn("repodono.storage.tests.test_annotation.Dummy", annotations.keys())

        # assign some values
        dummy.field1 = u"Test"

        # Now the annotation will be in assigned.
        value = annotations["repodono.storage.tests.test_annotation.Dummy"]
        self.assertTrue(isinstance(value, PersistentMapping))
        self.assertEqual(value, {"field1": u"Test"})

        # assign more values.
        dummy.field2 = 1
        dummy.field3 = 1

        # only fields defined in the interface are persisted.
        self.assertEqual(value, {"field1": u"Test", "field2": 1})

        old = dummy.uninstall()
        self.assertNotIn("repodono.storage.tests.test_annotation.Dummy", annotations.keys())
        self.assertFalse(isinstance(old, PersistentMapping))
        self.assertEqual(old, {"field1": u"Test", "field2": 1})
开发者ID:repodono,项目名称:repodono.storage,代码行数:31,代码来源:test_annotation.py

示例2: __init__

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
 def __init__(self, context):
     self.context = context
     
     annotations = IAnnotations(context)
     if APPROVED_KEY not in annotations.keys():
         annotations[APPROVED_KEY] = PersistentList()        
     #投赞成票的用户id 队列
     self.approved = annotations[APPROVED_KEY]
     if DISAPPROVED_KEY not in annotations.keys():
         annotations[DISAPPROVED_KEY] = PersistentList()        
     #投反对票的用户id 队列        
     self.disapproved = annotations[DISAPPROVED_KEY]        
开发者ID:adam139,项目名称:emc.kb,代码行数:14,代码来源:vote.py

示例3: test_annotation_not_field_no_mapping

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
    def test_annotation_not_field_no_mapping(self):
        # Assignment of unrelated fields will not trigger addition of
        # mapping
        dummy = IDummy3(self.portal)
        dummy.not_schema = u"Some value"
        # Failed assignments will not trigger addition of mapping.
        annotations = IAnnotations(self.portal)
        self.assertNotIn("repodono.storage.tests.test_annotation.Dummy2", annotations.keys())

        # Likewise with a method defined in schema interface.
        dummy.foo = u"Some value"
        # Failed assignments will not trigger addition of mapping.
        annotations = IAnnotations(self.portal)
        self.assertNotIn("repodono.storage.tests.test_annotation.Dummy2", annotations.keys())
开发者ID:repodono,项目名称:repodono.storage,代码行数:16,代码来源:test_annotation.py

示例4: upgrade_to_v2

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
def upgrade_to_v2(context):
    """Updates profile
    """
    ppcas = 'plone.portlets.contextassignments'
    catalog = getToolByName(context, 'portal_catalog')
    count = 0
    for brain in catalog(portal_type=['BlogEntry', 'BlogCategory', 'Blog']):
        obj = brain.getObject()
        annotations = IAnnotations(obj)
        if ppcas in annotations.keys():
            if 'blog.portlets' in annotations[ppcas]:
                count += 1
                if len(annotations[ppcas]) == 1:
                    del annotations[ppcas]
                else:
                    del annotations[ppcas]['blog.portlets']

    logger.info("%s %s annotations removed" % (str(count), ppcas))
    loadMigrationProfile(context, 'profile-ftw.blog.upgrades:to_v2')

    # remove blog_settings actions
    portal_actions = getToolByName(context, 'portal_actions')

    category = portal_actions.get('object_buttons', None)
    action_id = 'blog_settings'
    if category and action_id in category:
        del category[action_id]
开发者ID:CMcStone,项目名称:ftw.blog,代码行数:29,代码来源:to0002.py

示例5: HistoryStorage

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
class HistoryStorage(object):

    key = 'disposition_history'

    def __init__(self, context):
        self.context = context
        self._annotations = IAnnotations(self.context)
        if self.key not in self._annotations.keys():
            self._annotations[self.key] = PersistentList()

    @property
    def _storage(self):
        return self._annotations[self.key]

    def add(self, transition, actor_id, dossiers):
        """Adds a new history entry to the storage.
        transition: string
        actor_id: user_id as string
        dossiers: a list of dossier representations.
        """

        dossier_list = PersistentList(
            [dossier.get_storage_representation() for dossier in dossiers])
        self._storage.append(
            PersistentDict({'transition': transition,
                            'actor_id': actor_id,
                            'date': datetime.now(),
                            'dossiers': dossier_list}))

    def get_history(self):
        entries = [DispositionHistory.get(mapping)
                   for mapping in self._storage]
        entries.reverse()
        return entries
开发者ID:4teamwork,项目名称:opengever.core,代码行数:36,代码来源:history.py

示例6: LayoutSearchableText

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
def LayoutSearchableText(obj):
    text = [obj.id]
    try:
        text.append(obj.text.output)
    except AttributeError:
        pass
    try:
        text.append(safe_unicode(obj.title))
    except AttributeError:
        pass
    try:
        text.append(safe_unicode(obj.description))
    except AttributeError:
        pass

    behavior_data = ILayoutAware(obj)
    # get data from tile data
    annotations = IAnnotations(obj)
    for key in annotations.keys():
        if key.startswith(ANNOTATIONS_KEY_PREFIX):
            data = annotations[key]
            for field_name in ('title', 'label', 'content'):
                val = data.get(field_name)
                if isinstance(val, basestring):
                    text.append(val)
    if not behavior_data.contentLayout and behavior_data.content:
        dom = fromstring(behavior_data.content)
        for el in dom.cssselect('.mosaic-text-tile .mosaic-tile-content'):
            text.append(tostring(el))

    return concat(*text)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:33,代码来源:indexing.py

示例7: DeleteTile

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
class DeleteTile(TileTraverser):
    """Implements the @@delete-tile traversal view

    Traversing to /path/to/obj/@@delete-tile will list all tiles.
    Traversing to /path/to/obj/@@delete-tile/tile-id will delete tile.
    """

    tileId = None

    def __init__(self, context, request):
        super(DeleteTile, self).__init__(context, request)
        self.annotations = IAnnotations(self.context)

    def __call__(self):
        self.deleted = False
        if self.tileId is not None:
            del self.annotations['%s.%s' % (
                ANNOTATIONS_KEY_PREFIX, self.tileId)]
        return self.index()

    def tiles(self):
        for item in self.annotations.keys():
            if item.startswith(ANNOTATIONS_KEY_PREFIX):
                yield item[len(ANNOTATIONS_KEY_PREFIX) + 1:]

    def publishTraverse(self, request, name):
        """Allow traversal to @@delete-tile/tilename
        """

        if self.tileId is None:
            self.tileId = name

        return self
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:35,代码来源:traversal.py

示例8: onLayoutEdited

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
def onLayoutEdited(obj, event):
    """
    need to get the layout because you need to know what are
    acceptible storage values
    """
    lookup = ILayoutAware(obj)
    layout = lookup.content_layout()

    if not layout:
        return

    tree = fromstring(layout)
    tile_keys = []
    for el in utils.bodyTileXPath(tree):
        tile_url = el.attrib.get('data-tile', '')
        if 'plone.app.standardtiles.field' in tile_url:
            continue
        tile_keys.append(
            ANNOTATIONS_KEY_PREFIX +
            '.' +
            tile_url.split('?')[0].split('/')[-1]
        )

    annotations = IAnnotations(obj)
    for key in list(annotations.keys()):
        if key.startswith(ANNOTATIONS_KEY_PREFIX) and key not in tile_keys:
            del annotations[key]
开发者ID:plone,项目名称:plone.app.blocks,代码行数:29,代码来源:subscribers.py

示例9: __init__

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
 def __init__(self, context):
     self.context = context
     
     annotations = IAnnotations(context)
     if FOLLOWED_KEY not in annotations.keys():
         annotations[FOLLOWED_KEY] = PersistentList()          
     self.followed = annotations[FOLLOWED_KEY]
开发者ID:adam139,项目名称:emc.kb,代码行数:9,代码来源:follow.py

示例10: get_daviz

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
    def get_daviz(self):
        """Given an object, it will return the daviz+charts assigned

        It returns a mapping of
        <daviz uid A>:
            [daviz, (chart_id, chart title, embed_type, fallback_image)],
        <daviz uid B>:
            [daviz, (chart_id, chart title, embed_type, fallback_image)],
        """
        annot = IAnnotations(self.context).get('DAVIZ_CHARTS', {})

        uids_cat = getToolByName(self.context, 'uid_catalog')
        info = {}
        for uid in annot.keys():
            brains = uids_cat.searchResults(UID=uid)
            if not brains:
                logger.warning("Couldn't find visualization with UID %s" % uid)
                continue
            daviz = brains[0].getObject()
            tabs = getMultiAdapter((daviz, self.request),
                                   name="daviz-view.html").tabs

            annot_info = annot.get(uid, {})
            charts = []

            for chart_id in annot_info.keys():
                for tab in tabs:
                    if tab['name'] == chart_id:
                        #code = None #for the future, needs api in daviz
                        embed_type = annot_info[chart_id]
                        charts.append((chart_id, tab['title'], embed_type,
                                       tab['fallback-image']))
            info[uid] = (daviz, charts)

        return info
开发者ID:jean,项目名称:eea.daviz,代码行数:37,代码来源:daviz.py

示例11: purge_unassigned_notes

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
def purge_unassigned_notes(context):
    # this indiscriminately purge all notes not found within an file's
    # specified exposure file type.
    # XXX implement an alternate option that will retain any specified
    # notes
    # XXX don't make this method available in the upgrade step just yet.
    from zope.annotation.interfaces import IAnnotations

    prefix = 'pmr2.annotation.notes-'
    catalog = getToolByName(context, 'portal_catalog')
    files = catalog(portal_type='ExposureFile')
    for b in files:
        file = b.getObject()
        ftpath = file.file_type
        if not ftpath:
            continue

        cftviews = filetypes[ftpath]  # file type views for current file

        # remove unreferenced annotations
        # XXX this assumes users don't manually assign views after
        # specifying file types.
        annotations = IAnnotations(file)
        for k in annotations.keys():
            if not k.startswith(prefix):
                continue
            viewname = k[len(prefix):]
            if not viewname in cftviews:
                del annotations[k]
开发者ID:PMR2,项目名称:pmr2.app,代码行数:31,代码来源:setuphandlers.py

示例12: get_number

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
 def get_number(self, obj):
     ann = IAnnotations(obj)
     if SEQUENCE_NUMBER_ANNOTATION_KEY not in ann.keys():
         generator = getAdapter(obj, ISequenceNumberGenerator)
         value = generator.generate()
         ann[SEQUENCE_NUMBER_ANNOTATION_KEY] = value
     return ann.get(SEQUENCE_NUMBER_ANNOTATION_KEY)
开发者ID:hellfish2,项目名称:opengever.core,代码行数:9,代码来源:sequence.py

示例13: clear_cached_localroles

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
def clear_cached_localroles(userid):
    """Given user id (not login name), clear cached localroles"""
    prefix = 'collective.teamwork.user.localrole.checkLocalRolesAllowed'
    request = getRequest()
    anno = IAnnotations(request)
    relevant = [k for k in anno.keys() if k.startswith(prefix) and userid in k]
    for key in relevant:
        del anno[key]
开发者ID:collective,项目名称:collective.teamwork,代码行数:10,代码来源:localrole.py

示例14: __init__

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
    def __init__(self, context):
        self.context = context
        annotations = IAnnotations(context)
        if FAVORITE_KEY not in annotations.keys():
            # You know what happens if we don't use persistent classes here?
            annotations[FAVORITE_KEY] = PersistentList()

        self.favorite = annotations[FAVORITE_KEY]    
开发者ID:adam139,项目名称:emc.memberArea,代码行数:10,代码来源:favorite.py

示例15: remove_number

# 需要导入模块: from zope.annotation.interfaces import IAnnotations [as 别名]
# 或者: from zope.annotation.interfaces.IAnnotations import keys [as 别名]
    def remove_number(self, obj, **keys):
        """Remove the entry in the local storage for the combinated key.
        """
        key = self.get_key(obj, keys)

        ann = IAnnotations(obj)
        if key in ann.keys():
            del ann[key]
开发者ID:hellfish2,项目名称:opengever.core,代码行数:10,代码来源:unique_number.py


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