Widgeter: A simple engine for backend widgets
Project description
[![Build Status](https://travis-ci.org/dlapiduz/django-widgeter.png?branch=master)](https://travis-ci.org/dlapiduz/django-widgeter)
Widgeter
========================
A simple engine for django backend widgets based on https://github.com/marcinn/django-widgets.
Features
-----------------
- Creation of custom widgets in reusable apps
- Rendering of widgets by name
- Rendering of widget blocks without previous knowledge of widget names
- Autodiscovery of widgets from all installed apps
Installation
-----------------
1. Install the package using `pip install django-widgeter`
1. Add `widgeter` to your `INSTALLED_APPS` in `settings.py`
Defining a Widget
-----------------
Add a `widgets.py` file on your application with the following statements.
- Widgets can be defined with a template (and optionally a context):
```
from widgeter.base import Widget
class HelloWorld(Widget):
template = 'hello_world/widget.html'
def get_context(self, context, options=None):
return { 'message': u'Hello World!' }
```
or with a render function:
```
from widgeter.base import Widget
class HelloWorld(Widget):
def render(self, context, options=None):
return u'Hello world!'
```
- Register your widget:
```
from widgeter.registry import registry
registry.register('hello_world', HelloWorld())
```
Rendering a Widget
-----------------
On a template you first have to load the template tags and then render the particular widget:
```
{% load widgeter %}
{% widget "hello_world" %}
```
You can also pass variables to your widget:
```
{% load widgeter %}
{% widget "hello_world" current_user %}
```
Using Blocks
-----------------
Widget blocks allow you to render widgets without previously knowing the names for them.
The autodiscovery process will add them to the registry and you can the look them up by block name.
Priorities can also be assigned to render them in order.
- First define a block on the widget:
```
from widgeter.base import Widget
class HelloWorld(Widget):
block = 'home'
priority = '1'
template = 'hello_world/widget.html'
def get_context(self, context, options=None):
return { 'message': u'Hello World!' }
```
- Then, on the template, use the `widget_block` tag:
```
{% load widgeter %}
{% widget_block "home" current_user %}
```
Running the Tests
------------------------------------
You can run the tests with via::
python setup.py test
or::
python runtests.py
Widgeter
========================
A simple engine for django backend widgets based on https://github.com/marcinn/django-widgets.
Features
-----------------
- Creation of custom widgets in reusable apps
- Rendering of widgets by name
- Rendering of widget blocks without previous knowledge of widget names
- Autodiscovery of widgets from all installed apps
Installation
-----------------
1. Install the package using `pip install django-widgeter`
1. Add `widgeter` to your `INSTALLED_APPS` in `settings.py`
Defining a Widget
-----------------
Add a `widgets.py` file on your application with the following statements.
- Widgets can be defined with a template (and optionally a context):
```
from widgeter.base import Widget
class HelloWorld(Widget):
template = 'hello_world/widget.html'
def get_context(self, context, options=None):
return { 'message': u'Hello World!' }
```
or with a render function:
```
from widgeter.base import Widget
class HelloWorld(Widget):
def render(self, context, options=None):
return u'Hello world!'
```
- Register your widget:
```
from widgeter.registry import registry
registry.register('hello_world', HelloWorld())
```
Rendering a Widget
-----------------
On a template you first have to load the template tags and then render the particular widget:
```
{% load widgeter %}
{% widget "hello_world" %}
```
You can also pass variables to your widget:
```
{% load widgeter %}
{% widget "hello_world" current_user %}
```
Using Blocks
-----------------
Widget blocks allow you to render widgets without previously knowing the names for them.
The autodiscovery process will add them to the registry and you can the look them up by block name.
Priorities can also be assigned to render them in order.
- First define a block on the widget:
```
from widgeter.base import Widget
class HelloWorld(Widget):
block = 'home'
priority = '1'
template = 'hello_world/widget.html'
def get_context(self, context, options=None):
return { 'message': u'Hello World!' }
```
- Then, on the template, use the `widget_block` tag:
```
{% load widgeter %}
{% widget_block "home" current_user %}
```
Running the Tests
------------------------------------
You can run the tests with via::
python setup.py test
or::
python runtests.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-widgeter-0.1.tar.gz
(4.2 kB
view details)
File details
Details for the file django-widgeter-0.1.tar.gz
.
File metadata
- Download URL: django-widgeter-0.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 607ebe7b5adccd7f18f2b560bf1d1340b78324a3ad879817649b13a793258ac8 |
|
MD5 | d549f52f302c7a76325836a445e393c0 |
|
BLAKE2b-256 | a806d1cceb86d5292a9ef70a28d68e5d864fe5062e6939ac1c070cfd33a216ba |