.. include:: _replacement-directives.txt
================================
Customizing your MyDolmen site
================================
:Author: Vincent Fretin
:Contributors: Aroldo Souza-Leite
:Version: unknown
You will customize your |dlm| application in the following parts of this
tutorial.
Creating your own |dlm| site
----------------------------
In *src/mydolmen/app.py* module (remove all existing code), implement a |dlm|
site by inheriting from the ``Dolmen`` class:
.. code-block:: python
from dolmen.app.site import Dolmen
class MySite(Dolmen):
title = u"My project site"
But MySite will have a default factory and so will appear in the Add menu. To
disable the auto creation of the factory, change it like this:
.. code-block:: python
from dolmen.app.site import Dolmen
from dolmen import content
class MySite(Dolmen):
content.nofactory()
title = u"My project site"
For now, you only have the admin:admin account.
You can add a PAU to your application:
.. code-block:: python
from dolmen.app.site import Dolmen
from dolmen import content
from dolmen.app.authentication import initialize_pau
from zope.authentication.interfaces import IAuthentication
from zope.pluggableauth import PluggableAuthentication as PAU
import grok
class MySite(Dolmen):
content.nofactory()
title = u"My project site"
grok.local_utility(PAU, IAuthentication, setup=initialize_pau, public=True, name_in_container="users")
And you need *menhir.contenttype.user* to create a user directory and create
users.
Add to configure.zcml:
.. code-block:: xml
Add to setup.py:
.. code-block:: python
'zope.authentication',
'zope.pluggableauth',
'dolmen.app.authentication',
'menhir.contenttype.user',
You have to recreate your application. You can now create a user directory
(users) and create some users.
For the user, you can download the original image, with the namespace traverser
*download* and the field name *portrait*:
http://localhost:8080/demo/users/vincentfretin/++download++portrait
Anywhere in the portal, you can access to an avatar, a square image:
http://localhost:8080/demo/++avatar++vincentfretin
It's useful to develop a commenting system, like *menhir.simple.comments*.
Adding content types
--------------------
We'll add an *Image* content type.
Add to *setup.py*:
.. code-block:: python
menhir.contenttype.image
Add to *configure.zcml*:
.. code-block:: xml
Run the buildout. Restart the site. You can now add images.
Creating content types
----------------------
Creating a folder and a content:
.. code-block:: python
from dolmen.file import ImageField
from dolmen.blob import BlobProperty
from zope import schema
from zope.container.constraints import contains
from zope.interface import Interface
class IArtBook(Interface):
contains(".IPicture")
class ArtBook(content.Container):
grok.implements(IArtBook)
content.name(u"My documents")
content.require("dolmen.content.Add")
class IPicture(content.IBaseContent):
description = schema.Text(title=u"Description")
image = ImageField(title=u"Image")
class Picture(content.Content):
content.schema(IPicture)
content.name(u'My document')
content.require("dolmen.content.Add")
image = BlobProperty(IPicture['image'])
We inherit from ``content.IBaseContent`` which contains the title. We define
explicitly a BlobProperty for the image here. The ``content.schema`` directive
will do the grok.implements too.
ArtBook container can contain only Picture objects. Picture can be added
everywhere.
Add to *configure.zcml*:
.. code-block:: xml
and in your *setup.py*:
.. code-block:: python
dolmen.blob
dolmen.file
zope.container
zope.interface
zope.schema
For the image, you have access to thumbnails like this:
- http://localhost:8080/demo/image/++thumbnail++image.square
- http://localhost:8080/demo/image/++thumbnail++image.large
- etc.
Changing the view of a content type
-----------------------------------
To change the view for a content type:
.. code-block:: python
from dolmen.app.layout import models
class PictureView(models.Index):
grok.context(IPicture)
def render(self):
return "hello"
Include the type Image only in a IArtBook folder
------------------------------------------------
Example:
.. code-block:: python
from menhir.contenttype.image import IImage, Image
from zope.container.constraints import contains, containers
from zope.interface import Interface, classImplements
class IArtBook(content.IBaseContent):
contains(".IPicture", IImage)
class IImageConstraints(Interface):
containers(IArtBook)
classImplements(Image, IImageConstraints)
Include slimbox preview for an image
------------------------------------
Code:
.. code-block:: python
from megrok.resource import component_includes
from menhir.contenttype.user import UserView
from menhir.contenttype.image import ImagePopup
component_includes(UserView, ImagePopup)
It is already done in the *menhir.skin.snappy* theme, but not in the
*menhir.skin.lightblue* theme.
Other functionalities
---------------------
If buildout says that a package was not found, it's probably the package
doesn't have a release yet. You normally add it to auto-checkout in
:file:`sources.cfg` to fix that.
There are some packages you can add to your buildout to add functionalities to
your application. Simply add the package to :file:`setup.py` and
:file:`configure.zcml`:
Functionalities:
- dolmen.app.breadcrumbs: breadcrumbs
- dolmen.app.search: search box
- dolmen.app.viewselector: add a view menu
- menhir.simple.livesearch: add a livesearch to the searchbox
- menhir.simple.navtree
Functionalities in development, may be buggy:
- dolmen.app.clipboard: add cut, copy, paste functionalities
- dolmen.app.metadatas: metadata tab on simple content type to edit dublin core
metadata.
Content types:
- menhir.contenttype.document
- menhir.contenttype.file
- menhir.contenttype.folder
- menhir.contenttype.rstdocument
- menhir.contenttype.image
- menhir.contenttype.photoalbum
And other packages used in snappy demo:
- menhir.simple.tag
- snappy.*
You have the full list at
http://gitweb.dolmen-project.org/?o=project