Esempio n. 1
0
def get_user(id):
    user = User.query.get(id)
    if not user:
        abort(400)
    schema = UserSchema(exclude=('current_matches', 'recent_matches', 'friends'))
    res = schema.dumps(user)
    if not res.errors:
        return jsonify({'user' : res.data})
    else:
        # TODO: Sending server errors to client
        abort(500)
Esempio n. 2
0
    def testSerializeDeserialize(self):
        john = User.query.get(1) # getting John
        jack = User.query.get(3)

        john.recent_matches = []
        john.current_matches = []
        for m in john.matches:
            if m.finished == True:
                john.recent_matches.append(m)
            else:
                john.current_matches.append(m)
        userSchema = UserSchema()
        dumped_john = userSchema.dumps(john)
        assert not dumped_john.errors
        app.logger.debug('testSerializeDeserialize - OK')
Esempio n. 3
0
def get_main_view_controller():
    user = g.user
    user.current_matches = []
    user.recent_matches = []
    for m in user.matches:
        if m.finished == True:
            user.recent_matches.append(m)
        else:
            user.current_matches.append(m)
    schema = UserSchema()
    res = schema.dumps(user)
    if not res.errors:
        resp = make_response(res.data)
        resp.mimetype = 'application/json'
        return resp
    else:
        return jsonify(res.errors)