(protected_view)
return wrapper
decorator to check whether the username passed to the view (from the URL)
    matches the username with which the user is authenticated.
decorator to check whether the username passed to the view (from the URL)
    matches the username with which the user is authenticated.
decorator to check whether the username passed to the view ( from the URL ) matches the username with which the user is authenticated .
def check_username(protected_view):
    """
    decorator to check whether the username passed to the view (from the URL)
    matches the username with which the user is authenticated.
    """

    @wraps(protected_view)
    def wrapper(request, username, *args, **kwargs):

        if request.user.username.lower() == username.lower():
            return protected_view(request, *args, username=username, **kwargs)

        else:
            # TODO: raise SuspiciousOperation here?
            logger.warning(
                "username in authentication (%s) and in requested resource (%s) don't match"
                % (request.user.username, username)
            )
            return HttpResponseBadRequest(
                "username in authentication (%s) and in requested resource (%s) don't match"
                % (request.user.username, username)
            )

    return wrapper
def check_username ( protected_view ) : @ wraps ( protected_view ) def wrapper ( request , username , * args , * * kwargs ) : if request . user . username . lower ( ) == username . lower ( ) : return protected_view ( request , * args , username = username , * * kwargs ) else : # TODO: raise SuspiciousOperation here? logger . warning ( "username in authentication (%s) and in requested resource (%s) don't match" % ( request . user . username , username ) ) return HttpResponseBadRequest ( "username in authentication (%s) and in requested resource (%s) don't match" % ( request . user . username , username ) ) return wrapper