Skip to content

Commit

Permalink
new: Artist type filters
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Dec 2, 2018
1 parent 470085c commit c52ad1e
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 85 deletions.
2 changes: 1 addition & 1 deletion mishmash/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __parse_version(v): # pragma: nocover
return ver, rel, ver_info


__version__ = "0.3b8"
__version__ = "0.3b9"
__release_name__ = ""
__years__ = "2013-2018"

Expand Down
13 changes: 13 additions & 0 deletions mishmash/web/static/js/mishmash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function searchParamsFromAlbumTypeChecks() {
var all_checked = true;
var search = "";

$(".type-checkbox").each(function(i) {
all_checked &= this.checked;
search += (search ? "&" : "?") +
("type=" + (this.checked ? this.name : ("!" + this.name)));
});

return !all_checked ? search : "";
}
6 changes: 2 additions & 4 deletions mishmash/web/templates/album.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<div class="row">
Expand Down Expand Up @@ -67,5 +66,4 @@
</div>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
51 changes: 5 additions & 46 deletions mishmash/web/templates/albums.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<div class="container">
Expand All @@ -8,6 +7,7 @@
<span tal:repeat="L album_decades"><a href="#${L}"><strong>${L}</strong></a>&nbsp;</span>
</div>
</div>

<div class="row text-center">
<div class="col albums-box">
<span tal:repeat="T album_types.items()" class="albums-type-checkbox">
Expand All @@ -29,53 +29,12 @@
</span>
</div>

<script src="${request.static_url('mishmash.web:static/js/mishmash.js')}"></script>
<script>

$('.type-checkbox').on('change', function() {
var new_search = "";
var all_checked = true;

$(".type-checkbox").each(function(i) {
all_checked &= this.checked;
new_search += (new_search ? "&" : "?") + ("type=" + (this.checked ? this.name : ("!" + this.name)));
});

if (!all_checked) {
window.location.search = new_search;
}
else {
window.location.search = "";
}
window.location.search = searchParamsFromAlbumTypeChecks();
});
/*
$(function(){
var Url;
$("input[type='checkbox']").click(function(){
Url = 'http://myhomepage.com?';
$.each($("input[type='checkbox']"),function(){

if(this.checked)
{
var html = $.trim($(this).parent().html().replace('<input type="checkbox"> ',''));
Url = Url + html + "=1&";
}

});
console.log(Url);
$.ajax({
url: Url,
success: function(data) {
$('#result').html(data);
alert('Load was performed.');
}
});

});

});
*/
</script>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
8 changes: 3 additions & 5 deletions mishmash/web/templates/artist.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<div id="artist-header">
Expand All @@ -10,7 +9,7 @@
<ul class="nav nav-tabs">
<li tal:repeat="t tabs" class="${'active' if t[2]
else ('' if t[3] else 'disabled')}">

<a tal:define="tab_url '%s?album_tab=%s' % (request.path_url, t[0]) if t[3]
else 'javascript: void(0)'"
href="${tab_url}">${t[1]}</a>
Expand Down Expand Up @@ -42,5 +41,4 @@
</table>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
32 changes: 25 additions & 7 deletions mishmash/web/templates/artists.pt
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<div class="container">
<div class="row text-center">
<div class="col-xs-12">
<span tal:repeat="L artist_keys"><a href="#${L}">${L}</a>&nbsp;</span>
</div>
</div>
</div>

<div class="row text-center">
<div class="col-xs-12">
<span tal:repeat="L artist_keys"><a href="#${L}">${L}</a>&nbsp;</span>
</div>
<div class="col albums-box">
<span tal:repeat="T artist_types.items()" class="artist-type-checkbox">
<input type="checkbox" class="type-checkbox" id="${T[0]}" name="${T[0]}"
tal:attributes="checked T[1]['active']"/>
<label for="${T[0]}">${T[0]}</label>
</span>
</div>
</div>

<span tal:repeat="L artist_keys">
Expand All @@ -19,6 +30,13 @@
</ul>
</span>

<script src="${request.static_url('mishmash.web:static/js/mishmash.js')}"></script>
<script>
$('.type-checkbox').on('change', function() {
console.log(searchParamsFromAlbumTypeChecks());
window.location.search = searchParamsFromAlbumTypeChecks();
});
</script>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
6 changes: 2 additions & 4 deletions mishmash/web/templates/home.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<h3>Browse:</h3>
Expand All @@ -16,6 +15,5 @@
</div>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>

6 changes: 2 additions & 4 deletions mishmash/web/templates/new_music.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<table class='table-unstyled table-condensed'
Expand All @@ -17,5 +16,4 @@
</table>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
6 changes: 2 additions & 4 deletions mishmash/web/templates/search_results.pt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<metal:block use-macro="main_template">
<div metal:fill-slot="content">
<metal:block use-macro="main_template"><div metal:fill-slot="content">
<!--! begin content -->

<div tal:condition="artists">
Expand Down Expand Up @@ -30,5 +29,4 @@
</div>

<!--! end content -->
</div>
</metal:block>
</div></metal:block>
32 changes: 22 additions & 10 deletions mishmash/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def allArtistsView(request):

buckets = set()
artist_dict = {}
artist_types = {}

def _whichBucket(name):
first_l = name[0].upper()
Expand All @@ -65,12 +66,21 @@ def _whichBucket(name):
buckets.add(first_l)
return first_l

active_types = _getActiveAlbumTypes(request.params)
session = request.DBSession
for artist in session.query(Artist)\
.order_by(Artist.sort_name).all():

types = set([a.type for a in artist.albums])
print("TYPES: ", types)
types = set([alb.type for alb in artist.albums])
for t in types:
if t not in artist_types:
artist_types[t] = {
"active": t in active_types,
}

if not active_types.intersection(types):
continue

bucket = _whichBucket(artist.sort_name)
if bucket not in artist_dict:
artist_dict[bucket] = []
Expand All @@ -96,8 +106,7 @@ def _whichBucket(name):
buckets.remove(OTHER)
buckets.append(OTHER)

return ResponseDict(artist_keys=buckets,
artist_dict=artist_dict)
return ResponseDict(artist_keys=buckets, artist_dict=artist_dict, artist_types=artist_types)


@view_config(route_name="artist", renderer="templates/artist.pt",
Expand Down Expand Up @@ -223,12 +232,7 @@ def allAlbumsView(request):
album_dict = {}
album_types = {}

inc_types = set([p for p in request.params.getall("type") if p[0] != '!'])
exc_types = set([p[1:] for p in request.params.getall("type") if p[0] == '!'])
active_types = set(ALBUM_TYPE_IDS).difference(exc_types)
if inc_types:
active_types = active_types.intersection(inc_types)

active_types = _getActiveAlbumTypes(request.params)
session = request.DBSession
for album in session.query(Album)\
.order_by(Album.original_release_date).all():
Expand All @@ -253,3 +257,11 @@ def allAlbumsView(request):

return ResponseDict(album_decades=buckets, album_dict=album_dict, album_types=album_types)


def _getActiveAlbumTypes(params):
inc_types = set([p for p in params.getall("type") if p[0] != '!'])
exc_types = set([p[1:] for p in params.getall("type") if p[0] == '!'])
active_types = set(ALBUM_TYPE_IDS).difference(exc_types)
if inc_types:
active_types = active_types.intersection(inc_types)
return active_types

0 comments on commit c52ad1e

Please sign in to comment.