<s> from urllib import urlencode <EOL> from urlparse import urlparse , parse_qs , urlunparse <EOL> from django import template <EOL> from django . template . defaultfilters import stringfilter <EOL> register = template . Library ( ) <EOL> def re_qs ( url , key , value ) : <EOL> parsed = urlparse ( url ) <EOL> data = parse_qs ( parsed . query ) <EOL> if value is not None : <EOL> data . update ( { <EOL> key : [ value ] , <EOL> } ) <EOL> else : <EOL> if key in data : <EOL> del data [ key ] <EOL> _data = [ ] <EOL> for key , value in data . iteritems ( ) : <EOL> for item in value : <EOL> _data . append ( ( key , item ) ) <EOL> return urlunparse ( [ parsed . scheme , parsed . netloc , parsed . path , parsed . params , urlencode ( _data ) , parsed . fragment ] ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def repage ( value , new_page ) : <EOL> return re_qs ( value , "<STR_LIT>" , new_page ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def facet_python ( value , new = None ) : <EOL> return re_qs ( value , "<STR_LIT>" , new ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def facet_os ( value , new = None ) : <EOL> return re_qs ( value , "<STR_LIT>" , new ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def facet_license ( value , new = None ) : <EOL> return re_qs ( value , "<STR_LIT>" , new ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> @ stringfilter <EOL> def facet_implementation ( value , new = None ) : <EOL> return re_qs ( value , "<STR_LIT>" , new ) </s>
