Allows to change one of the URL get parameter while keeping all the others.

    Usage::

      {% load libs_tags %}
      {% get_query_params request "page" page_obj.next_page_number as query %}
      <a href="?{{ query }}">Next</a>

    You can also pass in several pairs of keys and values::

      {% get_query_params request "page" 1 "foobar" 2 as query %}

    You often need this when you have a paginated set of objects with filters.

    Your url would look something like ``/?region=1&gender=m``. Your paginator
    needs to create links with ``&page=2`` in them but you must keep the
    filter values when switching pages.

    :param request: The request instance.
    :param *args: Make sure to always pass in paris of args. One is the key,
      one is the value. If you set the value of a key to "!remove" that
      parameter will not be included in the returned query.

def get_query_params(request, *args):
    """
    Allows to change one of the URL get parameter while keeping all the others.

    Usage::

      {% load libs_tags %}
      {% get_query_params request "page" page_obj.next_page_number as query %}
      <a href="?{{ query }}">Next</a>

    You can also pass in several pairs of keys and values::

      {% get_query_params request "page" 1 "foobar" 2 as query %}

    You often need this when you have a paginated set of objects with filters.

    Your url would look something like ``/?region=1&gender=m``. Your paginator
    needs to create links with ``&page=2`` in them but you must keep the
    filter values when switching pages.

    :param request: The request instance.
    :param *args: Make sure to always pass in paris of args. One is the key,
      one is the value. If you set the value of a key to "!remove" that
      parameter will not be included in the returned query.

    """
    query = request.GET.copy()
    index = 1
    key = ''
    for arg in args:
        if index % 2 != 0:
            key = arg
        else:
            if arg == "!remove":
                try:
                    query.pop(key)
                except KeyError:
                    pass
            else:
                query[key] = arg
        index += 1
    return query.urlencode()