@register.tag
def ifinstalled(parser, token):
 try:
  (tag, app) = token.split_contents()
 except ValueError:
  raise TemplateSyntaxError(u'ifinstalled should be in the form: {% ifinstalled app_name %}{% endifinstalled %}')
 end_tag = (u'end' + tag)
 unmatched_end_tag = 1
 if (app.strip(u'"\'') not in settings.INSTALLED_APPS):
  while unmatched_end_tag:
   token = parser.tokens.pop(0)
   if (token.token_type == TOKEN_BLOCK):
    block_name = token.contents.split()[0]
    if (block_name == tag):
     unmatched_end_tag += 1
    if (block_name == end_tag):
     unmatched_end_tag -= 1
  parser.tokens.insert(0, token)
 nodelist = parser.parse((end_tag,))
 parser.delete_first_token()
 class IfInstalledNode(Node, ):
  def render(self, context):
   return nodelist.render(context)
 return IfInstalledNode()

@ register . tag def ifinstalled ( parser , token ) : try : ( tag , app ) = token . split_contents ( ) except ValueError : raise TemplateSyntaxError ( u'ifinstalled should be in the form: {% ifinstalled app_name %}{% endifinstalled %}' ) end_tag = ( u'end' + tag ) unmatched_end_tag = 1 if ( app . strip ( u'"\'' ) not in settings . INSTALLED_APPS ) : while unmatched_end_tag : token = parser . tokens . pop ( 0 ) if ( token . token_type == TOKEN_BLOCK ) : block_name = token . contents . split ( ) [ 0 ] if ( block_name == tag ) : unmatched_end_tag += 1 if ( block_name == end_tag ) : unmatched_end_tag -= 1 parser . tokens . insert ( 0 , token ) nodelist = parser . parse ( ( end_tag , ) ) parser . delete_first_token ( ) class IfInstalledNode ( Node , ) : def render ( self , context ) : return nodelist . render ( context ) return IfInstalledNode ( )
old-style if tag that renders contents if the given app is installed .