#NEWLINE# def do_tags_for_model( parser , token ) : #NEWLINE# #INDENT# '\n    Retrieves a list of ``Tag`` objects associated with a given model\n    and stores them in a context variable.\n\n    Usage::\n\n       {% tags_for_model [model] as [varname] %}\n\n    The model is specified in ``[appname].[modelname]`` format.\n\n    Extended usage::\n\n       {% tags_for_model [model] as [varname] with counts %}\n\n    If specified - by providing extra ``with counts`` arguments - adds\n    a ``count`` attribute to each tag containing the number of\n    instances of the given model which have been tagged with it.\n\n    Examples::\n\n       {% tags_for_model products.Widget as widget_tags %}\n       {% tags_for_model products.Widget as widget_tags with counts %}\n\n    ' #NEWLINE# bits = token . contents . split ( ) #NEWLINE# len_bits = len ( bits ) #NEWLINE# if ( len_bits not in ( 4 , 6 ) ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( _ ( '%s tag requires either three or five arguments' ) % bits [ 0 ] ) ) #NEWLINE# #UNINDENT# if ( bits [ 2 ] != 'as' ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( _ ( "second argument to %s tag must be 'as'" ) % bits [ 0 ] ) ) #NEWLINE# #UNINDENT# if ( len_bits == 6 ) : #NEWLINE# #INDENT# if ( bits [ 4 ] != 'with' ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( _ ( "if given, fourth argument to %s tag must be 'with'" ) % bits [ 0 ] ) ) #NEWLINE# #UNINDENT# if ( bits [ 5 ] != 'counts' ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( ( _ ( "if given, fifth argument to %s tag must be 'counts'" ) % bits [ 0 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len_bits == 4 ) : #NEWLINE# #INDENT# return TagsForModelNode ( bits [ 1 ] , bits [ 3 ] , counts = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return TagsForModelNode ( bits [ 1 ] , bits [ 3 ] , counts = True )