From deb96c9ce7211117022f70cfd3fa6757535ff7c7 Mon Sep 17 00:00:00 2001 From: krateng Date: Wed, 29 Mar 2023 17:56:07 +0200 Subject: [PATCH] Adjusted artist page for album artists --- maloja/database/__init__.py | 8 ++++++-- maloja/database/sqldb.py | 13 +++++++++++++ maloja/web/jinja/artist.jinja | 6 +++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 80bbf84..1d8dccd 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -398,14 +398,18 @@ def artist_info(dbconn=None,**keys): artist_id = sqldb.get_artist_id(artist,dbconn=dbconn) artist = sqldb.get_artist(artist_id,dbconn=dbconn) alltimecharts = get_charts_artists(timerange=alltime(),dbconn=dbconn) - scrobbles = get_scrobbles_num(artist=artist,timerange=alltime(),dbconn=dbconn) #we cant take the scrobble number from the charts because that includes all countas scrobbles + scrobbles = get_scrobbles_num(artist=artist,timerange=alltime(),dbconn=dbconn) + albums = sqldb.get_albums_of_artists(set([artist_id]),dbconn=dbconn) + isalbumartist = len(albums.get(artist_id,[]))>0 + # base info for everyone result = { "artist":artist, "scrobbles":scrobbles, - "id":artist_id + "id":artist_id, + "isalbumartist":isalbumartist } # check if credited to someone else diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index f8d89aa..3bc35b5 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -1055,6 +1055,19 @@ def get_artists_of_albums(album_ids,dbconn=None): artists.setdefault(row.album_id,[]).append(artist_db_to_dict(row,dbconn=dbconn)) return artists +@cached_wrapper_individual +@connection_provider +def get_albums_of_artists(artist_ids,dbconn=None): + op = sql.join(DB['albumartists'],DB['albums']).select().where( + DB['albumartists'].c.artist_id.in_(artist_ids) + ) + result = dbconn.execute(op).all() + + albums = {} + for row in result: + albums.setdefault(row.artist_id,[]).append(album_db_to_dict(row,dbconn=dbconn)) + return albums + @cached_wrapper_individual @connection_provider diff --git a/maloja/web/jinja/artist.jinja b/maloja/web/jinja/artist.jinja index d551315..ba4b99f 100644 --- a/maloja/web/jinja/artist.jinja +++ b/maloja/web/jinja/artist.jinja @@ -90,19 +90,22 @@ +{% if info["isalbumartist"] %}

Top Albums

{% with amountkeys={"perpage":15,"page":0} %} {% include 'partials/charts_albums.jinja' %} {% endwith %} +{% endif %} - +{% if info['scrobbles']>0 %}

Top Tracks

{% with amountkeys={"perpage":15,"page":0} %} {% include 'partials/charts_tracks.jinja' %} {% endwith %} +
@@ -180,5 +183,6 @@ {% with amountkeys = {"perpage":15,"page":0} %} {% include 'partials/scrobbles.jinja' %} {% endwith %} +{% endif %} {% endblock %}