Skip to content

Commit

Permalink
auto add content items
Browse files Browse the repository at this point in the history
  • Loading branch information
pirandig authored and Niels van Dijk committed Oct 10, 2013
1 parent 0acc9ee commit e53eff7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/advanced-usage.rst
Expand Up @@ -32,6 +32,8 @@ These settings are optional (default values are shown):
FIBER_METADATA_PAGE_SCHEMA = {}
FIBER_METADATA_CONTENT_SCHEMA = {}

FIBER_AUTO_CREATE_CONTENT_ITEMS = False

COMPRESS = [the opposite of DEBUG]

API_RENDER_HTML = False # If set to True, you must include 'djangorestframework' in INSTALLED_APPS as well
Expand Down
2 changes: 2 additions & 0 deletions fiber/app_settings.py
Expand Up @@ -20,6 +20,8 @@
PAGE_MANAGER = getattr(settings, 'FIBER_PAGE_MANAGER', 'fiber.managers.PageManager')
CONTENT_ITEM_MANAGER = getattr(settings, 'FIBER_CONTENT_ITEM_MANAGER', 'fiber.managers.ContentItemManager')

AUTO_CREATE_CONTENT_ITEMS = getattr(settings, 'FIBER_AUTO_CREATE_CONTENT_ITEMS', False)

METADATA_PAGE_SCHEMA = getattr(settings, 'FIBER_METADATA_PAGE_SCHEMA', {})
METADATA_CONTENT_SCHEMA = getattr(settings, 'FIBER_METADATA_CONTENT_SCHEMA', {})

Expand Down
6 changes: 4 additions & 2 deletions fiber/templatetags/fiber_tags.py
Expand Up @@ -5,7 +5,7 @@
from fiber import __version__ as fiber_version_number
from fiber.models import Page, ContentItem
from fiber.utils.urls import get_admin_change_url
from fiber.app_settings import PERMISSION_CLASS
from fiber.app_settings import PERMISSION_CLASS, AUTO_CREATE_CONTENT_ITEMS
from fiber.utils import class_loader


Expand Down Expand Up @@ -121,7 +121,9 @@ def show_content(context, content_item_name):
try:
content_item = ContentItem.objects.get(name__exact=content_item_name)
except ContentItem.DoesNotExist:
pass
if AUTO_CREATE_CONTENT_ITEMS:
content_item = ContentItem.objects.create(name=content_item_name)
return show_content(context, content_item_name)

context['content_item'] = content_item

Expand Down

0 comments on commit e53eff7

Please sign in to comment.