From 1b4415f98ca6883966244b5eecd722c2313f0b1e Mon Sep 17 00:00:00 2001 From: spl0k Date: Fri, 28 Jun 2013 12:39:46 +0200 Subject: [PATCH] Playlists enhancements - Playlists list sorted - Owner prefix for public playlists that aren't yours --- api/playlists.py | 10 +++++----- db.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/playlists.py b/api/playlists.py index fe6eea1..723c97c 100755 --- a/api/playlists.py +++ b/api/playlists.py @@ -1,7 +1,7 @@ # coding: utf-8 from flask import request -from sqlalchemy import or_ +from sqlalchemy import or_, func import uuid from web import app from db import Playlist, User, Track, session @@ -9,16 +9,16 @@ from . import get_entity @app.route('/rest/getPlaylists.view', methods = [ 'GET', 'POST' ]) def list_playlists(): - query = Playlist.query.filter(or_(Playlist.user_id == request.user.id, Playlist.public == True)) + query = Playlist.query.filter(or_(Playlist.user_id == request.user.id, Playlist.public == True)).order_by(func.lower(Playlist.name)) username = request.args.get('username') if username: if not request.user.admin: return request.error_formatter(50, 'Restricted to admins') - query = Playlist.query.join(User).filter(User.name == username) + query = Playlist.query.join(User).filter(User.name == username).order_by(func.lower(Playlist.name)) - return request.formatter({ 'playlists': { 'playlist': [ p.as_subsonic_playlist() for p in query ] } }) + return request.formatter({ 'playlists': { 'playlist': [ p.as_subsonic_playlist(request.user) for p in query ] } }) @app.route('/rest/getPlaylist.view', methods = [ 'GET', 'POST' ]) def show_playlist(): @@ -26,7 +26,7 @@ def show_playlist(): if not status: return res - info = res.as_subsonic_playlist() + info = res.as_subsonic_playlist(request.user) info['entry'] = [ t.as_subsonic_child(request.user) for t in res.tracks ] return request.formatter({ 'playlist': info }) diff --git a/db.py b/db.py index f229d79..17038f1 100755 --- a/db.py +++ b/db.py @@ -350,10 +350,10 @@ class Playlist(Base): user = relationship('User') tracks = relationship('Track', secondary = playlist_track_assoc) - def as_subsonic_playlist(self): + def as_subsonic_playlist(self, user): info = { 'id': str(self.id), - 'name': self.name, + 'name': self.name if self.user_id == user.id else '[%s] %s' % (self.user.name, self.name), 'owner': self.user.name, 'public': self.public, 'songCount': len(self.tracks),