Skip to content

Instantly share code, notes, and snippets.

@acdha
Created November 10, 2009 22:55
Show Gist options
  • Save acdha/231350 to your computer and use it in GitHub Desktop.
Save acdha/231350 to your computer and use it in GitHub Desktop.
Example of the new richer ApplicationContent type for FeinCMS - see http://github.com/acdha/feincms/tree/rich_appcontent
"""
Support for embedding blogs as FeinCMS ApplicationContent
"""
from django import forms
from .models import Blog
from .views import blog_detail
def get_admin_fields(form, *args, **kwargs):
"""Get form fields when using missions as FeinCMS ApplicationContent
Return a dict containing names and Django Field instances
"""
return {
'exclusive_subpages': forms.BooleanField(
label = "Exclusive Subpages",
required = False,
initial = form.instance.parameters.get("exclusive_subpages", False),
help_text = "Exclude everything other than application's content when rendering application subpages",
),
'blog_slug': forms.ChoiceField(
label = "Blog",
required = True,
initial = form.instance.parameters.get("blog_slug", False),
choices = Blog.published.values_list("slug", "title"),
help_text = "Select the blog to embed here",
)
}
def view_wrapper(request, view=None, appcontent_parameters=None, *args, **kwargs):
if not callable(view):
raise TypeError("view must be the callable original view!")
assert appcontent_parameters is not None
kwargs['blog_slug'] = appcontent_parameters["blog_slug"]
if not "slug" in kwargs:
view = blog_detail
# We're choosing to override this here so we can have a master /blogs with
# separate templates:
kwargs['template_name'] = "content/blog/%s.html" % view.__name__
return view(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment