Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support to define container in context variables

Fixed Issue #2
  • Loading branch information...
commit eb9f0e90754e411a986e56cfea3def7ad2e50efc 1 parent 40fd54b
@rhblind authored
Showing with 9 additions and 4 deletions.
  1. +9 −4 gcharts/templatetags/gcharts.py
View
13 gcharts/templatetags/gcharts.py
@@ -8,7 +8,7 @@
from django.conf import settings
from django import template
from django.template.loader import render_to_string
-from django.template.base import TemplateSyntaxError
+from django.template.base import TemplateSyntaxError, VariableDoesNotExist
from django.core.exceptions import ImproperlyConfigured
register = template.Library()
@@ -87,7 +87,7 @@ def options(parser, token):
# {% render "container_id" "data" "options" %}
class RenderNode(template.Node):
def __init__(self, container, data, options, pkg):
- self.container = container
+ self.container = template.Variable(container)
self.data = template.Variable(data)
self.options = options
self.pkg = pkg
@@ -109,8 +109,13 @@ def render(self, context):
else:
raise TemplateSyntaxError("%s is not a valid package. Valid packages are %s" \
% (self.pkg, ", ".join(GOOGLECHARTS_PACKAGES)))
-
- return self.render.__doc__ % {"options": self.options, "container": self.container,
+ try:
+ # Try to resolve the container from context variables.
+ # Useful if creating charts in a loop, etc.
+ container = self.container.resolve(context)
+ except VariableDoesNotExist:
+ container = self.container
+ return self.render.__doc__ % {"options": self.options, "container": container,
"src": self.data.var, "data": self.data.resolve(context)}
Please sign in to comment.
Something went wrong with that request. Please try again.