2009/12/9 Jim Baack <
jba...@accelerantsys.com>:
> Want to understand the "recommended" way to access the schema from a
> content object. In this code
>
> .......
> from zope.app.content import queryContentType
> from plone.dexterity.schema import SCHEMA_CACHE
Definitely not by accessing the SCHEMA_CACHE, which is an implementation detail.
> .........
> class custom(plone.dexterity.content.Item):
> .......
> schema1 = queryContentType(self)
> schema2 = SCHEMA_CACHE.get(self.portal_type)
>
>
>
> the first way always returns None while the second works fine.
queryContentType should work, and is the recommended way. In which
context are you calling it? What is the schema interface? How did you
register it?
The "other" way is to do lookupSchema() on the FTI.
Do not use the SCHEMA_CACHE.
> I have
> a schema defined with an XML model via plone.supermodel and as you can
> see, a custom content type. Adding, editing and viewing the type works
> fine. The documentation led me to believe the first way should work.
If the schema is the default and wired up correctly, it should be
marked with IContentType and so should work with queryContentType().
If you can give us a bit more detail so that we can reproduce the
issue, then it may be a bug that needs fixing.
Otherwise, getUtility(IDexterityFTI, name=u"my.type").lookupSchema()
will work too, and has the benefit of working even when you don't have
a type object.
Martin