Skip to content

Commit

Permalink
Proper category separation for the artists page.
Browse files Browse the repository at this point in the history
  • Loading branch information
karamanolev committed Sep 22, 2014
1 parent 9f58bf2 commit 4bebc88
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions home/info_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
(15, 'Interview'),
(16, 'Mixtape'),
(21, 'Unknown'),
(22, 'Concert Recording'),
(23, 'Demo'),
)


Expand Down
12 changes: 7 additions & 5 deletions static/whatify/home/artist.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<div class="artist-details-page">
<div artist-info artist="artist" size="250"></div>

<h2>Albums</h2>
<div ng-repeat="category in artist.categories">
<h2>{{ category.name }}</h2>

<div ng-repeat="torrentGroup in artist.torrent_groups.Album">
<div album-info torrent-group="torrentGroup" size="176" link-title></div>
<div class="unindent" album-playlist torrent-group="torrentGroup"
ng-if="torrentGroup.have === true"></div>
<div ng-repeat="torrentGroup in category.torrent_groups">
<div album-info torrent-group="torrentGroup" size="176" link-title></div>
<div class="unindent" album-playlist torrent-group="torrentGroup"
ng-if="torrentGroup.have === true"></div>
</div>
</div>

<p>
Expand Down
6 changes: 3 additions & 3 deletions static/whatify/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ angular.
var refreshInterval = null;
var showArtist = function(artist) {
var hasInProgress;
$.each(artist.torrent_groups, function(i, section) {
$.each(section, function(j, torrentGroup) {
$.each(artist.categories, function(i, category) {
$.each(category.torrent_groups, function(j, torrentGroup) {
if (angular.isNumber(torrentGroup.have)) {
hasInProgress = true;
return false;
Expand Down Expand Up @@ -228,7 +228,7 @@ angular.
directive('coverGrid', function() {
return {
template: '<div class="cover-grid"><a class="cover-grid-item" ' +
'ng-href="#/torrentGroups/{{ item.id }}" '+
'ng-href="#/torrentGroups/{{ item.id }}" ' +
'ng-repeat="item in torrentGroups"><div square-image src="item.wiki_image">' +
'</div><div class="title">{{ item.name }}</div><div class="artist">' +
'{{ item.joined_artists }}</div></a><a class="cover-grid-item"></a>' +
Expand Down
31 changes: 18 additions & 13 deletions whatify/response_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.http import urlquote

from WhatManager2.utils import get_artists, get_artists_list
from home import info_holder
from home.info_holder import WHAT_RELEASE_TYPES
from home.models import WhatTorrent, TransTorrent, ReplicaSet, WhatFileMetadataCache
from what_transcode.utils import html_unescape
from whatify.filtering import sort_filter_torrents
Expand Down Expand Up @@ -34,18 +34,23 @@ def get_artist_dict(artist, include_all=False):
assert not artist.is_shell, 'Can not get torrents for a shell artist'
torrent_groups = {t['groupId']: t for t in artist.info['torrentgroup']}
torrent_groups_have = get_torrent_groups_have(torrent_groups.keys(), True)

torrent_groups_data = {}
for releaseTypeId, releaseTypeName in info_holder.WHAT_RELEASE_TYPES:
items_list = []
for t in torrent_groups.values():
if t['releaseType'] != releaseTypeId:
continue
item_data = get_artist_group_dict(t)
item_data.update(torrent_groups_have[t['groupId']])
items_list.append(item_data)
torrent_groups_data[releaseTypeName] = items_list
data['torrent_groups'] = torrent_groups_data
torrent_groups = list(torrent_groups.values())
torrent_groups.sort(key=lambda g: g['groupYear'], reverse=True)

main_artist_groups = defaultdict(list)
for torrent_group in torrent_groups:
if any(artist.id == a['id'] for a in torrent_group['artists']):
item_data = get_artist_group_dict(torrent_group)
item_data.update(torrent_groups_have[torrent_group['groupId']])
main_artist_groups[torrent_group['releaseType']].append(item_data)
categories = []
for release_type in WHAT_RELEASE_TYPES:
if main_artist_groups[release_type[0]]:
categories.append({
'name': release_type[1],
'torrent_groups': main_artist_groups[release_type[0]],
})
data['categories'] = categories
data['tags'] = sorted(artist.info['tags'], key=lambda tag: tag['count'], reverse=True)
return data

Expand Down
5 changes: 3 additions & 2 deletions whatify/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from WhatManager2.utils import json_return_method
from home.models import get_what_client, ReplicaSet, DownloadLocation
from what_meta.models import WhatTorrentGroup, WhatArtist, WhatMetaFulltext
from what_transcode.utils import html_unescape
from whatify.response_gen import get_torrent_group_dict, get_torrent_groups_have, \
get_artist_dict, get_artist_alias_dict, get_image_cache_url
from whatify.utils import get_ids_to_download
Expand Down Expand Up @@ -133,8 +134,8 @@ def top10_torrent_groups(request):
group_set.add(torrent['groupId'])
results.append({
'id': torrent['groupId'],
'joined_artists': torrent['artist'],
'name': torrent['groupName'],
'joined_artists': html_unescape(torrent['artist']),
'name': html_unescape(torrent['groupName']),
'year': torrent['groupYear'],
'wiki_image': get_image_cache_url(torrent['wikiImage']),
})
Expand Down

0 comments on commit 4bebc88

Please sign in to comment.