@contextfunction
def htsortlink(context, field_name):
    "Return URL of the sorting field"

    if 'request' not in context:
        return ''
    request = context['request']

    sort_value = field_name
    url = u"%s?" % (request.path)
    if request.GET:
        for arg in request.GET:
            values = request.GET.getlist(arg)
            for value in values:
                svalue = value.lstrip('-')
                if arg == 'sorting' and svalue == field_name:
                    if value[0] != '-':
                        sort_value = u'-%s' % sort_value
                else:
                    url += unicode(arg) + "=" + value + "&"
    url += "sorting=%s" % sort_value

    return url
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/modules.py/htsortlink/original