<s> from django import template <EOL> from django . conf import settings <EOL> from django . db . models import get_model <EOL> from django . template import defaultfilters , loader <EOL> from . . import library <EOL> from . . import renderers <EOL> from . . dashboard import forms <EOL> ContentType = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> register = template . Library ( ) <EOL> @ register . assignment_tag <EOL> def update_blocks_form ( page , container_name ) : <EOL> container = page . get_container_from_name ( container_name ) <EOL> if not container : <EOL> return None <EOL> return forms . BlockUpdateSelectForm ( container ) <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def render_attribute ( context , attr_name , * args ) : <EOL> """<STR_LIT>""" <EOL> block = context . get ( renderers . BlockRenderer . context_object_name ) <EOL> value = getattr ( block , attr_name ) <EOL> for arg in args : <EOL> flt = getattr ( defaultfilters , arg ) <EOL> if flt : <EOL> value = flt ( value ) <EOL> user = context . get ( '<STR_LIT>' ) . user <EOL> if not user . is_authenticated : <EOL> return unicode ( value ) <EOL> if not user . is_staff : <EOL> return unicode ( value ) <EOL> wrapped_attr = u'<STR_LIT>' <EOL> return wrapped_attr . format ( <EOL> uuid = block . uuid , attr_name = attr_name , value = unicode ( value ) ) <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def get_object_visibility ( context , obj ) : <EOL> try : <EOL> return obj . is_visible <EOL> except AttributeError : <EOL> pass <EOL> return True <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def render_block_form ( context , form ) : <EOL> model = form . _meta . model <EOL> model_name = model . __name__ . lower ( ) <EOL> template_names = [ <EOL> "<STR_LIT>" % ( model . _meta . app_label , model_name ) , <EOL> "<STR_LIT>" % model_name , form . template_name ] <EOL> tmpl = loader . select_template ( template_names ) <EOL> context [ '<STR_LIT>' ] = "<STR_LIT>" % ( <EOL> settings . MEDIA_URL , getattr ( settings , "<STR_LIT>" , '<STR_LIT>' ) ) <EOL> return tmpl . render ( context ) <EOL> @ register . filter <EOL> def depth_as_range ( depth ) : <EOL> return range ( depth - <NUM_LIT:1> ) <EOL> @ register . assignment_tag <EOL> def get_content_type ( obj ) : <EOL> return ContentType . objects . get_for_model ( obj . __class__ ) <EOL> @ register . inclusion_tag ( <EOL> '<STR_LIT>' , takes_context = True ) <EOL> def render_block_selection ( context ) : <EOL> request = context . get ( '<STR_LIT>' ) <EOL> if not request or not request . fp_edit_mode : <EOL> return u'<STR_LIT>' <EOL> grouped_blocks = library . get_grouped_content_blocks ( ) <EOL> return { '<STR_LIT>' : grouped_blocks } </s>
