Back to index

plone3  3.1.7
Go to the documentation of this file.
00001 from Products.Archetypes.interfaces import ISchema, IBaseObject
00002 from zope.component import adapter
00003 from zope.interface import implementer
00005 @implementer(ISchema)
00006 @adapter(IBaseObject)
00007 def instanceSchemaFactory(context):
00008     """Default schema adapter factory.
00010     In BaseObject, the Schema() method will do 'schema = ISchema(self)'. This
00011     adapter factory is the default, meaning that setting a 'schema' class
00012     attribute pointing to a schema is the default way of supplying a schema.
00014     You may override this behaviour by supplying a different adapter. Most
00015     likely, this will adapt some marker interface you apply to your own
00016     content type and provide ISchema, e.g.:
00018       @implementer(ISchema)
00019       @adapter(IMyObject)
00020       def mySchemaFactory(context):
00021           return ...
00023     The challenge is that the accessors and mutators of the returned schema
00024     must be available as methods on 'context', with appropriate security
00025     declarations. When the schema is set in a 'schema' class-attribute, this
00026     is taken care of by ClassGen. However, if you wish to provide the schema
00027     with a different adapter, you have three choices:
00029      1. Provide the accessor and mutator methods explicitly in the class. This
00030      probably means you will be properly implementing a particular interface,
00031      which is never a bad thing.
00033      2. Run Products.Archetypes.VariableSchemaSupport.VarClassGen on the class.
00034      This will generate the missing methods. However, this may be slow, so
00035      you may need to implement a marker to ensure it only happens once. (The
00036      VariableSchemaSupport class attempts to do this, but does it badly and is
00037      probably not to be relied on). Also note that this effectively precludes
00038      any site-local or per-instance semantics, since it modifies the global
00039      class dict.
00041      3. Add the methods per-instance yourself. This is what the ContentFlavors
00042      product does, so you may be better off using that.
00043     """
00044     return context.schema