-
-
Save pije76/3974890 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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