overview

A PyLucid plugin is very similar to a Django App, with views.py, models.py, template-dirs etc.

The Plugins stored in special directories:

../pylucid_project/pylucid_plugins/ all shipped with PyLucid
../pylucid_project/external_plugins/ for external plugins, installed by users

All Plugins in theses special directories would be automatic insert in settings.INSTALLED_APPS and settings.TEMPLATE_DIRS

There are a few API/callbacks in PyLucid for theses plugins. Read below...

view types

view type HttpResponse inline urls.py
lucidTag - X -
http_get_views() X X -
PluginPage X X X
context middleware X X -

explanation:

  • HttpResponse:
    • Plugin can build a complete page via return HttpResponse object
    • Plugin can return other response type, e.g.: HttpRedirect
  • inline:
    • Plugin can replace the normal page content with this own content
  • urls.py:
    • Plugin can have more than one view

plugin hooks

lucidTag

Probably the most used API. Used by many plugins e.g.: auth (insert login/logout link), RSS to insert a feed into the page.

A lucidTag is the simples plugin API. It's nice to insert dynamic stuff into a page. You can insert lucidTag into PageContent or into the global page template.

The plugin must only defined a lucidTag function in the views.py file and return a string/unicode content.

The lucidTag is a django template tag, witch called the view function. It's allways available.
Defined in pylucid_project/apps/pylucid/defaulttags/lucidTag.py

tag syntax looks like this:

1
2
3
4
{% lucidTag PluginName %}
{% lucidTag PluginName.view_method %}
{% lucidTag PluginName kwarg1="value1" %}
{% lucidTag PluginName kwarg1="value1" kwarg2="value2" %}

examples:

The followed tag calls the view lucidTag(request, id=123) from pylucid_plugins/poll/views.py:

1
{% lucidTag poll id=123 %}

This tag calls all_polls() from pylucid_plugins/poll/views.py:

1
{% lucidTag poll.all_polls %}

for surounding the plugin output with a DIV or SPAN tag the plugin template can extends from css_anchor_div or css_anchor_span, e.g:

1
2
3
4
5
{% extends "pylucid/css_anchor_div.html" %}

{% block plugin_content %}
...the plugin html template content...
{% endblock %}

http_get_views()

used by e.g.: auth login/logout views

Requested via http GET Parameter, e.g.:

http_get_views() can return:

PluginPage

used by e.g.: blog plugin

A PluginPage is one type of plugin PageTree. The plugin has his own urls.py file. These urls would be "inserted" at the PageTree point.

The admin must create a PageTree entry from type plugin and select the plugin.

It's for "big" plugins witch has more than one view.

The template/output must extends from template, e.g.:

HTML+Django/Jinja
1
2
3
4
5
{% extends template_name %}

{% block content %}
...the plugin html template content...
{% endblock content %}

To 'insert' a page into the django admin panel, extends from admin/base_site.html, e.g.:

HTML+Django/Jinja
1
2
3
4
5
{% extends "admin/base_site.html" %}

{% block content %}
...the plugin html template content...
{% endblock content %}

context middleware

used by e.g.: breadcrumb

see also:

plugin has a context_middleware.py with a ContextMiddleware class witch has a render method.

context middleware plugin are inserted via a special tag:

1
<!-- ContextMiddleware PluginName -->

The Plugin ContextMiddleware.render() method should return None or a HttpResponse object. The content from the response would be replace the tag.