Skip to content
Browse files

[mq]: jsify.patch

  • Loading branch information...
1 parent 14b52d4 commit 3dcc43cfae72180856b93ec2f8ead70eb009cc4e Tom Willis committed
View
15 CHANGES.txt
@@ -1,3 +1,18 @@
+0.6
+---
+
+- replace chameleon templates with mako and jquery-tmpl(temporary
+ until jquery-ui decides what they are going to endorse)
+- replaced player with jPlayer
+- upgraded jquery and jquery-ui dependencies
+-
+
+
+0.5.1.1
+-------
+
+- port to pyramid
+
0.5.1
-----
View
2 README.txt
@@ -3,7 +3,7 @@
=========
Spazzer is a web based music portal application. It's written in
-python, it runs under WSGI, it's built on top of bfg.
+python, it runs under WSGI, it's built on top of pyramid.
View
2 setup.py
@@ -16,7 +16,7 @@
"PasteScript>=1.7.3"]
setup(name = 'spazzer',
- version = '0.5.1',
+ version = '0.6',
description = 'spazzer',
long_description = README + '\n\n' + CHANGES,
classifiers = [
View
10 spazzer/web/templates/artist.pt
@@ -1,10 +0,0 @@
-<ul xmlns:tal="http://xml.zope.org/namespaces/tal"
- id="artist-list" class="data-list list">
- <li class="artist-item" tal:repeat="item items">
- <h3><a class="artist-header"
- href="${context.get_url(request)}detail?artist=${request.url_quote(unicode(item))}">${unicode(item)}</a></h3>
- <div class="artist-content">
- ${unicode(item)} content pane
- </div>
- </li>
-</ul>
View
2 spazzer/web/templates/browse.mako
@@ -57,7 +57,7 @@
</div>
<div class="jp-title">
<ul>
- <li>Cro Magnon Man</li>
+ <li></li>
</ul>
</div>
<div class="jp-no-solution" style="display: none; ">
View
26 spazzer/web/templates/detail.pt
@@ -1,26 +0,0 @@
-<ul xmlns:tal="http://xml.zope.org/namespaces/tal"
- class="album-list data-list list">
- <li class="album-item" tal:repeat="item albums">
- <h3>${fat(item)}&nbsp;&nbsp;<a class="download-link" href="${'%s/download/?artist=%s&amp;album=%s' % (request.application_url,request.url_quote(unicode(artist.name if artist else '')) ,request.url_quote(unicode(item.name)))}">(download)</a></h3>
- <table class="album-table">
- <tr class="track-row"
- tal:repeat="track item.get_tracks()">
- <td class="index-cell">${repeat["track"].index + 1}</td>
- <td class="title-cell">
- <span tal:attributes="class 'relevant-track track-title' if track.on_compilation() and artist_context and track.artist == artist_context.name else 'track-title' " tal:content="ftt(track.on_compilation())(track)">track</span>
- </td>
- <td class="action-cell">
- <a class="download-link"
- href="${'%s/download/?track=%s' % (request.application_url,str(track.id))}">
- download
- </a>
- &nbsp;&nbsp;
- <a class="play-link"
- href="#" onclick="play('${'%s/download/?track=%s' % (request.application_url,str(track.id))}')">
- play
- </a>
- </td>
- </tr>
- </table>
- </li>
-</ul>
View
32 spazzer/web/templates/search.mako
@@ -55,7 +55,7 @@
</div>
<div class="jp-title">
<ul>
- <li>Cro Magnon Man</li>
+ <li></li>
</ul>
</div>
<div class="jp-no-solution" style="display: none; ">
@@ -78,23 +78,47 @@
<p class="info">
Artists whose name contains '${criteria}'
</p>
- <span>${artists|n}</span>
+ <div class="content"></div>
</div>
<div id="album-results" class="results">
<h3>Albums</h3>
<p class="info">
Albums whose name contains '${criteria}'
</p>
- <span>${albums|n}</span>
+ <div class="content"></div>
</div>
<div id="track-results" class="results">
<h3>Tracks</h3>
<p class="info">
Tracks whose title contains '${criteria}'
</p>
- <span>${tracks|n}</span>
+ <div class="content"></div>
</div>
</div>
+ % if results:
+ <script type="text/javascript">
+ var results = ${results|n};
+ </script>
+ %else:
+ <script type="text/javascript">
+ var results = {};
+ </script>
+ %endif
+ <script type="text/javascript">
+ $(function(){
+ $.UI.init_filter_widget("#filter-widget");
+ $.UI.init_player_widget("#player",
+ {
+ swfPath:"${request.application_url}/static/js/jQuery.jPlayer.2.1.0/"
+ });
+ });
+
+
+ function play(url){
+ $.UI.play(url);
+ }
+ </script>
+
<script type="text/javascript">
$(function(){
$.UI.init_search_results("#results");
View
20 spazzer/web/templates/static/detail.html
@@ -1,13 +1,23 @@
<ul class="album-list data-list list">
- {{each items}}
+ {{each(album_index, album) items}}
<li class="album-item">
- <h3>${$value.name}&nbsp;&nbsp;<a class="download-link" href="${$value.download_url}">(download)</a></h3>
+ <h3>${album.title}&nbsp;&nbsp;<a class="download-link" href="${album.download_url}">(download)</a></h3>
<table class="album-table">
- {{each $value.tracks}}
+ {{each album.tracks}}
<tr class="track-row">
<td class="index-cell">${$value.track}</td>
<td class="title-cell">
- <span tal:attributes="class 'relevant-track track-title' if track.on_compilation() and artist_context and track.artist == artist_context.name else 'track-title' " tal:content="ftt(track.on_compilation())(track)">${$value.title}</span>
+ {{if $value.on_compilation}}
+ {{if artist_context !=$value.artist}}
+ <span class="track-title">
+ {{else}}
+ <span class="track-title relevant-track">
+ {{/if}}
+ ${$value.title}</span>
+ {{else}}
+ <span class="track-title">${$value.title}</span>
+ {{/if}}
+
</td>
<td class="action-cell">
@@ -17,7 +27,7 @@
</a>
&nbsp;&nbsp;
<a class="play-link"
- href="#" onclick="play('${$value.download_url}')">
+ href="${$value.download_url}">
play
</a>
</td>
View
81 spazzer/web/templates/static/js/ui.js
@@ -1,39 +1,54 @@
/*ui logic for spazzer depends on jquery*/
(function($){
- var init_artist_header_click = function(selector, OPTIONS, render_cb){
+ var init_artist_view = function(selector, OPTIONS, render_cb){
/*handle click events on all child headers of selector present and future*/
- $(selector).find(OPTIONS.header_selector).live("click",
+ $(OPTIONS.header_selector, selector).live("click",
function(event){
event.preventDefault();
var content = $(event.target).closest(OPTIONS.item_selector).children(OPTIONS.content_selector);
var link = $(event.target);
var url = $(link).attr("href");
if(!$(content).is(":visible")){
+
$(content).html("<div>Loading....</div>").show("normal");
$.get(url,
function(data){
render_cb(content, data);
-
+
}
);
}else{
$(content).toggle("normal");
+ console.info("toggled");
}
});
+ /*handles click events on all play links*/
+ $(OPTIONS.play_link, selector).live("click",
+ function(event){
+ event.preventDefault();
+ var url = $(event.target).attr("href");
+ $.UI.play(url);
+ });
};
var template_cache = {};
- var render = function(template, data, container){
- /*handles template caching*/
+ var render = function(template, data, container, cb){
+ /*handles template caching
+ * template: url to template to fetched
+ * data: data to use to render the template
+ * container: container to insert template result in to
+ * cb: callback to call when rendering is done*/
var x = function(){
- console.info("rendering data with template " + template);
- $(container).hide("fast").html($.tmpl(template, data)).show("normal");
+ var content = $.tmpl(template, data);
+ $(container).hide("fast").html(content).show("normal");
+ if(cb){
+ cb();
+ }
};
if(!template_cache[template]){
$.get(template,function(data){
- console.info("fetched template: " + template);
template_cache[template] = $.template(template, data);
x();
});
@@ -51,7 +66,9 @@
header_selector: ".artist-header",
list_selector: ".artist-list",
artist_list_template: "/static/artist-list.html",
- detail_template: "/static/detail.html"
+ detail_template: "/static/detail.html",
+ tracks_template: "/static/tracks.html",
+ play_link:".play-link"
};
var OPTIONS = $.extend(DEFAULT_OPTIONS, options || {});
@@ -62,10 +79,14 @@
};
var render_artist_list = function(data, status, xhr){
- render(OPTIONS.artist_list_template, data, $("#panel-content", selector));
+ render(OPTIONS.artist_list_template, data, $("#panel-content", selector),
+ function(){
+ $(OPTIONS.content_selector).hide();
+ $(OPTIONS.content_selector).html("<p/>");
+ });
};
- init_artist_header_click(selector, OPTIONS, render_artist_content_cb);
+ init_artist_view(selector, OPTIONS, render_artist_content_cb);
$(selector).tabs(
{show: function(){
@@ -73,9 +94,6 @@
}, //end show
load: function(event,ui){
- $(OPTIONS.list_selector).hide();
- $(OPTIONS.content_selector).hide();
- $(OPTIONS.content_selector).html("<p/>");
},//end load
ajaxOptions:{
success:render_artist_list
@@ -99,11 +117,42 @@
item_selector: ".artist-item",
content_selector: ".artist-content",
header_selector: ".artist-header",
- list_selector: ".artist-list"
+ list_selector: ".artist-list",
+ artist_list_template: "/static/artist-list.html",
+ detail_template: "/static/detail.html",
+ tracks_template: "/static/tracks.html",
+ play_link:".play-link"
};
var OPTIONS = $.extend(DEFAULT_OPTIONS, options || {});
+ var render_artist_list = function(data){
+ render(OPTIONS.artist_list_template, data, $(".content",$("#artist-results", "#results")),
+ function(){
+ $(OPTIONS.content_selector).hide();
+ $(OPTIONS.content_selector).html("<p/>");
+ });
+
+ };
+ var render_artist_content_cb = function(container, data){
+ render(OPTIONS.detail_template, data, container);
+
+ };
+
+ var render_album_list = function(data){
+ render(OPTIONS.detail_template, data, $(".content",$("#album-results", "#results")));
+ };
+
+ var render_track_list = function(data){
+ render(OPTIONS.tracks_template, data, $(".content",$("#track-results", "#results")));
+ };
+
$(selector).find(OPTIONS.content_selector).hide();
- init_artist_header_click(selector, OPTIONS);
+ init_artist_view(selector, OPTIONS, render_artist_content_cb);
+
+ if(window.results){
+ render_artist_list({items:window.results.artists});
+ render_album_list({items:window.results.albums});
+ render_track_list({items:window.results.tracks});
+ }
}
};
})(jQuery);
View
14 spazzer/web/templates/static/tracks.html
@@ -0,0 +1,14 @@
+<table class="track-content data-list list track-list">
+ {{each items}}
+ <tr class="track-row">
+ <td class="track-cell">${$value.title} by ${$value.artist}</td>
+ <td class="action-cell"><a class="download-link" href="${$value.download_url}">download</a>
+ &nbsp;&nbsp;
+ <a class="play-link"
+ href="${$value.download_url}">
+ play
+ </a>
+ </td>
+ </tr>
+ {{/each}}
+</table>
View
12 spazzer/web/templates/tracks.pt
@@ -1,12 +0,0 @@
-<table xmlns:tal="http://xml.zope.org/namespaces/tal" class="track-content data-list list track-list">
- <tr class="track-row" tal:repeat="track tracks">
- <td class="track-cell" tal:content="ftt(track)">track</td>
- <td class="action-cell"><a class="download-link" href="${'%s/download/?track=%s' % (request.application_url,str(track.id))}">download</a>
- &nbsp;&nbsp;
- <a class="play-link"
- href="#" onclick="play('${'%s/download/?track=%s' % (request.application_url,str(track.id))}')">
- play
- </a>
- </td>
- </tr>
-</table>
View
113 spazzer/web/views.py
@@ -3,12 +3,11 @@
"""
from webob import Response
from webob.exc import HTTPNotFound
-from pyramid.chameleon_zpt import render_template
from urllib import quote as url_quote
from pyramid.view import view_config
from pyramid.compat import json
import models
-
+import mimetypes
def quote(s):
return url_quote(s.encode("utf-8"))
@@ -32,13 +31,10 @@ def quote(s):
keys.reverse()
keys.append("[#]")
-
-@view_config(context=models.CollectionModel, name="search",
- renderer="search.mako")
-def search(context, request):
- request.url_quote = url_quote
+def get_search_results(context, request):
+ request.url_quote = quote
if "POST" in request.params:
- criteria = request.POST.get("criteria")
+ criteria = request.params.get("criteria")
artists = context.search_artists(criteria)
albums = context.search_albums(criteria)
tracks = context.search_tracks(criteria)
@@ -47,21 +43,45 @@ def search(context, request):
albums = []
tracks = []
criteria = None
+ return dict(artists=artists, albums=albums, tracks=tracks, criteria=criteria)
- return {
+@view_config(context=models.CollectionModel, name="search",
+ renderer="search.mako")
+def search(context, request):
+ sr = get_search_results(context, request)
+ artists, albums, tracks, criteria = sr["artists"], sr["albums"], sr["tracks"], sr["criteria"]
+ return dict(results=json.dumps({
"artists": render_artists(artists,
request,
context),
"albums": render_albums(context,
request,
albums or [],
+ show_artist=True)["items"],
+ "tracks": render_tracks(tracks,
+ request,
show_artist=True),
+ "criteria": criteria}), criteria=criteria)
+
+
+@view_config(context=models.CollectionModel, name="search_json",
+ renderer="json")
+def search_json(context, request):
+ sr = get_search_results(context, request)
+ artists, albums, tracks, criteria = sr["artists"], sr["albums"], sr["tracks"], sr["criteria"]
+ return {
+ "artists": render_artists(artists,
+ request,
+ context),
+ "albums": render_albums(context,
+ request,
+ albums or [],
+ show_artist=True)["items"],
"tracks": render_tracks(tracks,
request,
show_artist=True),
"criteria": criteria}
-
@view_config(context=models.SiteModel, renderer="browse.mako")
def home(context, request):
return browse(context["collection"], request)
@@ -95,9 +115,9 @@ def view_manage(context, request):
@view_config(context=models.CollectionModel, name="data", renderer="json")
def view_artist(context, request):
- request.url_quote = url_quote
+ request.url_quote = quote
items = context.list_items(request)
- return render_artists(items, request, context)
+ return dict(items=render_artists(items, request, context))
@view_config(context=models.CollectionModel, name="detail", renderer="json")
@@ -120,7 +140,6 @@ def render_albums(context,
show_artist=False,
artist_context=None):
- request.url_quote = quote
if albums is None:
key = request.params.get("artist")
try:
@@ -143,35 +162,38 @@ def render_albums(context,
fat = f_album_title(show_artist)
ftt = f_track_title
- result=dict(items=[], artist=artist.name)
+ result = dict(items=[], artist_context=artist.name if artist else "")
for album in albums:
item = dict(title=fat(album),
name=album.name,
year=album.year,
download_url="%s/download/?artist=%s&;album=%s" % \
(request.application_url,
- request.url_quote(artist.name if artist else ""),
- request.url_quote(album.name)),
+ quote(artist.name if artist else ""),
+ quote(album.name)),
tracks=[]
)
for track in album.get_tracks():
- compilation = track.on_compilation()
- item["tracks"].append(dict(on_compilation=compilation,
- download_url="%s/download/?track=%s" % \
- (request.application_url,
- str(track.id)),
- track=track.track,
- name=track.title,
- title=ftt(compilation)(track),
- year=track.year,
- artist=track.artist,
- album=track.album))
+ item["tracks"].append(track_to_track_view(track, request, ftt))
result["items"].append(item)
-
return result
+def track_to_track_view(track, request, ftt):
+ compilation = track.on_compilation()
+ return dict(on_compilation=compilation,
+ download_url="%s/download/?track=%s" % \
+ (request.application_url,
+ str(track.id)),
+ track=track.track,
+ name=track.title,
+ title=ftt(compilation)(track),
+ year=track.year,
+ artist=track.artist,
+ album=track.album)
+
+
@view_config(context=models.DownloadModel)
def serve(context, request):
"""
@@ -181,10 +203,7 @@ def serve(context, request):
result = context.get_file(request)
if result:
buf, length, fname = result
- try:
- return _serve(buf, length, fname)
- finally:
- buf.close()
+ return _serve(buf, length, fname)
else:
return HTTPNotFound()
@@ -193,35 +212,32 @@ def _serve(filebuf, filename, filesize):
"""
request builder for serving files
"""
- response = Response(content_type="binary/octet-stream")
+ response = Response(conditional_response=True,
+ content_type=mimetypes.guess_type(filename)[0] \
+ or "binary/octet-stream")
response.headers.add("Content-Disposition",
"attachment; filename=%s; size=%d" % (
filename, filesize))
-
- response.body = filebuf.read()
+ response.app_iter = filebuf
return response
def render_artists(items, request, context):
- request.url_quote = quote
base_url = context.get_url(request)
-
item_views = [dict(name=unicode(item),
- detail_url="%sdetail?artist=%s" % (base_url, unicode(item))) \
+ detail_url="%sdetail?artist=%s" \
+ % (base_url, quote(item.name))) \
for item in items]
- return dict(items=item_views)
+ return item_views
def render_tracks(items, request, show_artist=False):
"""
render functions assemble pieces from the context
"""
- request.url_quote = quote
-
- return render_template("templates/tracks.pt",
- tracks=items,
- request=request,
- ftt=f_track_title(show_artist))
+ ftt = f_track_title
+ return [track_to_track_view(item, request, ftt) \
+ for item in items]
def f_album_title(show_artist=True):
@@ -243,7 +259,12 @@ def f_track_title(show_artist=False):
_show = show_artist
def _x(track):
- track_title = track.title or u'(Unknown)'
+ try:
+ track_title = track.title or u'(Unknown)'
+ except:
+ print track
+ raise
+
if _show:
return u"%s by %s" % (track_title,
track.artist or u'(Unknown)')

0 comments on commit 3dcc43c

Please sign in to comment.
Something went wrong with that request. Please try again.