<s> from django . template import Library <EOL> from django . utils . safestring import mark_safe <EOL> from xadmin . util import static , vendor as util_vendor <EOL> register = Library ( ) <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def view_block ( context , block_name , * args , ** kwargs ) : <EOL> if '<STR_LIT>' not in context : <EOL> return "<STR_LIT>" <EOL> admin_view = context [ '<STR_LIT>' ] <EOL> nodes = [ ] <EOL> method_name = '<STR_LIT>' % block_name <EOL> for view in [ admin_view ] + admin_view . plugins : <EOL> if hasattr ( view , method_name ) and callable ( getattr ( view , method_name ) ) : <EOL> block_func = getattr ( view , method_name ) <EOL> result = block_func ( context , nodes , * args , ** kwargs ) <EOL> if result and type ( result ) in ( str , unicode ) : <EOL> nodes . append ( result ) <EOL> if nodes : <EOL> return mark_safe ( '<STR_LIT>' . join ( nodes ) ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ register . filter <EOL> def admin_urlname ( value , arg ) : <EOL> return '<STR_LIT>' % ( value . app_label , value . model_name , arg ) <EOL> static = register . simple_tag ( static ) <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def vendor ( context , * tags ) : <EOL> return util_vendor ( * tags ) . render ( ) </s>
