Clean up album and artist views
This commit is contained in:
@ -90,6 +90,24 @@ class Album(TimeStampedModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("music:album_detail", kwargs={'slug': self.uuid})
|
||||||
|
|
||||||
|
def scrobbles(self):
|
||||||
|
from scrobbles.models import Scrobble
|
||||||
|
|
||||||
|
return Scrobble.objects.filter(
|
||||||
|
track__in=self.track_set.all()
|
||||||
|
).order_by('-timestamp')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tracks(self):
|
||||||
|
return (
|
||||||
|
self.track_set.all()
|
||||||
|
.annotate(scrobble_count=models.Count('scrobble'))
|
||||||
|
.order_by('-scrobble_count')
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def primary_artist(self):
|
def primary_artist(self):
|
||||||
return self.artists.first()
|
return self.artists.first()
|
||||||
|
|||||||
@ -6,6 +6,11 @@ app_name = 'music'
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('albums/', views.AlbumListView.as_view(), name='albums_list'),
|
path('albums/', views.AlbumListView.as_view(), name='albums_list'),
|
||||||
|
path(
|
||||||
|
'album/<slug:slug>/',
|
||||||
|
views.AlbumDetailView.as_view(),
|
||||||
|
name='album_detail',
|
||||||
|
),
|
||||||
path("tracks/", views.TrackListView.as_view(), name='tracks_list'),
|
path("tracks/", views.TrackListView.as_view(), name='tracks_list'),
|
||||||
path(
|
path(
|
||||||
'tracks/<slug:slug>/',
|
'tracks/<slug:slug>/',
|
||||||
|
|||||||
@ -49,3 +49,15 @@ class ArtistDetailView(generic.DetailView):
|
|||||||
|
|
||||||
class AlbumListView(generic.ListView):
|
class AlbumListView(generic.ListView):
|
||||||
model = Album
|
model = Album
|
||||||
|
|
||||||
|
|
||||||
|
class AlbumDetailView(generic.DetailView):
|
||||||
|
model = Album
|
||||||
|
slug_field = 'uuid'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context_data = super().get_context_data(**kwargs)
|
||||||
|
# context_data['charts'] = ChartRecord.objects.filter(
|
||||||
|
# track__album=self.object, rank__in=[1, 2, 3]
|
||||||
|
# )
|
||||||
|
return context_data
|
||||||
|
|||||||
@ -23,11 +23,12 @@ def lookup_artist_from_tadb(name: str) -> dict:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
results = json.loads(response.content)
|
results = json.loads(response.content)
|
||||||
artist = results['artists'][0]
|
if results['artists']:
|
||||||
|
artist = results['artists'][0]
|
||||||
|
|
||||||
artist_info['biography'] = artist['strBiographyEN']
|
artist_info['biography'] = artist['strBiographyEN']
|
||||||
artist_info['genre'] = artist['strGenre']
|
artist_info['genre'] = artist['strGenre']
|
||||||
artist_info['mood'] = artist['strMood']
|
artist_info['mood'] = artist['strMood']
|
||||||
artist_info['thumb_url'] = artist['strArtistThumb']
|
artist_info['thumb_url'] = artist['strArtistThumb']
|
||||||
|
|
||||||
return artist_info
|
return artist_info
|
||||||
|
|||||||
78
vrobbler/templates/music/album_detail.html
Normal file
78
vrobbler/templates/music/album_detail.html
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
{% extends "base_list.html" %}
|
||||||
|
{% load mathfilters %}
|
||||||
|
|
||||||
|
{% block title %}{{object.name}}{% endblock %}
|
||||||
|
|
||||||
|
{% block lists %}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
{% if object.cover_image %}
|
||||||
|
<p style="float:left; width:302px; padding:0; border: 1px solid #ccc">
|
||||||
|
<img src="{{object.cover_image.url}}" width=300 height=300 />
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<p>{{object.scrobbles.count}} scrobbles</p>
|
||||||
|
{% if charts %}
|
||||||
|
<p>{% for chart in charts %}<em><a href="{{chart.link}}">{{chart}}</a></em>{% if forloop.last %}{% else %} | {% endif %}{% endfor %}</p>
|
||||||
|
{% endif %}
|
||||||
|
<div class="col-md">
|
||||||
|
<h3>Top tracks</h3>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Rank</th>
|
||||||
|
<th scope="col">Track</th>
|
||||||
|
<th scope="col">Artist</th>
|
||||||
|
<th scope="col">Count</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for track in object.tracks %}
|
||||||
|
<tr>
|
||||||
|
<td>{{rank}}#1</td>
|
||||||
|
<td><a href="{{track.get_absolute_url}}">{{track.title}}</a></td>
|
||||||
|
<td><a href="{{track.artist.get_absolute_url}}">{{track.artist}}</a></td>
|
||||||
|
<td>{{track.scrobble_count}}</td>
|
||||||
|
<td>
|
||||||
|
<div class="progress-bar" style="margin-right:5px;">
|
||||||
|
<span class="progress-bar-fill" style="width: {{track.scrobble_count|mul:10}}%;"></span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md">
|
||||||
|
<h3>Last scrobbles</h3>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Date</th>
|
||||||
|
<th scope="col">Track</th>
|
||||||
|
<th scope="col">Artist</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for scrobble in object.scrobbles %}
|
||||||
|
<tr>
|
||||||
|
<td>{{scrobble.timestamp}}</td>
|
||||||
|
<td><a href="{{scrobble.track.get_absolute_url}}">{{scrobble.track.title}}</a></td>
|
||||||
|
<td><a href="{{scrobble.track.artist.get_absolute_url}}">{{scrobble.track.artist.name}}</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -6,11 +6,18 @@
|
|||||||
{% block lists %}
|
{% block lists %}
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for album in artist.album_set.all %}
|
|
||||||
{% if album.cover_image %}
|
{% if object.thumbnail %}
|
||||||
<p style="width:150px; float:left;"><img src="{{album.cover_image.url}}" width=150 height=150 /></p>
|
<p style="float:left; width:302px; padding:0; border: 1px solid #ccc">
|
||||||
|
<img src="{{artist.thumbnail.url}}" width=300 height=300 />
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
{% if object.album_set.first.cover_image %}
|
||||||
|
<p style="float:left; width:302px; padding:0; border: 1px solid #ccc">
|
||||||
|
<img src="{{object.album_set.first.cover_image.url}}" width=300 height=300 />
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<p>{{artist.scrobbles.count}} scrobbles</p>
|
<p>{{artist.scrobbles.count}} scrobbles</p>
|
||||||
@ -25,6 +32,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Rank</th>
|
<th scope="col">Rank</th>
|
||||||
<th scope="col">Track</th>
|
<th scope="col">Track</th>
|
||||||
|
<th scope="col">Album</th>
|
||||||
<th scope="col">Count</th>
|
<th scope="col">Count</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -33,7 +41,8 @@
|
|||||||
{% for track in object.tracks %}
|
{% for track in object.tracks %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{rank}}#1</td>
|
<td>{{rank}}#1</td>
|
||||||
<td>{{track.title}}</td>
|
<td><a href="{{track.get_absolute_url}}">{{track.title}}</a></td>
|
||||||
|
<td><a href="{{track.album.get_absolute_url}}">{{track.album}}</a></td>
|
||||||
<td>{{track.scrobble_count}}</td>
|
<td>{{track.scrobble_count}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="progress-bar" style="margin-right:5px;">
|
<div class="progress-bar" style="margin-right:5px;">
|
||||||
@ -63,8 +72,8 @@
|
|||||||
{% for scrobble in object.scrobbles %}
|
{% for scrobble in object.scrobbles %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{scrobble.timestamp}}</td>
|
<td>{{scrobble.timestamp}}</td>
|
||||||
<td>{{scrobble.track.title}}</td>
|
<td><a href="{{scrobble.track.get_absolute_url}}">{{scrobble.track.title}}</a></td>
|
||||||
<td>{{scrobble.track.album.name}}</td>
|
<td><a href="{{scrobble.track.album.get_absolute_url}}">{{scrobble.track.album.name}}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -22,14 +22,16 @@
|
|||||||
<th scope="col">Date</th>
|
<th scope="col">Date</th>
|
||||||
<th scope="col">Track</th>
|
<th scope="col">Track</th>
|
||||||
<th scope="col">Album</th>
|
<th scope="col">Album</th>
|
||||||
|
<th scope="col">Artist</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for scrobble in object.scrobble_set.all %}
|
{% for scrobble in object.scrobble_set.all %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{scrobble.timestamp}}</td>
|
<td>{{scrobble.timestamp}}</td>
|
||||||
<td>{{scrobble.track.title}}</td>
|
<td><a href="{{scrobble.track.get_absolute_url}}">{{scrobble.track.title}}</a></td>
|
||||||
<td>{{scrobble.track.album.name}}</td>
|
<td><a href="{{scrobble.track.album.get_absolute_url}}">{{scrobble.track.album}}</a></td>
|
||||||
|
<td><a href="{{scrobble.track.artist.get_absolute_url}}">{{scrobble.track.artist}}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user