<s> from django . utils . html import escape <EOL> from table . utils import Accessor , AttributesDict <EOL> class Column ( object ) : <EOL> """<STR_LIT>""" <EOL> instance_order = <NUM_LIT:0> <EOL> def __init__ ( self , field = None , header = None , attrs = None , header_attrs = None , <EOL> header_row_order = <NUM_LIT:0> , sortable = True , searchable = True , safe = True , <EOL> visible = True , space = True ) : <EOL> self . field = field <EOL> self . attrs = attrs or { } <EOL> self . sortable = sortable <EOL> self . searchable = searchable <EOL> self . safe = safe <EOL> self . visible = visible <EOL> self . space = space <EOL> self . header = ColumnHeader ( header , header_attrs , header_row_order ) <EOL> self . instance_order = Column . instance_order <EOL> Column . instance_order += <NUM_LIT:1> <EOL> def __str__ ( self ) : <EOL> return self . header . text <EOL> def render ( self , obj ) : <EOL> text = Accessor ( self . field ) . resolve ( obj ) <EOL> return escape ( text ) <EOL> class BoundColumn ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj , column ) : <EOL> self . obj = obj <EOL> self . column = column <EOL> self . base_attrs = column . attrs . copy ( ) <EOL> self . field = column . field <EOL> self . sortable = column . sortable <EOL> self . searchable = column . searchable <EOL> self . safe = column . safe <EOL> self . visible = column . visible <EOL> self . header = column . header <EOL> @ property <EOL> def html ( self ) : <EOL> text = self . column . render ( self . obj ) <EOL> if text is None : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return text <EOL> @ property <EOL> def attrs ( self ) : <EOL> attrs = { } <EOL> for attr_name , attr in self . base_attrs . items ( ) : <EOL> if callable ( attr ) : <EOL> attrs [ attr_name ] = attr ( self . obj , self . field ) <EOL> elif isinstance ( attr , Accessor ) : <EOL> attrs [ attr_name ] = attr . resolve ( self . obj ) <EOL> else : <EOL> attrs [ attr_name ] = attr <EOL> return AttributesDict ( attrs ) . render ( ) <EOL> class ColumnHeader ( object ) : <EOL> def __init__ ( self , text = None , attrs = None , row_order = <NUM_LIT:0> ) : <EOL> self . text = text <EOL> self . base_attrs = attrs or { } <EOL> self . row_order = row_order <EOL> @ property <EOL> def attrs ( self ) : <EOL> return AttributesDict ( self . base_attrs ) . render ( ) </s>
