Skip to main content

Dolmen content-type framework

Project description

The package dolmen.content is a convenient way to define content types. Content types usually have several attributes : a type, a schema, an icon. In addition, they need security to control the creation, pages to edit them, easy ways to control the display, and the widgets. This is what provides dolmen.content, with an easy-to-use set of grok directives.

Example

A dolmen.content content is declared as a simple class. Some directives are available to define your content: name, icon, schema and factory. To have detailed information about these directives, please have a look at the package tests.

Defining the content

Let’s demonstrate the package’s features with a simple and non-exhaustive test:

>>> import dolmen.content
>>> from zope import schema

>>> class IContentSchema(dolmen.content.IBaseContent):
...    text = schema.Text(title=u"A body text", default=u"N/A")

>>> class MyContent(dolmen.content.Content):
...  """A very simple content
...  """
...  dolmen.content.schema(IContentSchema)
...  dolmen.content.name("a simple content type")

Grokking

We now let Grok register our component:

>>> import grok
>>> grok.testing.grok_component('mycontent', MyContent)
True

Factory

When the content is registered, a factory is registered, using the full module and class dotted names. It allows us to query and instanciate the content easily:

>>> from zope.component import getUtility
>>> factory = getUtility(dolmen.content.IFactory,
...                      name="dolmen.content.MyContent")
>>> factory
<dolmen.content.factoring.Factory object at ...>

Schema

The content can now be instanciated. As we can see here, the object is effectively providing the schema:

>>> my_content = factory()

>>> my_content.__content_type__
'a simple content type'

>>> IContentSchema.providedBy(my_content)
True
>>> my_content.text
u'N/A'

Changelog

0.2.2 (2009-09-25)

  • Using the last dolmen.field version with a bug fix.

0.2.1 (2009-09-20)

  • Added tests and cleaned the testing module.

0.2 (2009-09-04)

  • Added an OrderedContainer base class.

0.1 (2009-09-01)

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dolmen.content-0.2.2.tar.gz (11.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page