<s> from django import template <EOL> try : <EOL> import simplejson as json <EOL> except ImportError , e : <EOL> import json <EOL> import datetime <EOL> from knockout_modeler . ko import ko , ko_data , ko_model , ko_bindings , get_fields <EOL> register = template . Library ( ) <EOL> def knockout ( values ) : <EOL> """<STR_LIT>""" <EOL> if not values : <EOL> return '<STR_LIT>' <EOL> field_names = get_fields ( values [ <NUM_LIT:0> ] ) <EOL> return ko ( values , field_names ) <EOL> def knockout_data ( values , args = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if not values : <EOL> return '<STR_LIT>' <EOL> name = None <EOL> safe = False <EOL> if args : <EOL> arg_list = [ arg . strip ( ) for arg in args . split ( '<STR_LIT:U+002C>' ) ] <EOL> if len ( arg_list ) > <NUM_LIT:1> : <EOL> safe = True <EOL> else : <EOL> safe = False <EOL> name = arg_list [ <NUM_LIT:0> ] <EOL> field_names = get_fields ( values [ <NUM_LIT:0> ] ) <EOL> return ko_data ( values , field_names , name , safe ) <EOL> def knockout_model ( values ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if not values : <EOL> return '<STR_LIT>' <EOL> field_names = get_fields ( values [ <NUM_LIT:0> ] ) <EOL> modelClass = values [ <NUM_LIT:0> ] . __class__ <EOL> return ko_model ( modelClass , field_names ) <EOL> def knockout_bindings ( values ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if not values : <EOL> return '<STR_LIT>' <EOL> return ko_bindings ( values [ <NUM_LIT:0> ] ) <EOL> register . filter ( knockout ) <EOL> register . filter ( knockout_data ) <EOL> register . filter ( knockout_model ) <EOL> register . filter ( knockout_bindings ) </s>
