summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2016-06-13 19:19:36 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2016-06-13 20:06:47 (GMT)
commitf98e87fcbca60c51d274c3b6d029f8204f092c05 (patch)
tree1d3b0ed12fdc0f53af06613928a76c3ac45250b9
parent861d7a6004aa38ab7ecaa5fbb72d09b0065a8282 (diff)
downloadcmsplugin-blurp-f98e87fcbca60c51d274c3b6d029f8204f092c05.zip
cmsplugin-blurp-f98e87fcbca60c51d274c3b6d029f8204f092c05.tar.gz
cmsplugin-blurp-f98e87fcbca60c51d274c3b6d029f8204f092c05.tar.bz2
Restore blurp_tags (fixes #11323)v1.15
-rw-r--r--src/cmsplugin_blurp/templatetags/__init__.py0
-rw-r--r--src/cmsplugin_blurp/templatetags/blurp_tags.py68
2 files changed, 68 insertions, 0 deletions
diff --git a/src/cmsplugin_blurp/templatetags/__init__.py b/src/cmsplugin_blurp/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/cmsplugin_blurp/templatetags/__init__.py
diff --git a/src/cmsplugin_blurp/templatetags/blurp_tags.py b/src/cmsplugin_blurp/templatetags/blurp_tags.py
new file mode 100644
index 0000000..78789b6
--- /dev/null
+++ b/src/cmsplugin_blurp/templatetags/blurp_tags.py
@@ -0,0 +1,68 @@
+import logging
+import json
+
+from django import template
+from django.conf import settings
+from django.utils.html import escape
+from django.core.serializers import serialize
+from django.core.serializers.json import DjangoJSONEncoder
+from django.db.models.query import QuerySet
+from django.utils.safestring import mark_safe
+
+from classytags.arguments import Argument
+from classytags.core import Options, Tag
+
+from .. import utils
+
+register = template.Library()
+
+# originally copied from django-jsonify(https://bitbucket.org/marltu/django-jsonify/)
+# released under a three-clause BSD License by Marius Grigaitis
+@register.filter
+def jsonify(obj):
+ if isinstance(obj, QuerySet):
+ return mark_safe(serialize('json', obj))
+ return mark_safe(json.dumps(obj, cls=DjangoJSONEncoder))
+
+@register.tag
+class RenderBlurp(Tag):
+ name = 'render_blurp'
+ options = Options(
+ Argument('name', resolve=False),
+ )
+
+
+ def render_tag(self, context, name):
+ renderer = utils.resolve_renderer(name)
+ if not renderer:
+ return ''
+ template = renderer.render_template()
+ context = renderer.render(context)
+ try:
+ if not hasattr(template, 'render'):
+ template = template.Template(template)
+ return template.render(context)
+ except Exception, e:
+ logging.getLogger(__name__).exception('error while rendering %s',
+ renderer)
+ msg = ''
+ if settings.TEMPLATE_DEBUG:
+ msg += 'error while rendering %s: %s' % (renderer, e)
+ msg = '<pre>%s</pre>' % escape(msg)
+ return msg
+
+
+@register.tag
+class BlurpNode(Tag):
+ '''Insert content generated from a blurp block and render inside template'''
+ name = 'blurp'
+ options = Options(
+ Argument('name'),
+ blocks=[('endblurp', 'nodelist')])
+
+ def render_tag(self, context, name, nodelist):
+ context.push()
+ utils.insert_blurp_in_context(name, context)
+ output = self.nodelist.render(context)
+ context.pop()
+ return output