Esempio n. 1
0
 def add_contract_to_actor():
     try:
         print("Input movie name:")
         movie_name = input()
         print("Input actor name:")
         actor_name = input()
         print("Input studio name:")
         studio_name = input()
         print("Input value:")
         value = int(input())
         if movie_name and actor_name and studio_name and value:
             s = Session()
             movie = s.query(Movie).filter_by(name=movie_name).first()
             studio = s.query(Studio).filter_by(name=studio_name).first()
             actor = s.query(Actor).filter_by(full_name=actor_name).first()
             if (movie is None) or (actor is None) or (studio is None):
                 View.display_no_results()
                 s.close()
             else:
                 s.add(
                     Contract(movie_id=movie.id,
                              studio_id=studio.id,
                              actor_id=actor.id,
                              value=value))
                 s.commit()
                 s.close()
                 View.display_success()
         else:
             print("Incorrect input")
     except SQLAlchemyError as e:
         View.display_error()
Esempio n. 2
0
    def delete_contract_from_actor():
        try:
            print("Input movie name:")
            movie_name = input()
            print("Input actor name:")
            actor_name = input()
            print("Input studio name:")
            studio_name = input()

            if movie_name and actor_name and studio_name:
                s = Session()
                movie = s.query(Movie).filter_by(name=movie_name).first()
                studio = s.query(Studio).filter_by(name=studio_name).first()
                actor = s.query(Actor).filter_by(full_name=actor_name).first()
                if (movie is None) or (actor is None) or (studio is None):
                    View.display_no_results()
                    s.close()
                else:
                    s.query(Contract).filter(
                        Contract.movie_id == movie.id,
                        Contract.actor_id == actor.id,
                        Contract.studio_id == studio.id).delete()

                    s.commit()
                    s.close()
                    View.display_success()
            else:
                print("Incorrect input")
        except SQLAlchemyError as e:
            print(e)
            View.display_error()
Esempio n. 3
0
def get_all_songs_from_playlist(session: Session, playlist_id: int, offset: int = 0, limit: int = 10, song_title: str = None, song_artist: str = None) -> list:
    if song_title and song_artist:
        songs_result = session.query(Song).filter(Song.title == song_title,
                                                 Song.artist == song_artist,
                                                 Song.playlists.any(id = playlist_id))\
            .offset(offset)\
            .limit(limit)\
            .all()
    elif song_title:
        songs_result = session.query(Song).filter(Song.title == song_title,
                                                  Song.playlists.any(id = playlist_id)) \
            .offset(offset) \
            .limit(limit) \
            .all()
    elif song_artist:
        songs_result = session.query(Song).filter(Song.artist == song_artist,
                                                  Song.playlists.any(id = playlist_id)) \
            .offset(offset) \
            .limit(limit) \
            .all()
    else:
        songs_result = session.query(Song).filter(Song.playlists.any(id = playlist_id)) \
            .offset(offset) \
            .limit(limit) \
            .all()
    return songs_result
Esempio n. 4
0
def index():
    """
    Passes a list of player-character Characters and two locations to the template.
    """
    s = Session()

    try:
        pcs = s.query(Character).filter_by(player_character=True).all()
        locs = s.query(Location).limit(2).all()
        s.close()
        return render_template('index.html', pcs=pcs, locations=locs)
    except Exception as e:
        return str(e)
Esempio n. 5
0
 def delete_studio():
     print("Input name:")
     name = input()
     if not name:
         print("Incorrect input")
     else:
         try:
             s = Session()
             s.query(Studio).filter_by(name=name).delete()
             s.commit()
             s.close()
             View.display_success()
         except SQLAlchemyError:
             View.display_error()
Esempio n. 6
0
 def update_movie():
     try:
         print("Input name:")
         name = input()
         print("Input new name:")
         new_name = input()
         print("Input genre:")
         genre = input()
         print("Input description:")
         description = input()
         print("Input budget:")
         budget = int(input())
         if name and (new_name or genre or description or budget):
             s = Session()
             movie = s.query(Movie).filter_by(name=name).first()
             if new_name:
                 movie.name = new_name
             if genre:
                 movie.genre = genre
             if description:
                 movie.description = description
             if budget:
                 movie.budget = budget
             s.add(movie)
             s.commit()
             s.close()
             View.display_success()
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()
     except ValueError:
         print("Incorrect input")
Esempio n. 7
0
 def update_actor():
     try:
         print("Input name:")
         name = input()
         print("Input new name:")
         new_name = input()
         print("Input gender:")
         gender = input()
         print("Input age:")
         age = int(input())
         if name and (new_name or gender or age):
             s = Session()
             actor = s.query(Actor).filter_by(full_name=name).first()
             if new_name:
                 actor.full_name = new_name
             if gender:
                 actor.gender = gender
             if age:
                 actor.age = age
             s.add(actor)
             s.commit()
             s.close()
             View.display_success()
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()
     except ValueError:
         print("Incorrect input")
Esempio n. 8
0
def add_location():
    """
    Adds a new location to the database from the given form.
    Only reachable if the user is logged in.
    """
    if not current_user.is_authenticated:
        flash('Please login or register to add locations.')
        return redirect(url_for('index'))

    form = AddLocationForm()

    if form.validate_on_submit():
        s = Session()

        new_loc = Location(name=form.name.data,
                           content=form.content.data,
                           user_id=current_user.get_id())
        s.add(new_loc)
        s.commit()
        # get the full data of the new loc
        loc = s.query(Location).filter_by(name=form.name.data).first()
        s.close()
        flash('"{}" has been added as a location!'.format(form.name.data))
        return redirect(url_for('location', loc_name=loc.name))

    return render_template('locations/add_location_form.html', form=form)
Esempio n. 9
0
def get_all_playlists(session: Session,
                      user_id: int,
                      offset: int = 0,
                      limit: int = 10) -> list:
    return session.query(Playlist).filter_by(user_id = user_id)\
            .offset(offset)\
            .limit(limit)
Esempio n. 10
0
 def update_studio():
     try:
         print("Input name:")
         name = input()
         print("Input new name:")
         new_name = input()
         print("Input country:")
         country = input()
         if name and (new_name or country):
             s = Session()
             studio = s.query(Studio).filter_by(name=name).first()
             if new_name:
                 studio.name = new_name
             if country:
                 studio.country = country
             s.add(studio)
             s.commit()
             s.close()
             View.display_success()
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()
     except ValueError:
         print("Incorrect input")
Esempio n. 11
0
def update_song_ownership(session: Session, song_id: int, new_owner_user_id: int) -> bool:
    song = session.query(Song).filter_by(id = song_id).first()
    if song:
        song.user_id = new_owner_user_id
        session.commit()
        return True
    else:
        return False
Esempio n. 12
0
def update_playlist(session: Session, playlist_id: int,
                    playlist_name: str) -> bool:
    playlist = session.query(Playlist).filter(Playlist.id == playlist_id)
    if playlist:
        playlist.name = playlist_name
        session.commit()
        return True
    else:
        return False
Esempio n. 13
0
def get_all_songs(session: Session, offset: int = 0, limit: int = 10, song_title: str = None, song_artist: str = None) -> list:
    if song_title and song_artist:
        songs_result = session.query(Song).filter_by(title = song_title, artist = song_artist)\
            .offset(offset)\
            .limit(limit)
    elif song_title:
        songs_result = session.query(Song).filter_by(title = song_title)\
            .offset(offset)\
            .limit(limit)
    elif song_artist:
        songs_result = session.query(Song).filter_by(artist = song_artist)\
            .offset(offset)\
            .limit(limit)
    else:
        songs_result = session.query(Song)\
            .offset(offset)\
            .limit(limit)\
            .all()
    return songs_result
Esempio n. 14
0
def update_song(session: Session, song_id: int, song_title: str, song_album : str, song_release_year: int, song_url: str) -> bool:
    song = session.query(Song).filter_by(id = song_id).first()
    if song:
        song.title = song_title if song_title else song.title
        song.album = song_album if song_album else song_album
        song.release_year = song_release_year if song_release_year else song_release_year
        song.url = song_url if song_url else song.url
        session.commit()
        return True
    else:
        return False
Esempio n. 15
0
def location(loc_name):
    """
    Displays the page about the given location.

    :param loc_name: str - name of the location
    """
    s = Session()

    loc = s.query(Location).filter_by(name=loc_name).first()
    s.close()
    return render_template('locations/location.html', location=loc)
Esempio n. 16
0
 def show_movies():
     try:
         s = Session()
         movies = s.query(Movie).all()
         s.close()
         if movies:
             View.display_movies(movies)
         else:
             View.display_no_results()
     except SQLAlchemyError:
         View.display_error()
Esempio n. 17
0
 def show_actors():
     try:
         s = Session()
         actors = s.query(Actor).all()
         s.close()
         if actors:
             View.display_actors(actors)
         else:
             View.display_no_results()
     except SQLAlchemyError:
         View.display_error()
Esempio n. 18
0
 def show_studios():
     try:
         s = Session()
         studios = s.query(Studio).all()
         s.close()
         if studios:
             View.display_studios(studios)
         else:
             View.display_no_results()
     except SQLAlchemyError:
         View.display_error()
Esempio n. 19
0
def get_all_characters():
    """
    Gets a list of all characters in the database and the template displays their name and race.
    """
    s = Session()

    try:
        characters = s.query(Character).all()
        s.close()
        return render_template("characters/character_list.html", characters=characters)
    except Exception as e:
        return str(e)
Esempio n. 20
0
def get_entry(id_):
    """
    Gets the Entry corresponding to id_ from the database.

    :type id_: int
    :return: Entry
    """
    s = Session()

    session_entry = s.query(Entry).filter_by(id=id_).first()
    s.close()
    return session_entry
Esempio n. 21
0
def get_pc(pc_id):
    """
    Gets the Character corresponding to pc_id from the database.

    :type pc_id: str
    :return: Character
    """
    s = Session()

    character = s.query(Character).filter_by(name=pc_id).first()
    s.close()
    return character
Esempio n. 22
0
def all_entries():
    """
    Gets a list of all Entries and displays their title and creation time in the template.
    """
    s = Session()

    try:
        entries_list = s.query(Entry).all()
        s.close()
        return render_template("entries/entries_list.html",
                               entries=entries_list)
    except Exception as e:
        return str(e)
Esempio n. 23
0
def all_locations():
    """
    Gets a list of all locations from the database and passes it to the template.
    The template iterates through the list and displays some info on the location.
    """
    s = Session()

    try:
        locations_list = s.query(Location).all()
        s.close()
        return render_template("locations/locations_list.html",
                               locations=locations_list)
    except Exception as e:
        return str(e)
Esempio n. 24
0
 def add_actor_to_movie():
     try:
         print("Input movie name:")
         movie_name = input()
         print("Input actor name:")
         actor_name = input()
         if movie_name and actor_name:
             s = Session()
             movie = s.query(Movie).filter_by(name=movie_name).first()
             actor = s.query(Actor).filter_by(full_name=actor_name).first()
             s.add(movie)
             if (movie is None) or (actor is None):
                 View.display_no_results()
                 s.close()
             else:
                 movie.cast.append(actor)
                 View.display_success()
                 s.commit()
                 s.close()
         else:
             print("Incorrect input")
     except SQLAlchemyError as e:
         View.display_error()
Esempio n. 25
0
def update_user(session: Session, user_id: str, user_first_name: str,
                user_last_name: str, user_email: str, user_password: str,
                user_password_salt: str) -> bool:
    user = session.query(User).filter_by(id=user_id).first()
    if not user:
        return False

    user.first_name = user_first_name if user_first_name else user.first_name
    user.last_name = user_last_name if user_last_name else user.last_name
    user.email = user_email if user_email else user.email
    user.password = user_password if user_password else user.password
    user.password_salt = user_password_salt if user_password_salt else user.password_salt
    session.commit()
    return True
Esempio n. 26
0
 def remove_movie_from_studio():
     try:
         print("Input movie name:")
         movie_name = input()
         print("Input studio name:")
         studio_name = input()
         if movie_name and studio_name:
             s = Session()
             movie = s.query(Movie).filter_by(name=movie_name).first()
             studio = s.query(Studio).filter_by(name=studio_name).first()
             s.add(studio)
             if (movie is None) or (studio is None):
                 View.display_no_results()
                 s.close()
             else:
                 studio.movies.remove(movie)
                 View.display_success()
                 s.commit()
                 s.close()
         else:
             print("Incorrect input")
     except SQLAlchemyError as e:
         View.display_error()
Esempio n. 27
0
 def show_actor():
     try:
         print("Input name:")
         name = input()
         if name:
             s = Session()
             actor = s.query(Actor).filter_by(full_name=name).first()
             s.close()
             if actor is None:
                 View.display_no_results()
             else:
                 View.display_actor(actor)
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()
Esempio n. 28
0
def create_user(session: Session, user_first_name: str, user_last_name: str,
                user_email: str, user_password: str, user_password_salt: str,
                user_auth_token: str) -> bool:
    result = session.query(exists().where(User.email == user_email)).scalar()
    if result:
        return False

    user = User(first_name=user_first_name,
                last_name=user_last_name,
                email=user_email,
                password_hashed=user_password,
                password_salt=user_password_salt,
                auth_token=user_auth_token)
    session.add(user)
    session.commit()
    return True
Esempio n. 29
0
 def show_studio():
     try:
         print("Input name:")
         name = input()
         if name:
             s = Session()
             studio = s.query(Studio).filter_by(name=name).first()
             s.close()
             if studio is None:
                 View.display_no_results()
             else:
                 View.display_studio(studio)
                 View.display_movies(studio.movies)
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()
Esempio n. 30
0
 def show_movie():
     try:
         print("Input name:")
         name = input()
         if name:
             s = Session()
             movie = s.query(Movie).filter_by(name=name).first()
             s.close()
             if movie is None:
                 View.display_no_results()
             else:
                 View.display_movie(movie)
                 View.display_actors(movie.cast)
         else:
             print("Incorrect input")
     except SQLAlchemyError:
         View.display_error()