Exemplo n.º 1
0
def session(tmpdir):
    db_file = os.path.join(tmpdir.strpath, 'temp.db')
    if os.path.exists(db_file):
        os.remove(db_file)

    create_all_tables(db_file)
    session = connect(db_file)
    yield session
    session.close()
Exemplo n.º 2
0
def session(tmpdir):
    db_file = os.path.join(tmpdir.strpath, 'temp.db')
    if os.path.exists(db_file):
        os.remove(db_file)

    create_all_tables(db_file)
    session = connect(db_file)
    yield session
    session.close()
Exemplo n.º 3
0
def session_with_artist_including_unicode(tmpdir):
    db_file = os.path.join(tmpdir.strpath, 'temp.db')
    if os.path.exists(db_file):
        os.remove(db_file)

    create_all_tables(db_file)
    session = connect(db_file)
    with vcr.use_cassette('test_add_artist_to_db_unicode'):
        add_artist_to_db(ALT_J_MBID, session)  # Tested separately
    session.commit()
    yield session
    session.close()
Exemplo n.º 4
0
def session_with_artist_including_unicode(tmpdir):
    db_file = os.path.join(tmpdir.strpath, 'temp.db')
    if os.path.exists(db_file):
        os.remove(db_file)

    create_all_tables(db_file)
    session = connect(db_file)
    with vcr.use_cassette('test_add_artist_to_db_unicode'):
        add_artist_to_db(ALT_J_MBID, session)  # Tested separately
    session.commit()
    yield session
    session.close()
Exemplo n.º 5
0
def get_artists():
    session = connect()
    artists = session.query(Artist)

    rows = []

    for artist in artists:
        total_tracks = session.query(Track) \
            .join(Release) \
            .join(Album) \
            .join(Artist) \
            .filter(Release.is_selected, Artist.musicbrainz_id == artist.musicbrainz_id).count()

        possessed_tracks_count = 0

        latest_album = artist.albums.join(Release).order_by(Release.release_date.desc()).first()

        if latest_album:
            latest_album_title = latest_album.title
            latest_release = latest_album.releases.order_by(Release.release_date.desc()).first()
            latest_album_release_date = latest_release.release_date
            latest_album_id = latest_album.musicbrainz_id
        else:
            latest_album_title, latest_album_release_date, latest_album_id = None, None, None

        rows.append({
            'id': artist.musicbrainz_id,
            'name': artist.name,
            'status': artist.status.name,
            'total_tracks': total_tracks,
            'possessed_tracks': 0,  # TODO: implement
            'latest_album': latest_album_title,
            'latest_album_release_date': latest_album_release_date,
            'latest_album_id': latest_album_id
        })

    return jsonify({
        'data': rows
    })
Exemplo n.º 6
0
def get_artists():
    session = connect()
    artists = session.query(Artist)

    rows = []

    for artist in artists:
        total_tracks = session.query(Track) \
            .join(Release) \
            .join(Album) \
            .join(Artist) \
            .filter(Release.is_selected, Artist.musicbrainz_id == artist.musicbrainz_id).count()

        possessed_tracks_count = 0

        latest_album = artist.albums.join(Release).order_by(
            Release.release_date.desc()).first()

        if latest_album:
            latest_album_title = latest_album.title
            latest_release = latest_album.releases.order_by(
                Release.release_date.desc()).first()
            latest_album_release_date = latest_release.release_date
            latest_album_id = latest_album.musicbrainz_id
        else:
            latest_album_title, latest_album_release_date, latest_album_id = None, None, None

        rows.append({
            'id': artist.musicbrainz_id,
            'name': artist.name,
            'status': artist.status.name,
            'total_tracks': total_tracks,
            'possessed_tracks': 0,  # TODO: implement
            'latest_album': latest_album_title,
            'latest_album_release_date': latest_album_release_date,
            'latest_album_id': latest_album_id
        })

    return jsonify({'data': rows})
Exemplo n.º 7
0
def delete_artist(artist_id):
    session = connect()
    artist = session.query(Artist).filter_by(musicbrainz_id=artist_id).first()
    session.delete(artist)
    session.commit()
    return redirect('/home')
Exemplo n.º 8
0
def delete_artist(artist_id):
    session = connect()
    artist = session.query(Artist).filter_by(musicbrainz_id=artist_id).first()
    session.delete(artist)
    session.commit()
    return redirect('/home')