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


Python base.IBaseObject类代码示例

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


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

示例1: filterTypes

def filterTypes(self, out, types, package_name):
    typesTool = getToolByName(self, 'portal_types')

    filtered_types = []

    for rti in types:
        t = rti['klass']
        name = rti['name']
        meta_type = rti['meta_type']

        isBaseObject = 0
        if IBaseObject.isImplementedByInstancesOf(t):
            isBaseObject = 1
        else:
            for k in t.__bases__:
                if IBaseObject.isImplementedByInstancesOf(k):
                    isBaseObject = 1
                    break

        if isBaseObject:
            filtered_types.append(t)
        else:
            print >> out, ("%s doesnt implements IBaseObject. "
                           "Possible misconfiguration. "
                           "Check if your class has an "
                           "'__implements__ = IBaseObject' "
                           "(or IBaseContent, or IBaseFolder)" % repr(t))

    return filtered_types
开发者ID:dtgit,项目名称:dtedu,代码行数:29,代码来源:utils.py

示例2: filterTypes

def filterTypes(self, out, types, package_name):
    filtered_types = []

    for rti in types:
        t = rti['klass']

        isBaseObject = 0
        if IBaseObject.implementedBy(t):
            isBaseObject = 1
        else:
            for k in t.__bases__:
                if IBaseObject.implementedBy(k):
                    isBaseObject = 1
                    break

        if isBaseObject:
            filtered_types.append(t)
        else:
            print >> out, ("%s doesnt implements IBaseObject. "
                           "Possible misconfiguration. "
                           "Check if your class has an "
                           "'implements(IBaseObject)' "
                           "(or IBaseContent, or IBaseFolder)" % repr(t))

    return filtered_types
开发者ID:seanupton,项目名称:Products.Archetypes,代码行数:25,代码来源:utils.py

示例3: findBaseTypes

def findBaseTypes(klass):
    bases = []
    if hasattr(klass, '__bases__'):
        for b in klass.__bases__:
            if IBaseObject.providedBy(b):
                bases.append(className(b))
    return bases
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:7,代码来源:Registry.py

示例4: __bobo_traverse__

 def __bobo_traverse__(self, REQUEST, name):
     try:
         return self.boboTraverse(self.obj, REQUEST, name)
     except AttributeError:
         if not IBaseObject.providedBy(self.obj):
             return self.boboTraverse(getSite(), REQUEST, name)
         raise
开发者ID:saibatizoku,项目名称:collective.routes,代码行数:7,代码来源:content.py

示例5: findBaseTypes

def findBaseTypes(klass):
    bases = []
    if hasattr(klass, '__bases__'):
        for b in klass.__bases__:
            if IBaseObject.isImplementedByInstancesOf(b):
                bases.append(className(b))
    return bases
开发者ID:dtgit,项目名称:dtedu,代码行数:7,代码来源:Registry.py

示例6: update_translated_ids

def update_translated_ids(obj, event):
    if IBaseObject.providedBy(obj) and obj.isTemporary():
        return
    handler = IMultilanguageURLHandler(event.newParent, None)
    old_handler = IMultilanguageURLHandler(event.oldParent, None)
    if handler is not None and old_handler is not None:
        for lang, id in old_handler.get_translated_ids(event.oldName):
            handler.set_translated_id(event.newName, id, lang)
    if not event.newParent is event.oldParent and old_handler is not None:
        old_handler.remove_translated_ids(event.oldName, False)
开发者ID:Raptus,项目名称:raptus.multilanguageurls,代码行数:10,代码来源:handler.py

示例7: _rawEnum

 def _rawEnum(self, callback, *args, **kwargs):
     # Finds all object to check if they are 'referenceable'.
     catalog = getToolByName(self, 'portal_catalog')
     brains = catalog(dict(id=[]))
     for b in brains:
         o = b.getObject()
         if o is not None:
             if IBaseObject.providedBy(o):
                 callback(o, *args, **kwargs)
         else:
             log('no object for brain: %s:%s' % (b, b.getURL()))
开发者ID:seanupton,项目名称:Products.Archetypes,代码行数:11,代码来源:ArchetypeTool.py

示例8: getFields

 def getFields(self):
     """
     The context should provide IBaseObject
     The creation flag shoul be True
     The context portal_type should be in the list of types with captcha validation
     """
     first_cond = IBaseObject.providedBy(self.context)
     second_cond = self.context.checkCreationFlag()
     third_cond = self.context.portal_type in self.get_captcha_types()
     if first_cond and second_cond and third_cond:
         return self._fields
     return []
开发者ID:luca-bellenghi,项目名称:collective.atcaptchavalidation,代码行数:12,代码来源:extender.py

示例9: create

def create(container=None, type=None, id=None, title=None, strict=True, *args,
           **kwargs):
    """Create a new object.

    :param container: [required] Container object in which to create the new
        object.
    :type container: Folderish content object
    :param type: [required] Type of the object.
    :type type: string
    :param id: Id of the object.  If the id conflicts with another object in
        the container, a suffix will be added to the new object's id. If no id
        is provided, automatically generate one from the title. If there is no
        id or title provided, raise a ValueError.
    :type id: string
    :param title: Title of the object. If no title is provided, use id as
        the title.
    :type title: string
    :param strict: When True, the given id will be enforced. If the id is
        conflicting with another object in the target container, raise a
        KeyError. When False, ``create`` creates a new, non-conflicting id.
    :type param: boolean
    :returns: Content object
    :Example: :ref:`create_content_example`
    """
    if not container:
        raise ValueError('The ``container`` attribute is required.')

    if not type:
        raise ValueError('The ``type`` attribute is required.')

    if not id and not title:
        raise ValueError('You have to provide either the ``id`` or the '
                         '``title`` attribute')

    # Create a temporary id
    id = str(random.randint(0, 99999999))
    container.invokeFactory(type, id, title=title, **kwargs)
    content = container[id]

    # Archetypes specific code
    if IBaseObject.providedBy(content):
        # Will finish Archetypes content item creation process,
        # rename-after-creation and such
        content.processForm()

    # Create a new id from title
    chooser = INameChooser(container)
    new_id = chooser.chooseName(title, content)
    content.aq_parent.manage_renameObject(id, new_id)

    return content
开发者ID:kcleong,项目名称:plone.api,代码行数:51,代码来源:content.py

示例10: unrestricted_create

def unrestricted_create(container=None, portal_type=None,
                        id=None, title=None, transition=None, **kwargs):
    """Create content, bypassing security checks.

    XXX: this would be a bit cleaner if we used api.env.adopt_roles,
    but it doesn't seem to work properly..

    XXX 2: Verbose security needs to be turned on in buildout to make
    this method work. WTF! We need to fix this.

    :param container: container for the created object
    :param portal_type: type of the object to create
    :param id: id of the object to create
    :param title: title of the object to create
    :param transition: name of a workflow transition to perform after
        creation
    :param kwargs: additional parameters which are passed to the
        createContent function (e.g. title, description etc.)
    :returns: object that was created
    """
    portal_types = api.portal.get_tool("portal_types")
    type_info = portal_types.getTypeInfo(portal_type)
    content_id = id or str(random.randint(0, 99999999))
    obj = type_info._constructInstance(
        container, content_id, title=title, **kwargs)

    # Archetypes specific code
    if IBaseObject.providedBy(obj):
        # Will finish Archetypes content item creation process,
        # rename-after-creation and such
        obj.processForm()

    if not id:
        # Create a new id from title
        chooser = INameChooser(container)
        derived_id = id or title
        new_id = chooser.chooseName(derived_id, obj)
        transaction.savepoint(optimistic=True)
        with api.env.adopt_roles(['Manager', 'Member']):
            obj.aq_parent.manage_renameObject(content_id, new_id)

    # perform a workflow transition
    if transition:
        with api.env.adopt_roles(['Manager', 'Member']):
            api.content.transition(obj, transition=transition)

    return obj
开发者ID:tribunasi,项目名称:tribuna.annotator,代码行数:47,代码来源:utils.py

示例11: migrateUIDs

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.providedBy(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?
            # this one can be part of the catalog
            setattr(obj, olduididx, objUID)
            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:seanupton,项目名称:Products.Archetypes,代码行数:44,代码来源:migrations.py

示例12: reindex_object

def reindex_object(obj, recursive=0):
    """reindex the given object.

    If 'recursive' is true then also take reindex of all sub-objects.
    """
    if not IBaseObject.providedBy(obj):
        return

    try:
        catalog_object(obj)
        # Also reindex AT References
        if hasattr(obj, 'at_references'):
            refs = getattr(obj.at_references, 'objectValues', lambda: ())()
            for ref in refs:
                catalog_object(ref)
    except Exception, err:
        logger.warn("Couldn't reindex obj --> %s",
                    getattr(obj, 'absolute_url', lambda: 'None')())
        logger.exception(err)
开发者ID:eea,项目名称:eea.asyncmove,代码行数:19,代码来源:async.py

示例13: update

 def update(self):
     self.available = False
     if not HAS_ARCHETYPES:
         return
     self.context = aq_inner(self.context)
     replaced_types = [
         "ATFolder",
         "ATDocument",
         "ATFile",
         "ATImage",
         "ATNewsItem",
         "ATLink",
         "ATEvent",
         "ATBlobImage",
         "ATBlobFile",
         "Collection",
     ]
     if self.context.meta_type not in replaced_types:
         return
     if not IBaseObject.providedBy(self.context):
         return
     context_fti = self.context.getTypeInfo()
     if IDexterityFTI.providedBy(context_fti):
         self.available = True
开发者ID:mingtak,项目名称:plone.app.contenttypes_for_tpa,代码行数:24,代码来源:viewlets.py

示例14: __call__

    def __call__(self):
        wrapped = IndexableObjectWrapper(self.context, self.catalog)
        text = getattr(wrapped, 'SearchableText')
        if safe_callable(text):
            text = text()

        # Archetypes object: remove id and title
        if IBaseObject.providedBy(self.context):
            for fieldname in ['id', 'title']:
                field = self.context.Schema().getField(fieldname)
                if field is None:
                    continue

                method = field.getIndexAccessor(self.context)
                value = method()
                text = text.replace(value, '', 1)
        # other content (e.g. dexterity): remove title
        elif IContentish.providedBy(self.context):
            text = text.replace(self.context.Title(), '', 1)

        # Strip html tags
        text = re.sub('<[^<]+?>', '', text)

        return text
开发者ID:jean,项目名称:ftw.solr,代码行数:24,代码来源:indexers.py

示例15: create

def create(
    container=None,
    type=None,
    id=None,
    title=None,
    safe_id=False,
    **kwargs
):
    """Create a new content item.

    :param container: [required] Container object in which to create the new
        object.
    :type container: Folderish content object
    :param type: [required] Type of the object.
    :type type: string
    :param id: Id of the object.  If the id conflicts with another object in
        the container, a suffix will be added to the new object's id. If no id
        is provided, automatically generate one from the title. If there is no
        id or title provided, raise a ValueError.
    :type id: string
    :param title: Title of the object. If no title is provided, use id as
        the title.
    :type title: string
    :param safe_id: When False, the given id will be enforced. If the id is
        conflicting with another object in the target container, raise an
        InvalidParameterError. When True, choose a new, non-conflicting id.
    :type safe_id: boolean
    :returns: Content object
    :raises:
        KeyError,
        :class:`~plone.api.exc.MissingParameterError`,
        :class:`~plone.api.exc.InvalidParameterError`
    :Example: :ref:`content_create_example`
    """
    # Create a temporary id if the id is not given
    content_id = not safe_id and id or str(random.randint(0, 99999999))

    if title:
        kwargs['title'] = title

    try:
        container.invokeFactory(type, content_id, **kwargs)
    except UnicodeDecodeError:
        # UnicodeDecodeError is a subclass of ValueError,
        # so will be swallowed below unless we re-raise it here
        raise
    except ValueError as e:
        if ISiteRoot.providedBy(container):
            allowed_types = container.allowedContentTypes()
            types = [allowed_type.id for allowed_type in allowed_types]
        else:
            try:
                types = container.getLocallyAllowedTypes()
            except AttributeError:
                raise InvalidParameterError(
                    "Cannot add a '%s' object to the container." % type
                )

        raise InvalidParameterError(
            "Cannot add a '{0}' object to the container.\n"
            "Allowed types are:\n"
            "{1}\n"
            "{2}".format(type, '\n'.join(sorted(types)), e.message)
        )

    content = container[content_id]

    # Archetypes specific code
    if IBaseObject.providedBy(content):
        # Will finish Archetypes content item creation process,
        # rename-after-creation and such
        content.processForm()

    if not id or (safe_id and id):
        # Create a new id from title
        chooser = INameChooser(container)
        derived_id = id or title
        new_id = chooser.chooseName(derived_id, content)
        # kacee: we must do a partial commit, else the renaming fails because
        # the object isn't in the zodb.
        # Thus if it is not in zodb, there's nothing to move. We should
        # choose a correct id when
        # the object is created.
        # maurits: tests run fine without this though.
        transaction.savepoint(optimistic=True)
        content.aq_parent.manage_renameObject(content_id, new_id)

    return content
开发者ID:niteoweb,项目名称:plone.api,代码行数:88,代码来源:content.py


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