Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

templatetag cleanup

  • Loading branch information...
commit fb94bd62bccd30a180287927f1b9229a950e5164 1 parent 7fd3a8a
@stefanfoulis stefanfoulis authored
Showing with 13 additions and 12 deletions.
  1. +13 −12 stacks/templatetags/stack_tags.py
View
25 stacks/templatetags/stack_tags.py
@@ -3,7 +3,10 @@
from django import template
from django.utils import translation
from django.utils.safestring import mark_safe
+from cms.plugin_rendering import render_plugins
+from cms.plugins.utils import get_plugins
from stacks import models as stack_models
+from stacks.models import Stack
register = template.Library()
@@ -11,30 +14,28 @@ class StackNode(Tag):
name = 'stack'
options = Options(
Argument('code', required=True),
- KeywordArgument('language', required=False, default=None, ),
'as',
Argument('varname', required=False, resolve=False)
)
- def render_tag(self, context, code, language, varname):
+ def render_tag(self, context, code, varname):
if not code:
# an empty string was passed in or the variable is not available in the context
return ''
- current_language = translation.get_language()
- language = language or current_language
- if not language == current_language:
- translation.activate(language)
-
# TODO: caching?
- stack, created = stack_models.Stack.objects.get_or_create(code=code, defaults={'name': code})
+ if isinstance(code, Stack):
+ stack = code
+ else:
+ stack, __ = stack_models.Stack.objects.get_or_create(code=code, defaults={'name': code})
+ # TODO: once we drop 2.3.x support we can just use the "render_plugin" templatetag
+ # instead of rendering html here.
placeholder = stack.content
- rendered_placeholder = mark_safe(placeholder.render(context, None))
+ plugins = get_plugins(context['request'], placeholder)
+ processors = ()
+ rendered_placeholder = mark_safe("".join(render_plugins(plugins, context, placeholder, processors)))
if varname:
context[varname] = rendered_placeholder
rendered_placeholder = u''
-
- if not language == current_language:
- translation.activate(current_language)
return rendered_placeholder
register.tag(StackNode)
Please sign in to comment.
Something went wrong with that request. Please try again.