Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

dolmen.app.content provides out-of-the-box utilities for Dolmen applications content.

Getting started

We import Grok and grok the package:

>>> import grok
>>> from grokcore.component import testing
>>> from zope.component.hooks import getSite

We create a dolmen.content content:

>>> from dolmen import content
>>> from dolmen.app.content import IDescriptiveSchema

>>> class Mammoth(content.Content):
...    content.name('A furry thing')
...    content.schema(IDescriptiveSchema)

>>> testing.grok_component("mammoth", Mammoth)
True

>>> manfred = Mammoth()
>>> manfred.title = u'A nice mammoth'

>>> site = getSite()
>>> site['manfred'] = manfred

Indexes

dolmen.app.content registers two indexes to catalog the dolmen.content.IBaseContent created inside a Dolmen application:

>>> from dolmen.app.content import indexes

Base indexes

ContentIndexes indexes the content type attribute if a dolmen.content.interfaces.IContent object:

>>> indexes.ContentIndexes.__grok_indexes__
{'content_type': <grok.index.Field object at ...>}

DescriptiveIndexes handles the title and the description of a content implementing IDescriptiveSchema:

>>> indexes.DescriptiveIndexes.__grok_indexes__
{'description': <grok.index.Text object at ...>,
 'title': <grok.index.Text object at ...>}

Searchable text

dolmen.app.content provides a simple ‘ISearchableText’ implementation, allowing full text searches. It comes in two parts.

The index:

>>> indexes.SearchableIndex.__grok_indexes__
{'searchabletext': <grok.index.Text object at ...>}

The adapter:

>>> from zope.index.text.interfaces import ISearchableText
>>> adapter = ISearchableText(manfred)
>>> adapter.getSearchableText()
(u'A nice mammoth', u'')

Thumbnailing

Thanks to dolmen.thumbnailer, dolmen.app.content provides a base thumbnailing policy, using ZODB blobs as storage and introducing a new scale.

Scales

Let’s introspect our Miniaturizer component:

>>> from dolmen.app.content import thumbnails

>>> thumbnails.BlobMiniaturizer.factory
<class 'dolmen.blob.file.BlobValue'>

>>> print thumbnails.BlobMiniaturizer.scales
{'mini': (250, 250), 'square': (64, 64), 'thumb': (150, 150), 'large': (700, 700), 'small': (128, 128), 'preview': (400, 400)}

The new scale, ‘square’, scales down and crops the original image to provide a square thumbnail. This is done using a IThumbnailer adapter:

>>> from dolmen.thumbnailer import IThumbnailer
>>> thumbnails.SquareThumbnailer
<class 'dolmen.app.content.thumbnails.SquareThumbnailer'>
>>> IThumbnailer.implementedBy(thumbnails.SquareThumbnailer)
True

Icon registration

dolmen.app.content allows you to register an icon for your content type.

The default value

>>> from dolmen.app.content import icon
>>> icon.bind().get(manfred)
'...content.png'

Retrieving the icon

>>> from zope.publisher.browser import TestRequest
>>> from zope.component import getMultiAdapter
>>> request = TestRequest()
>>> icon_view = getMultiAdapter((manfred, request), name="icon")
>>> icon_view()
'<img src="http://127.0.0.1/dolmen-app-content-interfaces-IDescriptiveSchema-icon.png" alt="DescriptiveSchema" width="16" height="16" border="0" />'

Defining a content icon

Let’s demonstrate the icon registration with a simple test:

>>> from zope import schema

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

>>> class MyContent(content.Content):
...  """A simple content with an icon
...  """
...  content.schema(IContentSchema)
...  content.name("a simple content type")
...  icon('container.png')

>>> testing.grok_component("mycontent", MyContent)
True

Now, we check if our content has a given icon:

>>> elephant = site['elephant'] = MyContent()
>>> icon_view = getMultiAdapter((elephant, request), name="icon")
>>> icon_view()
'<img src="http://127.0.0.1/dolmen-app-content-IContentSchema-icon.png" alt="ContentSchema" width="16" height="16" border="0" />'

Trying to register an icon file that doesn’t exist or cannot resolve will lead to an error:

>>> class AnotherContent(content.Content):
...  """Another content with an icon
...  """
...  content.schema(IContentSchema)
...  content.name("a simple content type")
...  icon('someimaginary thing.png')
Traceback (most recent call last):
...
GrokImportError: Directive 'icon' cannot resolve the file 'someimaginary thing.png'.

Credits

All Dolmen packages are sponsorised by NPAI (http://www.npai.fr)

Changelog

1.0b2 (2011-02-15)

  • Back to the use of zope.i18nmessageid instead of zope.i18nmessage.

  • Added the condition inclusion of zope.app.locales.

1.0b1 (2011-02-14)

  • Using the latest dolmen.content.

  • dolmen.app.content now defines the IDescriptiveSchema interface that provides the zope.dublincore IDCDescriptiveProperties interface. This is to be used instead of the old IBaseContent from dolmen.content.

  • The indexes now use the new IDescriptiveSchema interface. Please note : this requires the migration of the existing applications.

1.0a3 (2010-06-04)

  • Added an icon for the OrderedContainer type.

1.0a2 (2010-06-04)

  • Corrected the icon grokker that failed if the icon directive was not set on a content.

1.0a1 (2010-06-04)

  • dolmen.app.content now defines the icon directive that used to live in dolmen.content. Added tests to demonstrate the new feature.

0.2.1 (2010-02-25)

  • Using PIL 1.1.7 instead of PILwoTK 1.1.6. This prevents having to declare a third party archive download location.

  • Maintenance cleaning for the release of Grok 1.1rc1. Code is now pep8 compliant.

0.2 (2010-02-01)

  • Added dolmen.blob include in configure.zcml.

  • Cleaning dependencies. The package is now zope.app free and relies on the latest Grok evolution.

0.1 (2009-11-02)

  • Initial release

Metadata

Release files for dolmen.app.content 1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dolmen.app.content 1.0b2
File Size Uploaded
dolmen.app.content-1.0b2.tar.gz 10.0 kB Details

Release files / dolmen.app.content-1.0b2.tar.gz

Download URL dolmen.app.content-1.0b2.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
abdfac787b01d20cd47146293b3dd8bb0a89c6cae0b075f113c501276e5893ac
BLAKE2b-256 checksum
How to use checksums
d94c3a1d3bd8a4c10627d6a06d5828b980b2be43d3f7ab24cb9e0283fe87a21e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page