<s> from django . utils . safestring import mark_safe <EOL> from django . utils . html import escape <EOL> from django import template <EOL> register = template . Library ( ) <EOL> def query_string ( request , variables , mode ) : <EOL> variable_list = variables . split ( '<STR_LIT:U+0020>' ) <EOL> query_string_dict = { } <EOL> for variable in variable_list : <EOL> value = request . GET . get ( variable , '<STR_LIT>' ) <EOL> if value : <EOL> query_string_dict [ variable ] = escape ( value ) <EOL> if query_string_dict : <EOL> if mode == "<STR_LIT>" : <EOL> query_string = '<STR_LIT:U+0020>' . join ( [ u'<STR_LIT>' % ( k , v ) for k , v in query_string_dict . items ( ) ] ) <EOL> else : <EOL> query_string = '<STR_LIT:?>' + '<STR_LIT>' . join ( [ u'<STR_LIT>' % ( k , v ) for k , v in query_string_dict . items ( ) ] ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> if mode == "<STR_LIT>" : <EOL> query_string += '<STR_LIT>' <EOL> else : <EOL> if mode == "<STR_LIT>" : <EOL> query_string = '<STR_LIT:?>' <EOL> else : <EOL> query_string = '<STR_LIT>' <EOL> return mark_safe ( query_string ) <EOL> register . simple_tag ( query_string ) </s>
