* ``FORM_DESIGNER_DEFAULT_FORM_TEMPLATE`` or ``FORM_TEMPLATES`` to control the form output (e.g. render it with ``django-uni-form``). * ``FORM_DESIGNER_FIELD_CLASSES`` to define which field types are allowed. * ``FORM_DESIGNER_WIDGET_CLASSES`` to define which widgets are allowed. """ from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.formdesignerlink.models import FormDesignerLink from form_designer import settings as form_designer_settings from form_designer.views import process_form class FormDesignerLinkPlugin(ContentPlugin): model = FormDesignerLink category = _('Interactivity') cache_output = False def get_render_template(self, request, instance, **kwargs): return instance.form_definition.form_template_name or self.render_template or form_designer_settings.DEFAULT_FORM_TEMPLATE def get_context(self, request, instance, **kwargs): context = {} # The process_form() function is designed with Django CMS in mind, # and responds to both the GET and POST request. return process_form(request, instance.form_definition, context, is_cms_plugin=True) plugin_pool.register(FormDesignerLinkPlugin)
def render(self, request, instance, **kwargs): try: html = backend.render_text(instance.text, instance.language) except Exception, e: html = self.render_error(e) # Included in a DIV, so the next item will be displayed below. return mark_safe('<div class="markup">' + html + '</div>\n') # Dynamically create plugins for every language type. # Allows adding them separately in the admin, while using the same database table. for language, model in LANGUAGE_MODEL_CLASSES.iteritems(): if language not in appsettings.FLUENT_MARKUP_LANGUAGES: continue form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm, ), { 'default_language': language, }) classname = "{0}MarkupPlugin".format(language.capitalize()) PluginClass = type(classname, (MarkupPluginBase, ), { 'model': model, 'form': form, }) #globals()[classname] = PluginClass plugin_pool.register(PluginClass)
""" Plugin for rendering Gist snippets, hosted by Github. """ from django.utils.http import urlquote from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.gist.models import GistItem class GistPlugin(ContentPlugin): model = GistItem category = _('Programming') def render(self, request, instance, **kwargs): url = u'http://gist.github.com/{0}.js'.format(instance.gist_id) if instance.filename: url += u'?file={0}'.format(urlquote(instance.filename)) return mark_safe(u'<script src="{0}"></script>'.format(url)) plugin_pool.register(GistPlugin)
from article.models import ArticleTextItem from fluent_contents.extensions import ContentPlugin, plugin_pool class ArticleTextPlugin(ContentPlugin): name = "Text item" category = "Content plugins" model = ArticleTextItem render_template = "article/plugins/text.html" plugin_pool.register(ArticleTextPlugin)
from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.rawhtml.models import RawHtmlItem class RawHtmlPlugin(ContentPlugin): """ Plugin for rendering raw HTML output. This can be used to insert embed codes in a webpage, for example for Google Docs, YouTube or SlideShare. """ model = RawHtmlItem category = _('Advanced') admin_form_template = ContentPlugin.ADMIN_TEMPLATE_WITHOUT_LABELS class Media: css = {'screen': ('fluent_contents/plugins/rawhtml/rawhtml_admin.css',)} def render(self, request, instance, **kwargs): return instance.html plugin_pool.register(RawHtmlPlugin)
from django.conf import settings from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.disquswidgets.models import DisqusCommentsAreaItem class DisqusCommentsPlugin(ContentPlugin): model = DisqusCommentsAreaItem category = _("Interactivity") render_template = "fluent_contents/plugins/disquswidgets/comments.html" def get_context(self, request, instance, **kwargs): parent_url = instance.parent.get_absolute_url() return { "instance": instance, "DISQUS_WEBSITE_SHORTNAME": settings.DISQUS_WEBSITE_SHORTNAME, # for convenience, pass setting # Template config setters are hard to use, provide context here! "disqus_identifier": parent_url.strip("/"), # URL is expected to be relative. "disqus_url": parent_url, "disqus_developer": 0, # disqus_title } plugin_pool.register(DisqusCommentsPlugin)
""" Definition of the plugin. """ from django.utils.safestring import mark_safe from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.text.models import TextItem class TextPlugin(ContentPlugin): model = TextItem admin_init_template = "admin/fluent_contents/plugins/text/admin_init.html" admin_form_template = ContentPlugin.ADMIN_TEMPLATE_WITHOUT_LABELS class Media: js = ('fluent_contents/plugins/text/text_admin.js',) css = {'screen': ('fluent_contents/plugins/text/text_admin.css',)} def render(self, request, instance, **kwargs): # Included in a DIV, so the next item will be displayed below. return mark_safe('<div class="text">' + instance.text + '</div>\n') plugin_pool.register(TextPlugin)
def render(self, request, instance, **kwargs): try: html = backend.render_text(instance.text, instance.language) except Exception as e: html = self.render_error(e) # Included in a DIV, so the next item will be displayed below. return mark_safe('<div class="markup">' + html + '</div>\n') # Dynamically create plugins for every language type. # Allows adding them separately in the admin, while using the same database table. for language, model in LANGUAGE_MODEL_CLASSES.items(): if language not in appsettings.FLUENT_MARKUP_LANGUAGES: continue form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm,), { 'default_language': language, }) classname = "{0}MarkupPlugin".format(language.capitalize()) PluginClass = type(classname, (MarkupPluginBase,), { 'model': model, 'form': form, }) #globals()[classname] = PluginClass plugin_pool.register(PluginClass)
""" Definition of the plugin. """ from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.code.models import CodeItem from fluent_contents.plugins.code import appsettings, backend class CodePlugin(ContentPlugin): model = CodeItem category = _('Programming') admin_form_template = "admin/fluent_contents/plugins/code/admin_form.html" class Media: css = {'screen': ('fluent_contents/code/code_admin.css',)} def render(self, request, instance, **kwargs): # Style is not stored in the model, # it needs to be a side-wide setting (maybe even in the theme) return backend.render_code(instance, style_name=appsettings.FLUENT_CODE_STYLE) plugin_pool.register(CodePlugin)
return mark_safe('<div class="markup">' + html + "</div>\n") def _create_markup_plugin(language, model): """ Create a new MarkupPlugin class that represents the plugin type. """ form = type( "{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm, ), {"default_language": language}, ) classname = "{0}MarkupPlugin".format(language.capitalize()) PluginClass = type(classname, (MarkupPluginBase, ), { "model": model, "form": form }) return PluginClass # Dynamically create plugins for every language type. # Allows adding them separately in the admin, while using the same database table. for language, model in LANGUAGE_MODEL_CLASSES.items(): if language not in appsettings.FLUENT_MARKUP_LANGUAGES: continue # globals()[classname] = PluginClass plugin_pool.register(_create_markup_plugin(language, model))
""" Plugin to add an ``<iframe>`` to the page. """ from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.iframe.models import IframeItem class IframePlugin(ContentPlugin): model = IframeItem category = _('Advanced') def render(self, request, instance, **kwargs): return mark_safe(u'<iframe class="iframe" src="{src}" width="{width}" height="{height}"></iframe>'.format( src=escape(instance.src), width=instance.width, height=instance.height )) plugin_pool.register(IframePlugin)
# Included in a DIV, so the next item will be displayed below. return mark_safe('<div class="markup">' + html + '</div>\n') def _create_markup_plugin(language, model): """ Create a new MarkupPlugin class that represents the plugin type. """ form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm,), { 'default_language': language, }) classname = "{0}MarkupPlugin".format(language.capitalize()) PluginClass = type(classname, (MarkupPluginBase,), { 'model': model, 'form': form, }) return PluginClass # Dynamically create plugins for every language type. # Allows adding them separately in the admin, while using the same database table. for language, model in LANGUAGE_MODEL_CLASSES.items(): if language not in appsettings.FLUENT_MARKUP_LANGUAGES: continue #globals()[classname] = PluginClass plugin_pool.register(_create_markup_plugin(language, model))
from django.utils.html import escape from django.utils.http import urlquote from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.googledocsviewer.models import GoogleDocsViewerItem class GoogleDocsViewerPlugin(ContentPlugin): """ Plugin to add a Google Docs viewer to the page. This can be used to display a PDF file inline. Note then when using the Google Docs viewer on your site, Google assumes you agree with the Terms of Service, see: https://docs.google.com/viewer/TOS """ model = GoogleDocsViewerItem category = _('Online services') def render(self, request, instance, **kwargs): url = 'http://docs.google.com/viewer?url={url}&embedded=true'.format(url=urlquote(instance.url, '')) return u'<iframe class="googledocsviewer" src="{src}" width="{width}" height="{height}"></iframe>'.format( src=escape(url), width=instance.width, height=instance.height ) plugin_pool.register(GoogleDocsViewerPlugin)
""" Comments area plugin. This plugin package is not called "comments" as that conflicts with the `django.contrib.comments` appname. Hence, "commentsarea" it is. The plugin displays the form and messagelist that ``django.contrib.comments`` renders. Hence, it depends on a properly configured contrib module. The least you need to do, is: * providing a ``comments/base.html`` template. * include a ``title`` block that is displayed in the ``<head>`` of the base template. * include a ``content`` block that is displayed in the ``<body>`` of the base template. * provide a ``comments/posted.html`` template for the success page. * It could contains links to the blog page. * It could redirect automatically back to the blog in a few seconds. """ from django.utils.translation import ugettext_lazy as _ from fluent_contents.extensions import ContentPlugin, plugin_pool from fluent_contents.plugins.commentsarea.models import CommentsAreaItem class CommentsAreaPlugin(ContentPlugin): model = CommentsAreaItem category = _('Interactivity') render_template = "fluent_contents/plugins/commentsarea/commentsarea.html" plugin_pool.register(CommentsAreaPlugin)