'Arguments are passed like: _oc_<VIEW_NAME>=<COL_NAME>&_od_<VIEW_NAME>=\'asc\'|\'desc\''

@app_template_filter('link_order')
def link_order_filter(self, column, modelview_name):

    new_args = request.view_args.copy()
    args = request.args.copy()
    if (('_oc_' + modelview_name) in args):
        args[('_oc_' + modelview_name)] = column
        if (args.get(('_od_' + modelview_name)) == 'asc'):
            args[('_od_' + modelview_name)] = 'desc'
        else:
            args[('_od_' + modelview_name)] = 'asc'
    else:
        args[('_oc_' + modelview_name)] = column
        args[('_od_' + modelview_name)] = 'asc'
    return url_for(request.endpoint, **dict((list(new_args.items()) + list(args.to_dict().items()))))
