Commits

Mikhail Korobov  committed 04b70a4

Fix parsing of copy-pasted charts

  • Participants
  • Parent commits bab7952

Comments (0)

Files changed (1)

File chart_tools/templatetags/chart_tags.py

 from django import template
 from django.template import TemplateSyntaxError
 register = template.Library()
+API_URL = 'http://chart.apis.google.com/chart'
 
-API_URL = 'http://chart.apis.google.com/chart'
 
 @register.inclusion_tag('chart_tools/bar_chart.html')
 def bar_chart(values, captions, size='580x100', max_value=None):
 
     def render(self, context):
         input = self.nodelist.render(context)
-        return _prepare_chart(input, self.attr)
+        return prepare_chart(input, self.attr)
 
-def _prepare_chart(input, attr):
+def prepare_chart(input, attr=''):
     # remove whitespaces
     input_lines = input.replace(' ', '').splitlines()
 
     # build url
     lines = []
-    for line in filter(None, input_lines):
+
+    def clean_lines(line):
+        if line.startswith(API_URL):
+            return False
+        if not line:
+            return False
+        return True
+
+    for line in filter(clean_lines, input_lines):
+        if line.startswith('&'):
+            line = line[1:]
         if not line.endswith('&'):
             line = line + '&'
         lines.append(line)