Skip to main content

Dolmen contenttype extension : document

Project description

menhir.contenttype.document provides a text-centered content for Dolmen based Grok applications. This document type has a field allowing a WYSIWYG edition and indexes itself for full-text searches.


A Document has a dedicated schema defining a text field, in addition of the base IDescriptiveSchema:

>>> from import IDescriptiveSchema
>>> from menhir.contenttype.document import IDocument

>>> IDocument.isOrExtends(IDescriptiveSchema)

>>> from dolmen.content import schema
>>> from menhir.contenttype.document import Document

>>> IDocument in schema.bind().get(Document)

The text field is called “body”, as it is the document’s body text:

>>> for attr, doc in IDocument.namesAndDescriptions():
...   print attr, ':', doc
body : <zope.schema...Text object at ...>


In order to create a Document content, the current user will have to be granted the dolmen.content.Add permission, from the package:

>>> from dolmen.content import require
>>> require.bind().get(Document)


The WYSIWYG widget is provided by dolmen.widget.tinymce, using the javascript library TinyMCE and jQuery. The Add form and the Edit form will display the widget, since menhir.contenttype.document provides a FieldsCustomizer adapter (see dolmen.forms.crud documentation):

>>> from dolmen.forms.crud import Edit
>>> mydoc = Document(title=u'Some title', body=u"Some body")

>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()

>>> editform = Edit(mydoc, request)
>>> editform.update()

>>> editform.fields['body'].mode


A Document is indexed in full-text, using an ISearchableText adapter:

>>> from zope.index.text.interfaces import ISearchableText
>>> indexer = ISearchableText(mydoc)
>>> indexer.getSearchableText()
(u'Some title', u'', u'Some body\n\n')

>>> mydoc.body = u'<p>Rich content comes in <strong>HTML</strong></p>'
>>> indexer.getSearchableText()
(u'Some title', u'', u'Rich content comes in **HTML**\n\n')

>>> mydoc.description = u"I'm described"
>>> indexer.getSearchableText()
(u'Some title', u"I'm described", u'Rich content comes in **HTML**\n\n')


A Document has its very own index view, allowing it to render in a simple way, without the default field names (see dolmen.forms.crud):

>>> from zope.component import getMultiAdapter
>>> view = getMultiAdapter((mydoc, request), name='index')

>>> from import Page
>>> isinstance(view, Page)

>>> print view.content()
<div class="document">
  <h1>Some title</h1>
  <p>Rich content comes in <strong>HTML</strong></p>


0.2 (2011-02-14)

  • Updated to use IDescriptiveContent from instead of IBaseContent from dolmen.content that non longer exists : a document now has a description attribute in addition to title. This change has been echoed in the indexer.

  • Updated dependencies.

0.1 (2010-07-20)

  • 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

menhir.contenttype.document-0.2.tar.gz (5.5 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