Installation
-
Download deco-0.1.tgz; unpack it and run
python setup.py install - Optional: install markdown and textile
-
Add
'deco'to your INSTALLED_APPS setting -
Recommended: add the following line to the end of your urlpatterns, typically in urls.py:
(r'^(?P<url>.*)$', 'deco.quick.view') -
Run
manage.py syncdb
Frames
Deco organizes content into "frames". They can be fragments of pages (the header, or sidebar, or an ad) or whole pages. Every frame has a content format and some content.
Frames are editable through the admin interface. You can also access them with Python code - frames are represented by a Django model, deco.models.Frame.
Rendering a frame
When displaying content from a frame, it gets rendered. Rendering is handled by the draw method of the deco.models.Frame model - you can call it manually, it returns a string that is the frame's rendered output. The string is marked "safe" so it doesn't get auto-escaped by the template system.
If the format is HTML, the content is returned unmodified. If the format is plain text, markdown or textile it gets converted to HTML. If the format is template it gets rendered like any Django template (and you can pass an optional parameter named context - a dict with variables to be added to the template's context).
When rendering frames, a Django template may be specified as a decorator. It will receive one context variable named deco which is a dict with 3 values: 'content' (a string representing the rendered frame), 'title' (the frame's title, or '' if there is none) and 'url' (the frame's URL, or '' if there is none). In this case the output is the rendered decorator.
Template tags
Deco provides a templatetag library - deco-frames - with two tags.
frame
Returns the rendered content of a frame. The first parameter is the frame's title. The second (optional) parameter is a dict that specifies a context - this is useful for frames with the template format.
frame_link
Returns an HTML hyperlink for the specified frame. The frame's URL is taken from the model and the title is used for the link text.
An optional parameter can override the default link text.
Example:
{% frame_link "about page", "go to the about page"}
Assuming that you have a page titled "about page" and its URL is "/about", the output is:
<a href="/about">go to the about page</a>
The "quick" module
This module provides two convenience methods for simple uses of Deco frames.
view
A simple Django view that looks up a frame via URL and renders it, optionally passing in a decorator template and a context. The context is only useful if the frame's content is in Django template format, and it allows you to pass variables to the template. If the URL is not found, a Http404 exception is thrown, typically resulting in a "404 not found" page.
You can set a catch-all urlpattern that sends page requests to the deco.quick.view view, like this:
(r'^(?P
If you want to specify URLs more granularly, it's recommended that the url parameter include the whole requested URL. The following example also makes use of a decorator:
(r'^(?P
draw
This function looks up a frame by title and renders it. The "decorator" and "context" parameters have the same meaning as in the "view" function. This function saves you the trouble of looking up the frame by title (handling the case where the frame does not exist) and calling its draw method.
