Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2009-2011 Alexander Kojevnikov <alexander@kojevnikov.com> | ||
# | ||
# muspy is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# muspy is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with muspy. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
def arrange_for_table(items, columns): | ||
"""Prepare a list of items to show it in a table. | ||
Sort the items by columns, fill by rows. Return a list of rows. | ||
The algorithm is a bit tricky to allow for example this: | ||
|0 2 3| instead of |0 2 .| | ||
|1 . .| |1 3 .| | ||
""" | ||
L = len(items) | ||
N = columns | ||
M = 1 + (L - 1) // N | ||
return [[items[i + j * M - | ||
# Next line compensates for empty cells in the last row. | ||
max(0, j - L % N if i < M - 1 and L % N else 0)] | ||
if i * N + j < L else None | ||
for j in xrange(N)] | ||
for i in xrange(M)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
{% extends "base.html" %} | ||
{% block title %}Artists{% endblock %} | ||
{% block header %}Artists{% endblock %} | ||
{% block content %} | ||
|
||
{% if search %} | ||
{% if not found_artists %} | ||
<p>No artists matching your query.</p> | ||
{% else %} | ||
<p>Search results: <small>(click <img class="add_artist" src="/static/add.gif" alt="+"/> to follow the artist)</small></p> | ||
<div id="found_artists"> | ||
<ul> | ||
{% for artist in found_artists %} | ||
<li{% if artist.best_match %} class="best_match"{% endif %}> | ||
<a class="noborder" href="/artists-add?id={{ artist.id }}&search={{ search|urlencode }}"><img class="add_artist" src="/static/add.gif" alt="+" title="Add"/></a> | ||
<a href="/artist/{{ artist.id }}">{{ artist.name }}</a> | ||
{% if artist.disambiguation %} <small>({{ artist.disambiguation }})</small>{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
{% if artists_left %} | ||
<p><a href="/artists?search={{ search|urlencode }}{% if dontadd %}&dontadd=1{% endif %}&offset={{ artists_offset }}">{{ artists_left }} more artist{{ artists_left|pluralize }}</a></p> | ||
{% endif %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
<form action="/artists" method="post"> | ||
<p> | ||
Add a new artist or artists:<br/> | ||
<input type="text" id="search" name="search" size="50" maxlength="16384" value="{{ search }}"/> | ||
<input type="submit" id="add" value="{% if dontadd %}Search{% else %}Add{% endif %}"/> | ||
<input type="checkbox" id="dontadd" name="dontadd" value="1"{% if dontadd %} checked="checked"{% endif %}/> | ||
<label for="dontadd">Search, don't add</label> | ||
</p> | ||
<p> | ||
<small><strong>Hint:</strong> you can enter a comma-separated list of artists, for example: <em>Agalloch, Slumber, Lumsk</em></small> | ||
</p> | ||
<p>You can also <a href="/import">import artists</a> from your Last.fm profile.</p> | ||
</form> | ||
|
||
{% if importing %} | ||
<h2>Importing</h2> | ||
<p>These artists will be imported shortly:</p> | ||
<p>{{ importing }}</p> | ||
{% endif %} | ||
|
||
{% if pending %} | ||
<h2>Pending artists</h2> | ||
<p>These artists either could not be found or their names are ambiguous. <br/> | ||
Click on a name to search or select and remove the artists you don't want to follow.</p> | ||
<form id="form-pending" action="/artists-remove" method="post"> | ||
<table id="pending"> | ||
{% for row in pending_rows %} | ||
<tr> | ||
{% for name in row %} | ||
<td> | ||
{% if name %} | ||
<input type="checkbox" name="name" value="{{ name }}"/> <a href="/artists?search={{ name|urlencode }}&dontadd=1">{{ name }}</a> | ||
{% else %} | ||
| ||
{% endif %} | ||
</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
<div id="div-name-all"></div> | ||
<p><input type="submit" value="Remove"/> selected names</p> | ||
</form> | ||
{% endif %} | ||
|
||
<h2>Artists you are following:</h2> | ||
{% if artist_rows %} | ||
<form id="form-artists" action="/artists-remove" method="post"> | ||
<table id="artists"> | ||
{% for row in artist_rows %} | ||
<tr> | ||
{% for artist in row %} | ||
<td> | ||
{% if artist %} | ||
<input type="checkbox" name="id" value="{{ artist.artist_id }}"/> <a href="/artist/{{ artist.artist_id }}">{{ artist.name }}</a> | ||
{% else %} | ||
| ||
{% endif %} | ||
</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
<div id="div-id-all"></div> | ||
<p><input type="submit" value="Remove"/> selected artists</p> | ||
</form> | ||
{% else %} | ||
<p>You don't have any! Use the text box above to add your favourite artists | ||
to the list. You will receive a notification when one of the artists that you | ||
follow releases a new album.</p> | ||
{% endif %} | ||
|
||
{% endblock content %} | ||
|
||
{% block javascript %} | ||
<script type="text/javascript" src="/static/jquery-1.2.6.js"></script> | ||
<script type="text/javascript"> | ||
//<![CDATA[ | ||
$(function() { | ||
$("#search").focus(); | ||
|
||
$("#dontadd").click(function() { | ||
$("#add").val($("#dontadd").attr("checked") ? "Search" : "Add"); | ||
}); | ||
|
||
$("#div-name-all").html('<p><input type="checkbox" id="name-all"/> <label for="name-all">Select all</label></p>'); | ||
|
||
$("#div-id-all").html('<p><input type="checkbox" id="id-all"/> <label for="id-all">Select all</label></p>'); | ||
|
||
$("#name-all").click(function() { | ||
var checked_status = this.checked; | ||
$("input[@name=name]").each(function() { | ||
this.checked = checked_status; | ||
}); | ||
}); | ||
|
||
$("#id-all").click(function() { | ||
var checked_status = this.checked; | ||
$("input[@name=id]").each(function() { | ||
this.checked = checked_status; | ||
}); | ||
}); | ||
|
||
$("#form-pending").submit(function() { | ||
var checked = $("input[@name=name]:checked").length; | ||
if(checked < 2) return true; | ||
return confirm("Are you sure you want to remove " + | ||
checked.toString() + " artists?"); | ||
}); | ||
|
||
$("#form-artists").submit(function() { | ||
var checked = $("input[@name=id]:checked").length; | ||
if(checked < 2) return true; | ||
return confirm("Are you sure you want to remove " + | ||
checked.toString() + " artists?"); | ||
}); | ||
}); | ||
//]]> | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters