zerok / django-flatblocks forked from howiworkdaily/django-freetext
- Source
- Commits
- Network (3)
- Issues (0)
- Downloads (6)
- Wiki (1)
- Graphs
-
Tree:
588d49c
tree 016caf75d44e8fb06403d036c3d20e2cf807d222
parent 220abb6c2d6f9afe04285802d7a0959ea5969576
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Thu Jan 22 16:47:44 -0800 2009 | |
| |
AUTHORS.txt | Wed Apr 29 10:00:48 -0700 2009 | |
| |
LICENSE.txt | Thu Jan 29 12:43:54 -0800 2009 | |
| |
MANIFEST.in | Tue Jan 20 08:25:03 -0800 2009 | |
| |
README.rst | Sun Jun 21 12:10:44 -0700 2009 | |
| |
bootstrap.py | Wed Apr 29 06:42:59 -0700 2009 | |
| |
buildout.cfg | ||
| |
ez_setup.py | Fri Jan 30 13:32:03 -0800 2009 | |
| |
flatblocks/ | ||
| |
setup.py | ||
| |
test_project/ | Wed Apr 29 06:42:59 -0700 2009 |
django-flatblocks
django-flatblocks is a simple application for handling small text-blocks on websites. Think about it like django.contrib.flatpages just not for a whole page but for only parts of it, like an information text describing what you can do on a site.
Usage
Once you've created some instances of the flatblocks.models.FlatBlock model, you can load it it using the flatblock_tags templatetag-library:
{% load flatblock_tags %}
<html>
<head>
<!-- ... -->
</head>
<body>
<div id="page">
<div id="main">
<!-- ... -->
</div>
<div id="sidebar">
{% flatblock "page.info" %}
</div>
</div>
</body>
</html>
This way you can display a text block with the name 'page.info'. If you have the name of a block in a template variable, leave out the quotes.
This tag also accepts an optional argument where you can specify the number of seconds, the that block should be cached:
{% flatblock "page.info" 3600 %}
Additionally you can also specify which template should be used to render the flatblock:
{% flatblock "page.info" using "my_template.html" %}
# ...
{% flatblock "page.about" 3600 using "my_template.html" %}
As with the slug of the flatblock also with the template name you have the choice of using the literal name of the template or pass it to the templatetag as a variable.
edit-view
With flatblocks.views.edit django-flatblocks offers a simple view to edit your flatblocks from your frontend. To use it simply include it in your URLconf and create a flatblocks/edit.html template.
By default the view doesn't do any permission checking, so you should decorate it accordingly in your URLconf:
from flatblocks.views import edit
from django.contrib.auth.decorators import login_required
# ...
urlpatterns = pattern('',
url(r'^flatblocks/(?P<pk>\d+)/edit/$', login_required(edit),
name='flatblocks-edit'),
# ...
)
The template can operate on following variables:
- form
- flatblock
- origin (the URL of the previous page)
Additionally the view offers some basic customization hooks via these keyword arguments:
This argument lets you specify a callback function to do some flatblock-specific permission checking. Such a function could look like this:
def my_permcheck(request, flatblock):
if request.user.is_staff or flatblock.slug == 'free_for_all':
return True
return HttpResponseRedirect('/')
With this permission callback set, a user that is not a staff-user is not allowed to edit this view unless it's the "free_for_all" block. If these criteria are not met, the user is redirected to the root URL of the page.
The contract here is pretty simple. The permission callback should return False, if the user should receive a 403 message when trying to edit this link. If the function returns an instance of HttpResponse the view will proceed from the assumption that your view already did everything there is to do and return that response-object. Any other return value tells the view that the permissions are OK for the current user and that it should proceed.
History
Since this application targets use-cases that are basically applicable to most web-projects out there, there are tons of solutions similar to this one. In fact, this app is a fork originally from django-chunks developed by Clint Ecker.
In November 2008 Kevin Fricovsky created the original fork in order to add an additional "active"-flag to each chunk. That project was later on forked by Peter Baumgardner who removed that flag again and added a "header"-field in order to directly associate and optional title with each text block.
This fork aims now to add more features like variable chunks and also integrate some of the features developed by H. Waara and S. Cranford in the django-better-chunks fork (django.contrib.site- and i18n-support).
Releases
- All settings are now in the flatblocks.settings module
- Fixes a bug with FlatBlock.save() failing to reset the cache
- Buildout integration for easier testing
- Example urls.py and flatblocks/edit.html-template
- createflatblock and deleteflatblock commands
- On saving a flatblock its cache will be cleared
- As last argument of the template tag you can now also specify a template name.
- Translatable
- flatblocks.views.edit view for editing flatblocks

