def require_perms(view_func, required):
    from horizon.exceptions import NotAuthorized  # noqa
    # We only need to check each permission once for a view, so we'll use a set
    current_perms = getattr(view_func, '_required_perms', set([]))
    view_func._required_perms = current_perms | set(required)

    @functools.wraps(view_func, assigned=available_attrs(view_func))
    def dec(request, *args, **kwargs):
        if request.user.is_authenticated():
            if request.user.has_perms(view_func._required_perms):
                return view_func(request, *args, **kwargs)
        raise NotAuthorized(_("You are not authorized to access %s")
                            % request.path)

    # If we don't have any permissions, just return the original view.
    if required:
        return dec
    else:
        return view_func
"ORDER BY NULL" prevents MySQL from implicitly ordering by grouped
dataset/ETHPy150Open CiscoSystems/avos/horizon/decorators.py/require_perms--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/backends/mysql/base.py/DatabaseOperations.force_no_ordering