Esempio n. 1
0
    def save_and_return_errors(thing, user):
        try:
            if isinstance(thing, Convertible):
                thing.convert_to_database_units()

            thing.save_with_user(user)
            return {}
        except ValidationError as e:
            return package_validation_errors(thing._model_name, e)
Esempio n. 2
0
    def save_and_return_errors(thing, user):
        try:
            if isinstance(thing, Convertible):
                thing.convert_to_database_units()

            thing.save_with_user(user)
            return {}
        except ValidationError as e:
            return package_validation_errors(thing._model_name, e)
Esempio n. 3
0
def update_user(request, user):
    new_values = json_from_request(request) or {}
    for key in new_values:
        try:
            model, field = key.split(".", 1)
            if model != "user":
                return bad_request_json_response('All fields should be prefixed with "user."')
            if field not in USER_PROFILE_FIELDS:
                return bad_request_json_response(field + " is not an updatable field")
        except ValueError:
            return bad_request_json_response('All fields should be prefixed with "user."')
        setattr(user, field, new_values[key])
    try:
        user.save()
        return {"ok": True}
    except ValidationError, ve:
        return bad_request_json_response(validation_error_dict=package_validation_errors("user", ve))
Esempio n. 4
0
def update_user(request, user):
    new_values = json_from_request(request) or {}
    for key in new_values:
        try:
            model, field = key.split('.', 1)
            if model != 'user':
                return bad_request_json_response(
                    'All fields should be prefixed with "user."')
            if field not in USER_EDIT_FIELDS:
                return bad_request_json_response(field +
                                                 ' is not an updatable field')
        except ValueError:
            return bad_request_json_response(
                'All fields should be prefixed with "user."')
        setattr(user, field, new_values[key])
    try:
        user.save()
        return {"ok": True}
    except ValidationError, ve:
        return bad_request_json_response(
            validation_error_dict=package_validation_errors('user', ve))
Esempio n. 5
0
def update_user(request, username):
    user = get_object_or_404(User, username=username)
    if user != request.user:
        return HttpResponseForbidden()

    new_values = json_from_request(request) or {}
    for key in new_values:
        try:
            model, field = key.split(".", 1)
            if model != "user":
                return bad_request_json_response('All fields should be prefixed with "user."')
            if field not in ["first_name", "last_name", "email"]:
                return bad_request_json_response(field + " is not an updatable field")
        except ValueError:
            return bad_request_json_response('All fields should be prefixed with "user."')
        setattr(user, field, new_values[key])
    try:
        user.save()
        return {"ok": True}
    except ValidationError, ve:
        return bad_request_json_response(validation_error_dict=package_validation_errors("user", ve))
Esempio n. 6
0
def update_user(request, user):
    new_values = json_from_request(request) or {}
    for key in new_values:
        try:
            model, field = key.split('.', 1)
            if model != 'user':
                return bad_request_json_response(
                    'All fields should be prefixed with "user."')
            if field not in ['first_name', 'last_name', 'email']:
                return bad_request_json_response(
                    field + ' is not an updatable field')
        except ValueError:
            return bad_request_json_response(
                'All fields should be prefixed with "user."')
        setattr(user, field, new_values[key])
    try:
        user.save()
        return {"ok": True}
    except ValidationError, ve:
        return bad_request_json_response(
            validation_error_dict=package_validation_errors('user', ve))
Esempio n. 7
0
 def save_and_return_errors(thing, user):
     try:
         thing.save_with_user(user)
         return {}
     except ValidationError as e:
         return package_validation_errors(thing._model_name, e)