old_contents: import json
  
  from django.template import Library
  
  register = Library()
  
  
  @register.filter
  def format_json(data, indent=2):
      return json.dumps(json.loads(data), indent=indent)
  
  
  @register.simple_tag(takes_context=True)
  def construct_get_query(context, **params):
      request_get = context['request'].GET.dict()
      if not (request_get or params):
          return ''
  
      for param in params.keys():
          if param in request_get:
              del request_get[param]
  
      query = '?' + _format_params(params)
      if request_get:
          query += '&' + _format_params(request_get)
      return query
  
  
  def _format_params(params):
      return '&'.join(['%s=%s' % (param, value)
                      for param, value in params.items()])
  
new_contents: import json
  try:
      from urllib.parse import urlencode
  except ImportError:
      from urllib import urlencode
  
  from django.template import Library
  
  register = Library()
  
  
  @register.filter
  def format_json(data, indent=2):
      return json.dumps(json.loads(data), indent=indent)
  
  
  @register.simple_tag(takes_context=True)
  def construct_get_query(context, **params):
      request_get = context['request'].GET.dict()
      if not (request_get or params):
          return ''
      all_params = {}
      all_params.update(request_get)
      all_params.update(params)
      return '?' + urlencode(all_params)
  
subject: Simplify constructing url query