<s> """<STR_LIT>""" <EOL> from django import template <EOL> from django . template . loader import render_to_string <EOL> import floppyforms . __future__ as forms <EOL> register = template . Library ( ) <EOL> @ register . filter <EOL> def placeholder ( boundfield , value ) : <EOL> """<STR_LIT>""" <EOL> boundfield . field . widget . attrs [ "<STR_LIT>" ] = value <EOL> return boundfield <EOL> @ register . filter <EOL> def label ( boundfield , contents = None ) : <EOL> """<STR_LIT>""" <EOL> label_text = contents or boundfield . label <EOL> id_ = boundfield . field . widget . attrs . get ( '<STR_LIT:id>' ) or boundfield . auto_id <EOL> return render_to_string ( <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : label_text , <EOL> "<STR_LIT:id>" : id_ , <EOL> "<STR_LIT>" : boundfield , <EOL> } ) <EOL> @ register . filter <EOL> def label_text ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> return boundfield . label <EOL> @ register . filter <EOL> def value_text ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> val = boundfield . value ( ) <EOL> if isinstance ( val , list ) : <EOL> return '<STR_LIT>' <EOL> choices = getattr ( boundfield . field , "<STR_LIT>" , [ ] ) <EOL> return unicode ( dict ( choices ) . get ( val , val ) ) <EOL> @ register . filter <EOL> def values_text ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> val = boundfield . value ( ) <EOL> choice_dict = dict ( getattr ( boundfield . field , "<STR_LIT>" , [ ] ) ) <EOL> if val : <EOL> return [ unicode ( choice_dict . get ( v , v ) ) for v in val ] <EOL> else : <EOL> return [ ] <EOL> @ register . filter <EOL> def classes ( boundfield , classes ) : <EOL> """<STR_LIT>""" <EOL> attrs = boundfield . field . widget . attrs <EOL> attrs [ "<STR_LIT:class>" ] = "<STR_LIT:U+0020>" . join ( <EOL> [ c for c in [ attrs . get ( "<STR_LIT:class>" , None ) , classes ] if c ] ) <EOL> return boundfield <EOL> @ register . filter <EOL> def optional ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> return not boundfield . field . required <EOL> @ register . filter <EOL> def attr ( boundfield , attrval ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> attr , val = attrval . split ( "<STR_LIT::>" , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> attr , val = attrval , True <EOL> boundfield . field . widget . attrs [ attr ] = val <EOL> return boundfield <EOL> @ register . filter <EOL> def is_checkbox ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( <EOL> boundfield . field . widget , forms . CheckboxInput ) <EOL> @ register . filter <EOL> def is_readonly ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( boundfield . field , "<STR_LIT>" , False ) <EOL> @ register . filter <EOL> def is_multiple ( boundfield ) : <EOL> """<STR_LIT>""" <EOL> return isinstance ( boundfield . field . widget , forms . SelectMultiple ) </s>
