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


Python IBaseObject.isImplementedBy方法代码示例

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


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

示例1: _rawEnum

# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import isImplementedBy [as 别名]
 def _rawEnum(self, callback, *args, **kwargs):
     """Finds all object to check if they are 'referenceable'.
     """
     catalog = getToolByName(self, 'portal_catalog')
     brains = catalog(id=[])
     for b in brains:
         o = b.getObject()
         if o is not None:
             if IBaseObject.isImplementedBy(o):
                 callback(o, *args, **kwargs)
         else:
             log('no object for brain: %s:%s' % (b,b.getURL()))
开发者ID:dtgit,项目名称:dtedu,代码行数:14,代码来源:ArchetypeTool.py

示例2: migrateUIDs

# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import isImplementedBy [as 别名]
def migrateUIDs(portal, out):
    count=0
    uc = getToolByName(portal, UID_CATALOG)    
    print >>out, 'Migrating uids\n'
    
    # temporary add a new index    
    if olduididx not in uc.indexes():
        uc.addIndex(olduididx, 'FieldIndex', extra=None)
        if not olduididx in uc.schema():
            uc.addColumn(olduididx)
    
    # clear UID Catalog 
    uc.manage_catalogClear()
    
    # rebuild UIDS on objects and in catalog
    allbrains = portal.portal_catalog()
    for brain in allbrains:
        # get a uid for each thingie
        obj = brain.getObject()
        if not IBaseObject.isImplementedBy(obj): 
            continue #its no Archetype instance, so leave it
        
        objUID = getattr(aq_base(obj), '_uid', None)        
        if objUID is not None: #continue    # not an old style AT?
            setattr(obj, olduididx, objUID) # this one can be part of the catalog
            delattr(obj, '_uid')
            setattr(obj, UUID_ATTR, None)
        obj._register()            # creates a new UID
        obj._updateCatalog(portal) # to be sure
        count+=1
        if not count % 10:
            print >>out, '.',
        # avoid eating up all RAM
        if not count % 250:
            print >>out, '*',
            transaction.savepoint(optimistic=True)
    print >>out, '\nDone\n'
    if USE_FULL_TRANSACTIONS:
        transaction.commit()
    else:
        transaction.savepoint(optimistic=True)

    print >>out, count, "UID's migrated."
开发者ID:dtgit,项目名称:dtedu,代码行数:45,代码来源:migrations.py

示例3: install_indexes

# 需要导入模块: from Products.Archetypes.interfaces.base import IBaseObject [as 别名]
# 或者: from Products.Archetypes.interfaces.base.IBaseObject import isImplementedBy [as 别名]
def install_indexes(self, out, types):
    portal_catalog = catalog = getToolByName(self, 'portal_catalog')
    for cls in types:
        if 'indexes' not in cls.installMode:
            continue

        for field in cls.schema.fields():
            if not field.index:
                continue

            if isinstance(field.index, basestring):
                index = (field.index,)
            elif isinstance(field.index, (tuple, list)):
                index = field.index
            else:
                raise SyntaxError("Invalid Index Specification %r"
                                  % field.index)

            for alternative in index:
                installed = None
                index_spec = alternative.split(':', 1)
                use_column  = 0
                if len(index_spec) == 2 and index_spec[1] in ('schema', 'brains'):
                    use_column = 1
                index_spec = index_spec[0]

                accessor = field.getIndexAccessorName()

                parts = index_spec.split('|')
                # we want to be able to specify which catalog we want to use
                # for each index. syntax is
                # index=('member_catalog/:schema',)
                # portal catalog is used by default if not specified
                if parts[0].find('/') > 0:
                    str_idx = parts[0].find('/')
                    catalog_name = parts[0][:str_idx]
                    parts[0] = parts[0][str_idx+1:]
                    catalog = getToolByName(self, catalog_name)
                else:
                    catalog = portal_catalog
                
                #####################
                # add metadata column 
                
                # lets see if the catalog is itself an Archetype:
                isArchetype = IBaseObject.isImplementedBy(catalog)
                # archetypes based zcatalogs need to provide a different method 
                # to list its schema-columns to not conflict with archetypes 
                # schema                
                hasNewWayMethod = hasattr(catalog, 'zcschema')
                hasOldWayMethod = not isArchetype and hasattr(catalog, 'schema')
                notInNewWayResults = hasNewWayMethod and accessor not in catalog.zcschema()
                notInOldWayResults = hasOldWayMethod and accessor not in catalog.schema()
                if use_column and (notInNewWayResults or notInOldWayResults):
                    try:
                        catalog.addColumn(accessor)
                    except:
                        import traceback
                        traceback.print_exc(file=out)

                ###########
                # add index
                
                # if you want to add a schema field without an index
                #if not parts[0]:
                #    continue

                for itype in parts:
                    extras = itype.split(',')
                    if len(extras) > 1:
                        itype = extras[0]
                        props = Extra()
                        for extra in extras[1:]:
                            name, value = extra.split('=')
                            setattr(props, name.strip(), value.strip())
                    else:
                        props = None
                    try:
                        #Check for the index and add it if missing
                        catalog.addIndex(accessor, itype,
                                         extra=props)
                        catalog.manage_reindexIndex(ids=(accessor,))
                    except:
                        # FIXME: should only catch "Index Exists"
                        # damned string exception !
                        pass
                    else:
                        installed = 1
                        break

                if installed:
                    break
开发者ID:dtgit,项目名称:dtedu,代码行数:94,代码来源:utils.py


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