<s> import re <EOL> from django import template <EOL> from django . db import models <EOL> from django . utils . safestring import mark_safe <EOL> Person = models . get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> register = template . Library ( ) <EOL> class GetPeople ( template . Node ) : <EOL> def __init__ ( self , var_name , limit = None ) : <EOL> self . var_name = var_name <EOL> self . limit = limit <EOL> def render ( self , context ) : <EOL> if self . limit : <EOL> people = Person . objects . select_related ( ) [ : int ( self . limit ) ] <EOL> else : <EOL> people = Person . objects . all ( ) <EOL> context [ self . var_name ] = people <EOL> return '<STR_LIT>' <EOL> @ register . tag <EOL> def get_people ( parser , token ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> tag_name , arg = token . contents . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % token . contents . split ( ) [ <NUM_LIT:0> ] <EOL> m1 = re . search ( r'<STR_LIT>' , arg ) <EOL> m2 = re . search ( r'<STR_LIT>' , arg ) <EOL> if not m1 : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % tag_name <EOL> else : <EOL> var_name = m1 . groups ( ) [ <NUM_LIT:0> ] <EOL> return GetPeople ( var_name ) <EOL> if not m2 : <EOL> raise template . TemplateSyntaxError , "<STR_LIT>" % tag_name <EOL> else : <EOL> format_string , var_name = m2 . groups ( ) <EOL> return GetPeople ( var_name , format_string [ <NUM_LIT:0> ] ) </s>
