Beispiel #1
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)
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
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
Beispiel #4
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
Beispiel #5
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
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