Exemplo n.º 1
0
def delete_playlist_entry(dj_id: str, p_name: str, index: int) -> None:
    from klap4.db import Session
    session = Session()

    playlist_entries = session.query(PlaylistEntry) \
            .join(Playlist, and_(Playlist.id == PlaylistEntry.playlist_id, Playlist.name == p_name)) \
            .join(DJ, and_(DJ.id == Playlist.dj_id, DJ.id == dj_id)) \
            .order_by(PlaylistEntry.index) \
            .all()

    to_delete = session.query(PlaylistEntry) \
        .join(Playlist, and_(Playlist.id == PlaylistEntry.playlist_id, Playlist.name == p_name)) \
        .join(DJ, and_(DJ.id == Playlist.dj_id, DJ.id == dj_id)) \
        .filter(PlaylistEntry.index == index) \
        .one()

    to_delete.index = -1

    for entry in playlist_entries[index:]:
        entry.index = entry.index - 1

    session.commit()
    session.delete(to_delete)
    session.commit()

    return
Exemplo n.º 2
0
def delete_playlist(dj_id: str, name: str) -> None:
    from klap4.db import Session
    session = Session()

    session.query(Playlist).filter(
        and_(Playlist.dj_id == dj_id, Playlist.name == name)).delete()
    session.commit()

    return
Exemplo n.º 3
0
def report_problem(album_ref: str, dj_id: str, content: str) -> SQLBase:
    from klap4.db import Session
    session = Session()

    newProblem = AlbumProblem(id=album_ref, dj_id=dj_id, content=content)

    session.add(newProblem)
    session.commit()

    return newProblem
Exemplo n.º 4
0
def add_review(album_ref: str, dj_id: str, content: str) -> SQLBase:
    from datetime import datetime
    from klap4.db import Session
    session = Session()

    newReview = AlbumReview(id=album_ref, dj_id=dj_id, content=content)

    session.add(newReview)
    session.commit()

    return newReview.serialize
Exemplo n.º 5
0
def change_album_fcc(ref, fcc):
    from klap4.db import Session
    session = Session()

    album = get_entity_from_tag(ref)

    for song in album.songs:
        song.fcc_status = fcc
        session.commit()
    
    return get_json(album)
Exemplo n.º 6
0
def delete_program_log(program_type, timestamp, dj_id):
    from klap4.db import Session
    session = Session()

    from datetime import datetime
    #converted_timestamp = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
    delQuer = session.query(ProgramLogEntry) \
        .filter(and_(ProgramLogEntry.program_type == program_type, ProgramLogEntry.timestamp.contains(timestamp), ProgramLogEntry.dj_id == dj_id)) \
        .delete(synchronize_session='fetch')

    session.commit()
    return
Exemplo n.º 7
0
def add_playlist(dj_id: str, name: str, show: str) -> SQLBase:
    from klap4.db import Session
    session = Session()

    new_playlist = Playlist(dj_id=dj_id, name=name, show=show)

    session.add(new_playlist)
    session.commit()

    serialized_playlist = {"dj_id": dj_id, "name": name, "show": show}

    return serialized_playlist
Exemplo n.º 8
0
def check_user(userid, name, is_admin):
    from klap4.db import Session
    from klap4.db_entities.dj import DJ

    session = Session()
    if session.query(DJ).filter_by(id=userid).first() is None:
        user = DJ(id=userid, name=name, is_admin=is_admin)
        session.add(user)
        session.commit()
    else:
        user = session.query(DJ).filter_by(id=userid).first()

    return user
Exemplo n.º 9
0
def add_program_log(program_type, program_name, slot_id, dj_id):
    from klap4.db import Session
    session = Session()

    from datetime import datetime

    new_log = ProgramLogEntry(program_type=program_type,
                              program_name=program_name,
                              slot_id=int(slot_id),
                              timestamp=datetime.now(),
                              dj_id=dj_id)
    session.add(new_log)
    session.commit()

    return new_log
Exemplo n.º 10
0
def change_single_fcc(ref, song_number, fcc):
    from klap4.db import Session
    session = Session()

    album = get_entity_from_tag(ref)
    album_id = album.id

    update_song = session.query(Song) \
        .join(Album, and_(Album.id == Song.album_id, album.id == album_id)) \
        .filter(Song.number == song_number) \
        .one()
    
    update_song.fcc_status = fcc
    session.commit()

    return get_json(update_song)
Exemplo n.º 11
0
def update_program_log(program_type, program_name, slot_id, dj_id, new_name):
    from klap4.db import Session
    session = Session()

    from datetime import datetime

    update_entry = session.query(ProgramLogEntry) \
        .filter(
            and_(ProgramLogEntry.program_type == program_type, ProgramLogEntry.program_name == program_name,
                 ProgramLogEntry.slot_id == slot_id, ProgramLogEntry.dj_id == dj_id)
        ) \
        .one()

    update_entry.timestamp = datetime.now()
    update_entry.program_name = new_name
    session.commit()

    return update_entry
Exemplo n.º 12
0
def update_playlist(dj_id: str, name: str, show: str, new_name: str,
                    new_show: str) -> SQLBase:
    from klap4.db import Session
    session = Session()

    playlist_update = session.query(Playlist) \
        .filter(
            and_(Playlist.dj_id == dj_id, Playlist.name == name)
        ) \
        .one()

    playlist_update.name = new_name
    playlist_update.show = new_show

    session.commit()

    serialized_playlist = {"dj_id": dj_id, "name": new_name, "show": new_show}
    return serialized_playlist
Exemplo n.º 13
0
def add_playlist_entry(dj_id: str, p_name: str, entry) -> SQLBase:
    from klap4.db import Session
    session = Session()

    from datetime import datetime
    try:
        song_entry = session.query(Song) \
                        .join(Album, and_(Album.id == Song.album_id, Album.name == entry["album"])) \
                        .join(Artist, and_(Artist.id == Album.artist_id, Artist.name == entry["artist"])) \
                        .filter(Song.name == entry["song"]).one()

        old_times_played = song_entry.times_played
        song_entry.last_played = datetime.now()
        session.commit()
        song_entry.times_played = old_times_played + 1
        session.commit()

        reference_type = REFERENCE_TYPE.IN_KLAP4
        reference = song_entry.album.artist.genre.abbreviation + str(
            song_entry.album.artist.number) + song_entry.album.letter
    except:
        reference_type = REFERENCE_TYPE.MANUAL
        reference = str(entry)

    newPlaylistEntry = PlaylistEntry(dj_id=dj_id,
                                     playlist_name=p_name,
                                     reference=reference,
                                     reference_type=reference_type,
                                     entry=entry)

    session.add(newPlaylistEntry)
    session.commit()

    return get_json(newPlaylistEntry)
Exemplo n.º 14
0
def update_playlist_entry(dj_id: str, p_name: str, index: int, entry,
                          new_index: int, new_entry):
    from klap4.db import Session
    session = Session()

    from datetime import datetime

    if new_index is None and entry is not None and new_entry is not None:
        try:
            song_entry = session.query(Song) \
                        .join(Album, and_(Album.id == Song.album_id, Album.name == new_entry["album"])) \
                        .join(Artist, and_(Artist.id == Album.artist_id, Artist.name == new_entry["artist"])) \
                        .filter(Song.name == new_entry["song"]).one()
            old_times_played = song_entry.times_played

            song_entry.last_played = datetime.now()
            session.commit()
            song_entry.times_played = old_times_played + 1
            session.commit()

            reference_type = REFERENCE_TYPE.IN_KLAP4
            reference = song_entry.album.artist.genre.abbreviation + str(
                song_entry.album.artist.number) + song_entry.album.letter
        except:
            reference_type = REFERENCE_TYPE.MANUAL
            reference = str(new_entry)

        update_entry = session.query(PlaylistEntry) \
            .join(Playlist, and_(Playlist.id == PlaylistEntry.playlist_id, Playlist.name == p_name)) \
            .join(DJ, and_(DJ.id == Playlist.dj_id, DJ.id == dj_id)) \
            .filter(
                and_(PlaylistEntry.index == index,
                     PlaylistEntry.entry == entry)
            ) \
            .one()

        update_entry.entry = new_entry
        update_entry.reference = reference
        update_entry.reference_type = reference_type
        session.commit()

    else:
        old_index = index
        playlist_entries = session.query(PlaylistEntry) \
            .join(Playlist, and_(Playlist.id == PlaylistEntry.playlist_id, Playlist.name == p_name)) \
            .join(DJ, and_(DJ.id == Playlist.dj_id, DJ.id == dj_id)) \
            .order_by(PlaylistEntry.index) \
            .all()

        if new_index > old_index:
            playlist_entries[old_index - 1].index = -1
            for entry in playlist_entries[old_index:new_index]:
                entry.index = entry.index - 1

            session.commit()
            playlist_entries[old_index - 1].index = new_index
            session.commit()

        elif new_index < old_index:
            playlist_entries[new_index - 1].index = -1

            playlist_entries[old_index - 1].index = new_index
            session.commit()

            for num in range(old_index - 1, new_index, -1):
                playlist_entries[num -
                                 1].index = playlist_entries[num - 1].index + 1
                session.commit()

            session.commit()
            playlist_entries[new_index - 1].index = new_index + 1
            session.commit()

        else:
            pass

    return