Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
195 lines (118 sloc) 5.42 KB

Advanced usage

This document is used to gather more advanced usage examples.

Optional settings

These settings are optional (default values are shown):




FIBER_IMAGES_DIR = 'uploads/images'
FIBER_FILES_DIR = 'uploads/files'

FIBER_EDITOR = 'fiber.editor_definitions.ckeditor.EDITOR'

FIBER_PAGE_MANAGER = 'fiber.managers.PageManager'
FIBER_CONTENT_ITEM_MANAGER = 'fiber.managers.ContentItemManager'


COMPRESS = [the opposite of DEBUG]

API_RENDER_HTML = False  # If set to True, you must include 'djangorestframework' in INSTALLED_APPS as well

Set or override fiber_page in the view

In this example, the news_item_detail view looks up the Page of the news_item_list by looking up its named URL. This way, you can reuse the content you have placed on the news_item_list Page for each news_item_detail Page.

def news_item_detail(request, news_item_slug):
    news_item = get_object_or_404(NewsItem, slug=news_item_slug)

    fiber_page = Page.objects.get(url__exact='"news_item_list"')

    t = loader.get_template('news_item_detail.html')
    c = RequestContext(request, {
        'fiber_page': fiber_page,
        'news_item': news_item
    return HttpResponse(t.render(c))

Set or override fiber_page in the classed based view

In this example, the NewsItemDetailView's context is enriched with fiber_page and fiber_current_pages.

from django.core.urlresolvers import reverse
from django.views.generic import DetailView
from fiber.views import FiberPageMixin

class NewsItemDetailView(FiberPageMixin, DetailView):

    def get_fiber_page_url(self):
        return reverse('news_item_list')


In this example 4 page-templates will be available in the front- and backend-admin:

    ('', 'Default template'),
    ('tpl-home.html', 'Home template'),
    ('tpl-intro.html', 'Intro template'),
    ('tpl-with-sidebar.html', 'With sidebar template'),

The first choice '' will load the FIBER_DEFAULT_TEMPLATE, default this is 'base.html'

In this example 2 content-templates will be available in the front- and backend-admin:

    ('', 'Default template'),
    ('special-content-template.html', 'Special template'),

The first choice '' will load the default content-template, this is 'fiber/content_item.html'


In this example metadata (key-value pairs) for pages will be available in the backend-admin:

    'title': {
        'widget': 'select',
        'values': ['option1', 'option2', 'option3',],
    'bgcolor': {
        'widget': 'combobox',
        'values': ['#ffffff', '#fff000', '#ff00cc'],
        'prefill_from_db': True,
    'description': {
        'widget': 'textarea',

The first key key is 'title'. Because it has widget 'select' you will have 3 fixed values to choose from.

The second key is 'bgcolor'. Because it has widget 'combobox' you will have 3 fixed values to choose from and the choice to add your own 'bgcolor'. By setting prefill_from_db to True, the custom values you have chosen will also appear in the selectbox of fixed values.

The third key is 'description'. Because it has widget 'textarea' you can enter the value in a big textarea field.

Available widgets are:
select combobox textarea textfield (default widget)

Only the combobox can prefill from the database by setting prefill_from_db = True (default=False)

The same metadata schema is available for metadata for content:


CKEditor config settings

Some default CKEditor config settings can be altered by creating a file called admin-extra.js, which should be placed in a folder structure like this:


Make sure 'appname' is placed _before_ 'fiber' in settings.INSTALLED_APPS, otherwise the admin-extra.js file won't override the default admin-extra.js provided by Django Fiber.

Something like this should be placed in admin-extra.js:

window.CKEDITOR_CONFIG_FORMAT_TAGS = 'p;h1;h2;h3;h4';
    { name: 'intro paragraph', element: 'p', attributes: { 'class': 'intro' } }

You can also override the entire CKEditor toolbar, by setting the variable:


To see how this works, check the fiber.ckeditor.js file in the Django Fiber source:

Custom permissions

Fiber provides a :mod:`fiber.permissions` module. The Permission class defined here can be overridden by writing a custom permission class and pointing PERMISSION_CLASS in your settings module to that class.

Here's an example module that implements object level permissions:

Jump to Line
Something went wrong with that request. Please try again.