'Returns Objects the current user is allowed to access, depending on mode - read(r), write(w) or execute(x)'

def filter_by_request(request, manager, mode='r', filter_trash=True):

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except MultipleObjectsReturned:
            user = User.objects.filter(user__id=request.user.id)[0]
    if user:
        return Object.filter_permitted(user, manager, mode, filter_trash)
    return []
