Package: django-flatblocks
django-flatblocks is a simple application for handling small text-blocks on
websites. Think about it likedjango.contrib.flatpagesjust not for a
whole page but for only parts of it, like an information text describing what
you can do on a site.InstallationProbably the easiest way to install this application is to first runpip installdjango-flatblocks.  Once this step is complete add"flatblocks"to yourINSTALLED_APPSsetting in yoursettings.pyfile and runpython manage.py syncdbto update your database.Upgradingdjango-flatblocks usesSouthfor handling data and schema migrations
starting with version 0.6.0, so the South-typical update path applies here.If you’re upgrading from a 0.5.x version or earlier you will have to migrate
in 3 steps:Install south.Migrate your database to the first version of flatblocks using South:./manage.pymigrateflatblocks0001--fakeThen migrate your database to the latest version of flatblocks’ database
and data structure:./manage.pymigrateflatblocksUsageOnce you’ve created some instances of theflatblocks.models.FlatBlockmodel, you can load it it using theflatblockstemplatetag-library:{%loadflatblocks%}<html><head><!-- ... --></head><body><divid="page"><divid="main"><!-- ... --></div><divid="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.Additionally you can also specify which template should be used to render the
flatblock:{%flatblock"page.info"using="my_template.html"%}<!-- -->{%flatblock"page.about"using="my_template.html"%}If you want to simply output the value of thecontentfield of a flatblock
without using any template, you can use either options:{%flatblock"page.info"using=False%}or{%plain_flatblock"page.info"%}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.The content of a flatblock (as well as its header) can also be evaluated as a
full-fledged Django template:{%flatblock"page.info"evaluated=True%}This also works with the other parameters like the custom template and with
theplain_flatblocktemplatetag:{%flatblock"page.info"evaluated=Trueusing="my_template.html"%}<!-- -->{%plain_flatblock"page.about"evaluated=True%}edit-viewWithflatblocks.views.editdjango-flatblocks offers a simple view to edit
your flatblocks from your frontend. To use it simply include it in your
URLconf and create aflatblocks/edit.htmltemplate.By default the view doesn’t do any permission checking, so you should decorate
it accordingly in your URLconf:fromflatblocks.viewsimporteditfromdjango.contrib.auth.decoratorsimportlogin_required# ...urlpatterns=pattern('',url(r'^flatblocks/(?P<pk>\d+)/edit/$',login_required(edit),name='flatblocks-edit'),# ...)The template can operate on following variables:formflatblockorigin(the URL of the previous page)Additionally the view offers some basic customization hooks via these keyword
arguments:template_nameName of the template to be used for rendering this view. By defaultflatblocks/edit.htmlis used.success_urlAfter 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_classIf you want to use a customized ModelForm class for flatblocks you can
specify it here.permission_checkThis argument lets you specify a callback function to do some
flatblock-specific permission checking. Such a function could look like
this:defmy_permcheck(request,flatblock):ifrequest.user.is_stafforflatblock.slug=='free_for_all':returnTruereturnHttpResponseRedirect('/')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 returnFalse, if the user should receive a 403 message when trying to edit
this link. If the function returns an instance ofHttpResponsethe
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.HistorySince 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 fromdjango-chunksdeveloped by
Clint Ecker.In November 2008 Kevin Fricovsky created theoriginal forkin order to add
an additional “active”-flag to each chunk. That project was later onforked
by Peter Baumgardnerwho 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
thedjango-better-chunksfork (django.contrib.site- and i18n-support).Releases1.0.0:Add support for Django 2.2, 3.0, and 3.1.Add support for Python 3.6, 3.7, 3.8 and 3.9.Remove support for Django 1.7, 1.8, 1.9, 1.10, and 1.11.Remove support for Python 3.4 and 3.5.Move CI to GitHub Actions:https://github.com/jazzband/django-flatblocks/actions0.9.4:Drop Python 3.3 support.Add support for Django 1.11.0.9.3:Fixed Django 1.10 compatibility0.9.2:Fixed reading of README in setup.pyDropped Django 1.4 testingTidied code with flake8 and isortFix support for Django 1.7+Fix packaging to exclude tests module0.9.1:Dropped testing of Django 1.5 and 1.6Added migrations [Thanks Sergey Fedoseev]0.9:NOTE: Major tag syntax changes!Modernised to use simple_tag and standard kwarg syntax.Removed caching - use {% cache %} tag instead0.8:Python 3 & Django 1.6 support0.7:Support for evaluated blocks offering access to context variables0.6:South supportInstallation and upgrade instructionsNote: This is primarily a transitional release to get South in here and
open this project up for some database changes in the future.0.5.1Removed rendering of the content attribute from the admin list by Michael FladischerPyBabel compatibility by Michael FladischerFixed caching issue with memcache backend0.5Hungarian translation by Török GáborMethod added to demo edit form (#5) by Bill Evans0.4FlatBlock autocreation by Mikhail Korobov (can be enabled/disabled
with FLATBLOCKS_AUTOCREATE_STATIC_BLOCKS setting)Various fixes by Mikhail KorobovFix by Henrik Heimbuerger for the manifest0.3.5Russian translation by Mikhail Korobov0.3.4Norwegian translation by Eivind Uggedal0.3.3FlatBlock.save should also accept optional kwargs.0.3.2All settings are now in the flatblocks.settings module0.3.1Fixes a bug with FlatBlock.save() failing to reset the cacheBuildout integration for easier testingExample urls.py and flatblocks/edit.html-template0.3createflatblock and deleteflatblock commandsOn saving a flatblock its cache will be clearedAs last argument of the template tag you can now also specify a template
name.0.2Translatableflatblocks.views.editview for editing flatblocks0.1Initial release