django-flatblocks

django-flatblocks acts like django.contrib.flatpages but for parts of a page; like an editable help box you want show alongside the main content.
Download

django-flatblocks Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Horst Gutmann
  • Publisher web site:
  • http://github.com/zerok/

django-flatblocks Tags


django-flatblocks Description

django-flatblocks acts like django.contrib.flatpages but for parts of a page; like an editable help box you want show alongside the main content. django-flatblocks is a simple Django 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 %}edit-viewWith 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 editfrom django.contrib.auth.decorators import login_required# ...urlpatterns = pattern('', url(r'^flatblocks/(?Pd+)/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:template_name Name of the template to be used for rendering this view. By default flatblocks/edit.html is used.success_url After successfully editing a flatblock the view will redirect the user to the URL specified here. By default the view will try to determine the last visited page before entering the edit-view (which is normally a page where the flatblock is used) and redirect the user back there.modelform_class If you want to use a customized ModelForm class for flatblocks you can specify it here.permission_check 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. Requirements: · Python · Django What's New in This Release: · All settings are now in the flatblocks.settings module


django-flatblocks Related Software