<s> from __future__ import absolute_import , unicode_literals <EOL> from django . utils . safestring import mark_safe <EOL> from django_tables2 . utils import Accessor , AttributeDict <EOL> from . base import Column , library <EOL> @ library . register <EOL> class CheckBoxColumn ( Column ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None , checked = None , ** extra ) : <EOL> self . checked = checked <EOL> kwargs = { '<STR_LIT>' : False , '<STR_LIT>' : attrs } <EOL> kwargs . update ( extra ) <EOL> super ( CheckBoxColumn , self ) . __init__ ( ** kwargs ) <EOL> @ property <EOL> def header ( self ) : <EOL> default = { '<STR_LIT:type>' : '<STR_LIT>' } <EOL> general = self . attrs . get ( '<STR_LIT:input>' ) <EOL> specific = self . attrs . get ( '<STR_LIT>' ) <EOL> attrs = AttributeDict ( default , ** ( specific or general or { } ) ) <EOL> return mark_safe ( '<STR_LIT>' % attrs . as_html ( ) ) <EOL> def render ( self , value , bound_column , record ) : <EOL> default = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : bound_column . name , <EOL> '<STR_LIT:value>' : value <EOL> } <EOL> if self . is_checked ( value , record ) : <EOL> default . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> general = self . attrs . get ( '<STR_LIT:input>' ) <EOL> specific = self . attrs . get ( '<STR_LIT>' ) <EOL> attrs = AttributeDict ( default , ** ( specific or general or { } ) ) <EOL> return mark_safe ( '<STR_LIT>' % attrs . as_html ( ) ) <EOL> def is_checked ( self , value , record ) : <EOL> """<STR_LIT>""" <EOL> if self . checked is None : <EOL> return False <EOL> if self . checked is True : <EOL> return True <EOL> if callable ( self . checked ) : <EOL> return bool ( self . checked ( value , record ) ) <EOL> checked = Accessor ( self . checked ) <EOL> if checked in record : <EOL> return bool ( record [ checked ] ) <EOL> return False </s>
