[Product-Developers] know folderish types

Rafael Oliveira rafaelbco at gmail.com
Mon May 28 19:07:08 UTC 2012

I did the following to obtain all container-like Dexterity content
types on a project I'm working on.

However, reading through this thread I realized I can improve it to be
more bullet proof. More specifically: I should test for IFolderish
implementation rather than inheritance from the Container class. Maybe
someday I'll do that :)

# Code begin
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.InterfaceTool import getDottedName
from plone.dexterity.content import Container
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import resolveDottedName
from zope.app.component.hooks import getSite

def get_ftis():
    Return a sequence of `IDexterityFTI` corresponding to all
Dexterity content types on
    the portal.
    portal = getSite()
    portal_types = getToolByName(portal, 'portal_types')
    return [fti for fti in portal_types.listTypeInfo() if

def is_container_type(fti):
    Retorna `True` se e somente se o `IDexterityFTI` fornecido
representa um tipo que é um
    klass = resolveDottedName(fti.klass)
    return issubclass(klass, Container)

def get_container_ftis():
    Return a sequence of `IDexterityFTI` corresponding to all
Dexterity content types on
    the portal which are container-like.
    return [fti for fti in get_ftis() if is_container_type(fti)]
# Code end

Rafael Bruno Cavalhero de Oliveira
Analista de Desenvolvimento de Sistemas - SERPRO

On Mon, May 28, 2012 at 3:32 PM, Héctor Velarde
<hector.velarde at gmail.com> wrote:
> this is the code of listPortalTypesWithInterfaces:
>    def listPortalTypesWithInterfaces(self, ifaces):
>        pt = getToolByName(self, 'portal_types')
>        value = []
>        for data in listTypes():
>            klass = data['klass']
>            for iface in ifaces:
>                if iface.implementedBy(klass):
>                    ti = pt.getTypeInfo(data['portal_type'])
>                    if ti is not None:
>                        value.append(ti)
>        return value
> I think you can easily implement something like that asking for the
> fti.klass of the content type.
> ask Martin/David if they want to add something like that on Dexterity.
> did you already signed the Plone core developer agreement? ;-)
> best regards
> Héctor Velarde
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> https://lists.plone.org/mailman/listinfo/plone-product-developers

More information about the Product-Developers mailing list