<s> from itertools import izip_longest <EOL> from django import template <EOL> from django . utils import simplejson <EOL> from django . utils . safestring import mark_safe <EOL> from django . conf import settings <EOL> import posixpath <EOL> from . . charts import Chart , PivotChart <EOL> try : <EOL> CHARTIT_JS_REL_PATH = settings . CHARTIT_JS_REL_PATH <EOL> if CHARTIT_JS_REL_PATH [ <NUM_LIT:0> ] == '<STR_LIT:/>' : <EOL> CHARTIT_JS_REL_PATH = CHARTIT_JS_REL_PATH [ <NUM_LIT:1> : ] <EOL> CHART_LOADER_URL = posixpath . join ( settings . STATIC_URL , <EOL> CHARTIT_JS_REL_PATH , <EOL> '<STR_LIT>' ) <EOL> except AttributeError : <EOL> CHARTIT_JS_REL_PATH = '<STR_LIT>' <EOL> CHART_LOADER_URL = posixpath . join ( settings . STATIC_URL , <EOL> CHARTIT_JS_REL_PATH , <EOL> '<STR_LIT>' ) <EOL> def date_format ( obj ) : <EOL> return obj . isoformat ( ) if hasattr ( obj , '<STR_LIT>' ) else obj <EOL> register = template . Library ( ) <EOL> @ register . filter <EOL> def load_charts ( chart_list = None , render_to = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> embed_script = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if chart_list is not None : <EOL> if isinstance ( chart_list , ( Chart , PivotChart ) ) : <EOL> chart_list = [ chart_list ] <EOL> chart_list = [ c . hcoptions for c in chart_list ] <EOL> render_to_list = [ s . strip ( ) for s in render_to . split ( '<STR_LIT:U+002C>' ) ] <EOL> for hco , render_to in izip_longest ( chart_list , render_to_list ) : <EOL> if render_to : <EOL> hco [ '<STR_LIT>' ] [ '<STR_LIT>' ] = render_to <EOL> embed_script = ( embed_script % ( simplejson . dumps ( chart_list , <EOL> use_decimal = True , <EOL> default = date_format ) , <EOL> CHART_LOADER_URL ) ) <EOL> else : <EOL> embed_script = embed_script % ( ( ) , CHART_LOADER_URL ) <EOL> return mark_safe ( embed_script ) </s>
