@RequireLogin()
def put(request, username):
    """
    Update existing user based on username.
    """
    # Users can only update their own account, unless admin
    if (request.user['username'] != username) and (auth.is_admin(request.user) is False):
        return HttpResponseForbidden()

    try:
        in_json = json.loads(request.body)
    except __HOLE__:
        return HttpResponseBadRequest("invalid JSON")

    from api.models import db_model
    dbc = db_model.connect()
    user = dbc.hbuser.find_one({"username": username})
    if user is None:
        return HttpResponseNotFound()
    else:
        if "password" in in_json:
            m = hashlib.sha512()
            m.update(in_json['password'])
            user['password'] = m.hexdigest()
        if "email" in in_json:
            user['email'] = in_json['email']
        if "roles" in in_json:
            user['roles'] = in_json['roles']
        user['updatedAt'] = datetime.isoformat(datetime.now())
        dbc.hbuser.save(user)
        logger.info("user '%s' updated by '%s'" % (username, request.user['username']))
        return HttpResponse()
dataset/ETHPy150Open emccode/heliosburn/heliosburn/django/hbproject/api/views/user.py/put