def get_owned_object_or_40x(klass, owner, include_staff=False,
                            include_superuser=True, *args, **kwargs):
    obj = get_object_or_404(klass, *args, **kwargs)
    if obj.is_not_owned_by(owner, include_staff, include_superuser):
        raise PermissionDenied()
    return obj
Returns an object if it can be found (using get_object_or_404).
dataset/ETHPy150Open timsavage/django-extras/django_extras/contrib/auth/shortcuts.py/get_owned_object_or_40x