Cache components in Django automatically, turn caching on and off without changing the template
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
django-components
doc
.gitignore
.gitmodules
LICENSE
Makefile
README.md
nose.ini
requirements-dev.txt
requirements.txt

README.md

django-components

An encapsulated thing that is meant to be reused across the site in many
different views. Product reviews box, little stats widgets, etc. It's meant to
be like a mini-version of a view that you can embed in another page.

Benefits: easy to reuse code, change things in only one place to change
them everywhere, cache components automatically, turn caching on and off
without changing the template. All client side code (js, css, html) for one
component is in one place. No mucking around with manual cache key
generating.

In your template, add:

    {% components_maker %}
    {% reviewscomponent subscriber %}

Ta da.

To build a new component, simply inherit Component and:
    - Override fetch_data to return the context for your component template
    - Override options to pass in any variables you need, like user ids.
    This is in Classytags format.
    - Declare name as the template file to use.
    - Optionally override any other (cache key, rendering) function for
    more complex behavior

Overridables:
    - cached=True: enable / disable cache.
    - cache_duration=60*60*24: cache time in seconds.
    - tag_name=classname.lower(): name of the template tag
    - template_name: Name of the template to use
    - cache_vary_on: List of attribute names to get the value of when
    generating a cache key. Defaults to detecting the template tag
    arguments and using those.
    - sekizai_blocks: Dictionary of blockname -> content to inject js /
    css / etc into the template.

TODO: maybe have post_render also cache subcontext data
TODO: look into disabling offline compression to get compression to play
nice with components/sekizai https://github.com/ojii/django-sekizai/issues/4