Skip to main content

A simple, pluggable content-manager for django.

Project description

django-contentmanager is a so-called ‘reusable app’ to, wait for it, manage content. It does so using plugins that can be scattered over any number of apps, each providing specific types of content. A plugin could list the ten most popular news-stories, highest rated vegetarian dishes or show a selected gallery from a photo-collection app. Of course it could also be a block of (marked up) text.

Quick start

To try it out clone the repository and go to the demoproject-dir.

Assuming you have django on your PYTHONPATH you should be up and running with these commands:

$./manage.py syncdb --noinput
...
$./manage.py runserver

Then open your browser and go to http://localhost:8000/.

This will bring up a rather plain page (with this README) as an example of a ‘paragraph’. If you follow the ‘login’ link you will go to the admin where you can login with test/test. In your normal project you would have to provide a nicer mechanism for your users to log in (and out) but this is just a quick demo so I’ll leave that as an exercise for the reader.

Back at http://localhost:8000/ you will now see a link ‘Editmode On’. This will turn on ‘editmode’ and allow you to add, edit and delete plugins in an, in my opion, intuitive way. Right there on the page: No need to swich back and forth between admin and ‘frontend’ but instant feedback.

Using the contentmanager

To use the contentmanager in your project or application you’ll need to add the contentmanager to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = (
             ...
             'contentmanager',
             ...
             )

make sure your project uses the request-context-processsor:

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request"
    )

and finally include contentmanager.urls in your urls.py and run autodiscover:

urlpatterns = patterns(
        '',
        ...
        (r'^contentmanager/', include('contentmanager.urls')),
        ...
        )

from contentmanager import autodiscover
autodisvover()

and hook up the the contentmanager in your template(s):

{% load contentmanagertags %}
{% block content %}
{% get_area request 'content' %}
{% end block %}

{% block sidebar %}
{% get_area request 'sidebar' %}
{% end block %}

Writing plugins

Included with the demoapp are a few simple plugin examples (in basicblocks/reveplugins.py) to give you the basic idea.

To write your own plugins you have to add a reveplugins module to you application and subclass from contentmanager.plugins.BasePlugin (or BaseModelPlugin). The most basic plugins just need to define their own render method. The render method is passed the request object and should return a (unicode) string:

class HelloWorld(BasePlugin):
    def render(self, request):
        return "Hello world"

To make the plugin available to the contentmanager and ultimately your users you need to register it:

from contentmanager import registry
registry.register(HelloWorld)

Finally, to populate the registry you should include the following in your projects urls.py:

from contentmanager import autodiscover
autodiscover()

This will find all reveplugins modules in all your INSTALLED_APPS and load any registered plugins.

Permissions

Plugins roughly follow the same permission system as django-models. When a plugin is registered the contentmanager automatically creates add, change and delete permissions. Since these permissions could collide with model permissions all plugin permissions are kept in the contentmanager ‘namespace’ (linked to the content_type PluginType if you really want to know) and are appended with ‘_plugin’.

For example, a HTML-plugin would have the permissions ‘contentmanager.add_html_plugin’, ‘contentmanager.delete_html_plugin’, ‘contentmanager.delete_html_plugin’.

Plugins have convenient has_add_permission, has_change_permission, has_delete_permission methods but if you use the proper codename as explained above you can use the standard django permissions system in both python- and templatecode.

Plugins can also add additional permissions in the same manner as django models do except that they are all ‘bound’ to PluginType.

TODO

  • More complex plugin example

  • BaseModelPlugin example

  • Plugin API overview

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

django-contentmanager-2012.5.9.tar.gz (97.6 kB view details)

Uploaded Source

File details

Details for the file django-contentmanager-2012.5.9.tar.gz.

File metadata

File hashes

Hashes for django-contentmanager-2012.5.9.tar.gz
Algorithm Hash digest
SHA256 1e35e1e1ae08fe35a485e000b1915376a08863365fcaeea8e1665e3bb848d8fa
MD5 82aa95495f17e928e112ea4c8238f903
BLAKE2b-256 a34da2fb9cdadc958f873beaaf0187a1d3d2751c73efcbaf0475ddd5442bafe0

See more details on using hashes here.

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