Beispiel #1
0
def actor_add_relation():
    """
    Add a movie to actor's filmography
    """
    data = get_request_data()
    obj = Movie.query.filter_by(id=data['relation_id']).first()
    actor = Actor.add_relation(data['id'], obj)
    rel_actor = {k: v for k, v in actor.__dict__.items() if k in ACTOR_FIELDS}
    rel_actor['filmography'] = str(actor.filmography)
    return make_response(jsonify(rel_actor), 200)
def actor_add_relation():
    data = get_request_data()
    ''
    if 'id' in data.keys():
        try:
            row_id = int(data['id'])
        except:
            err = 'Id must be integer'
            return make_response(jsonify(error=err), 400)
        if 'relation_id' in data.keys():
            try:
                relation_id = int(data['relation_id'])
            except:
                err = 'Relation id must be integer'
                return make_response(jsonify(error=err), 400)
            try:
                rel_obj = Movie.query.filter_by(id=relation_id).first()
            except:
                err = 'No such movie'
                return make_response(jsonify(error=err), 400)
            # use this for 200 response code
            try:
                actor = Actor.add_relation(
                    row_id, rel_obj)  # add relation here #id , film
                rel_actor = {
                    k: v
                    for k, v in actor.__dict__.items() if k in ACTOR_FIELDS
                }
                rel_actor['filmography'] = str(actor.filmography)
                return make_response(jsonify(rel_actor), 200)
            except:
                err = 'Problem with add relation'
                return make_response(jsonify(error=err), 400)
        else:
            err = 'No relation id specified'
            return make_response(jsonify(error=err), 400)
    else:
        err = 'No id specified'
        return make_response(jsonify(error=err), 400)