Example #1
0
def get_user_marshmallow_integrated(request):
    user = DBSession.query(User).filter_by(name="Bruce Wayne").one()

    if random.randint(0, 1):
        request.render_schema = UserSchema()
    else:
        request.render_schema = UserSchema(exclude=("id", "created_at"))

    return user
Example #2
0
def get_user_sqlalchemy_marshmallow(request):
    user = DBSession.query(User).filter_by(name="Bruce Wayne").one()

    # Now we select the schema and which fields to be included/excluded
    # based on some runtime condition. Imagine a test if the currently
    # logged in user is admin or not.
    if random.randint(0, 1):
        user_schema = UserSchema()
    else:
        user_schema = UserSchema(exclude=("id", "created_at"))

    data, errors = user_schema.dump(user)
    return data
Example #3
0
def get_user_sqlalchemy_simple(request):
    user = DBSession.query(User).filter_by(name="Bruce Wayne").one()
    return user