<s> from django import template <EOL> from django . core . paginator import Paginator <EOL> from django . http import Http404 <EOL> from django . utils . http import urlencode <EOL> register = template . Library ( ) <EOL> @ register . assignment_tag ( takes_context = True ) <EOL> def paginate ( context , items ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> num = int ( context [ '<STR_LIT>' ] . GET [ '<STR_LIT>' ] ) if '<STR_LIT>' in context [ '<STR_LIT>' ] . GET else <NUM_LIT:1> <EOL> return Paginator ( items , <NUM_LIT:12> ) . page ( num ) <EOL> except : <EOL> raise Http404 <EOL> @ register . simple_tag ( takes_context = True ) <EOL> def modify_query_string ( context , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> qs = dict ( [ ( k , v ) for k , v in context [ '<STR_LIT>' ] . GET . items ( ) ] ) <EOL> qs . update ( kwargs ) <EOL> if '<STR_LIT>' in qs and qs [ '<STR_LIT>' ] == <NUM_LIT:1> : <EOL> del qs [ '<STR_LIT>' ] <EOL> return '<STR_LIT>' % ( <EOL> context [ '<STR_LIT>' ] . path , <EOL> '<STR_LIT:?>' if qs else '<STR_LIT>' , <EOL> urlencode ( qs ) , <EOL> ) </s>
