Exemplo n.º 1
0
def add_movie():
    if request.method == 'GET':
        return render_template('add_movie.html', genres=genres)
    elif request.method == 'POST':
        movie = Movie(None, request.form['name'], request.form['genre'],
                      request.form['release_year'], request.form['duration'],
                      request.form['description'], request.form['rating'],
                      request.form['director_name'])

        movie.create(movie)

        return redirect('/movies')
Exemplo n.º 2
0
def add_movie():
    """
    Add new movie
    """
    ### YOUR CODE HERE ###
    data = get_request_data()
    if 'name' in data.keys():
        if 'year' in data.keys():
            if 'genre' in data.keys():
                try:
                    if data['year'].isdigit() and len(data['year']) == 4 and data['genre'].isalpha():
                        new_record = Movie.create(**data)
                        try:
                            new_movie = {k: v for k, v in new_record.__dict__.items() if k in MOVIE_FIELDS}
                        except:
                            err = 'Record with such id does not exist'
                            return make_response(jsonify(error=err), 400)
                        return make_response(jsonify(new_movie), 200)
                    else:
                        return make_response(jsonify(error='ERROR'), 400)
                except:
                    return make_response(jsonify(error='ERROR'), 400)
            else:
                err = 'No genre specified'
                return make_response(jsonify(error=err), 400)
        else:
            err = 'No year specified'
            return make_response(jsonify(error=err), 400)
    else:
        err = 'No name specified'
        return make_response(jsonify(error=err), 400)
Exemplo n.º 3
0
def add_movie():
    """
    Add new movie
    """

    data = get_request_data()

    try:
        new_record = Movie.create(**data)
        new_movie = {
            k: v
            for k, v in new_record.__dict__.items() if k in MOVIE_FIELDS
        }
    except:
        err = 'Input wrong fields'
        return make_response(jsonify(error=err), 400)

    return make_response(jsonify(new_movie), 200)
Exemplo n.º 4
0
def add_movie():
    """
    Add new movie
    """

    data = get_request_data()
    try:
        if data['year'].isdigit() and len(
                data['year']) == 4 and data['genre'].isalpha():
            new_record = Movie.create(**data)
            new_movie = {
                k: v
                for k, v in new_record.__dict__.items() if k in MOVIE_FIELDS
            }
            return make_response(jsonify(new_movie), 200)
        else:
            return make_response(jsonify(error='ERROR'), 400)

    except:
        return make_response(jsonify(error='ERROR'), 400)
Exemplo n.º 5
0
 def actor_add_relation():
     """
     Add a movie to actor's filmography
     """
     #data = get_request_data()
     data = {
         'name': 'Megan Fox',
         'gender': 'female',
         'date_of_birth': dt.strptime('16.05.1986', '%d.%m.%Y').date(),
         'name': 'Transformers',
         'genre': 'action',
         'year': 2007
     }
     ### YOUR CODE HERE ###
     movie_data = {k: v for k, v in data.items() if k in MOVIE_FIELDS}
     movie = Movie.create(movie_data)
     # use this for 200 response code
     actor = Actor.add_relation(data["id"], movie)  # add relation here
     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)
Exemplo n.º 6
0
    'SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # silence the deprecation warning

db.init_app(app)

with app.app_context():
    db.create_all()
    # actor = Actor.create(**data_actor)
    # print('created actor:', actor.__dict__, '\n')
    #
    # movie = Movie.create(**data_movie)
    # print('created movie:', movie.__dict__, '\n')

    upd_actor = Actor.update(1, **data_actor_upd)
    print('updated actor:', upd_actor.__dict__, '\n')

    upd_movie = Movie.update(1, **data_movie_upd)
    print('updated movie:', upd_movie.__dict__, '\n')

    add_rels_actor = Actor.add_relation(1, upd_movie)
    movie_2 = Movie.create(**data_movie)
    add_more_rels_actor = Actor.add_relation(1, movie_2)
    print('relations list:', add_more_rels_actor.filmography, '\n')

    # clear_rels_actor = Actor.clear_relations(1)
    # print('all relations cleared:', clear_rels_actor.filmography, '\n')

    # del_actor = Actor.delete(15)
    # print('Actor deleted:', del_actor)
    #
    # del_movie = Movie.delete(1)
    # print('Movie deleted:', del_movie)