コード例 #1
0
def custom_model_post(endpoint):
    model_db_cached = fetch_model(request.headers['X-Internal-AccessToken'], endpoint)

    instance = model_db_cached(**request.json)
    to_persist(instance)

    serializer_class = build_serializer(model_db_cached)
    serializer = serializer_class()
    save_all()

    return jsonify({'result': serializer.dump(instance).data})
コード例 #2
0
def create(secret_key, name, email, password):
    strip(locals(), 'email', 'password')
    validate(locals(), validate_creation)

    if user_acessor.user_by_email(email):
        raise ApiException(codes.EMAIL_ALREADY_REGISTERED, email)

    user = User.create(name, email, encrypt_password(password))
    to_persist(user)

    return user
コード例 #3
0
def custom_model_put(endpoint, model_id):
    model_db_cached = fetch_model(request.headers['X-Internal-AccessToken'], endpoint)

    instance = model_acessor.find(model_db_cached, model_id)

    if not instance:
        raise ApiException(code=404)

    for key, value in request.json.items():
        setattr(instance, key, value)

    to_persist(instance)
    save_all()

    serializer_class = build_serializer(model_db_cached)
    serializer = serializer_class()

    return jsonify({'result': serializer.dump(instance).data})