mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Basic playlist management from the web interface
Mainly to allow to set the public flag, because most clients don't handle it
This commit is contained in:
parent
70aeea67d7
commit
ed526f1cd7
72
playlist.py
Executable file
72
playlist.py
Executable file
@ -0,0 +1,72 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
from flask import request, session, flash, render_template, redirect, url_for
|
||||||
|
import uuid
|
||||||
|
from web import app
|
||||||
|
import db
|
||||||
|
|
||||||
|
@app.route('/playlist')
|
||||||
|
def playlist_index():
|
||||||
|
return render_template('playlists.html', mine = db.Playlist.query.filter(db.Playlist.user_id == uuid.UUID(session.get('userid'))),
|
||||||
|
others = db.Playlist.query.filter(db.Playlist.user_id != uuid.UUID(session.get('userid'))))
|
||||||
|
|
||||||
|
@app.route('/playlist/<uid>')
|
||||||
|
def playlist_details(uid):
|
||||||
|
try:
|
||||||
|
uid = uuid.UUID(uid) if type(uid) in (str, unicode) else uid
|
||||||
|
except:
|
||||||
|
flash('Invalid playlist id')
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
||||||
|
playlist = db.Playlist.query.get(uid)
|
||||||
|
if not playlist:
|
||||||
|
flash('Unknown playlist')
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
||||||
|
return render_template('playlist.html', playlist = playlist)
|
||||||
|
|
||||||
|
@app.route('/playlist/<uid>', methods = [ 'POST' ])
|
||||||
|
def playlist_update(uid):
|
||||||
|
try:
|
||||||
|
uid = uuid.UUID(uid)
|
||||||
|
except:
|
||||||
|
flash('Invalid playlist id')
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
||||||
|
playlist = db.Playlist.query.get(uid)
|
||||||
|
if not playlist:
|
||||||
|
flash('Unknown playlist')
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
||||||
|
if str(playlist.user_id) != session.get('userid'):
|
||||||
|
flash("You're not allowed to edit this playlist")
|
||||||
|
elif not request.form.get('name'):
|
||||||
|
flash('Missing playlist name')
|
||||||
|
else:
|
||||||
|
playlist.name = request.form.get('name')
|
||||||
|
playlist.public = request.form.get('public') in (True, 'True', 1, '1', 'on', 'checked')
|
||||||
|
db.session.commit()
|
||||||
|
flash('Playlist updated.')
|
||||||
|
|
||||||
|
return playlist_details(uid)
|
||||||
|
|
||||||
|
@app.route('/playlist/del/<uid>')
|
||||||
|
def playlist_delete(uid):
|
||||||
|
try:
|
||||||
|
uid = uuid.UUID(uid)
|
||||||
|
except:
|
||||||
|
flash('Invalid playlist id')
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
||||||
|
playlist = db.Playlist.query.get(uid)
|
||||||
|
if not playlist:
|
||||||
|
flash('Unknown playlist')
|
||||||
|
elif str(playlist.user_id) != session.get('userid'):
|
||||||
|
flash("You're not allowed to delete this playlist")
|
||||||
|
else:
|
||||||
|
db.session.delete(playlist)
|
||||||
|
db.session.commit()
|
||||||
|
flash('Playlist deleted')
|
||||||
|
|
||||||
|
return redirect(url_for('playlist_index'))
|
||||||
|
|
@ -15,7 +15,7 @@
|
|||||||
<h1>Supysonic</h1>
|
<h1>Supysonic</h1>
|
||||||
|
|
||||||
<p><a href="{{ url_for('index') }}">Home</a> |
|
<p><a href="{{ url_for('index') }}">Home</a> |
|
||||||
{% if session.userid %}<a href="{{ url_for('user_profile') }}">{{ session.username }}</a> - <a href="{{ url_for('logout') }}">Log out</a>
|
{% if session.userid %}<a href="{{ url_for('playlist_index') }}">Playlists</a> | <a href="{{ url_for('user_profile') }}">{{ session.username }}</a> - <a href="{{ url_for('logout') }}">Log out</a>
|
||||||
{% else %}<a href="{{ url_for('login') }}">Log in</a>
|
{% else %}<a href="{{ url_for('login') }}">Log in</a>
|
||||||
{% endif %}</p>
|
{% endif %}</p>
|
||||||
|
|
||||||
|
25
templates/playlist.html
Executable file
25
templates/playlist.html
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block body %}
|
||||||
|
<h2>Playlist "{{ playlist.name }}"</h2>
|
||||||
|
{% if playlist.user_id|str == session.get('userid') %}
|
||||||
|
<h3>Edit</h3>
|
||||||
|
<form method="post">
|
||||||
|
<table>
|
||||||
|
<tr><th>Name</th><th>Public</th><th></th></tr>
|
||||||
|
<tr>
|
||||||
|
<td><input type="text" name="name" value="{{ playlist.name }}" /></td>
|
||||||
|
<td><input type="checkbox" name="public" {% if playlist.public %}checked="true"{% endif %} /></td>
|
||||||
|
<td><input type="submit" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
<h3>Tracks</h3>
|
||||||
|
<table>
|
||||||
|
<tr><th>Artist</th><th>Title</th><th>Album</th><th>Length</th></tr>
|
||||||
|
{% for t in playlist.tracks %}
|
||||||
|
<tr><td>{{ t.album.artist.name }}</td><td>{{ t.title }}</td><td>{{ t.album.name }}</td><td>{{ t.duration_str() }}</td></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
33
templates/playlists.html
Executable file
33
templates/playlists.html
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block body %}
|
||||||
|
<h2>My playlists</h2>
|
||||||
|
{% if not mine.count() %}
|
||||||
|
<p>You don't have any playlists.</p>
|
||||||
|
{% else %}
|
||||||
|
<table>
|
||||||
|
<tr><th>Playlist</th><th>Tracks</th><th>Public</th><th></th></tr>
|
||||||
|
{% for p in mine %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ url_for('playlist_details', uid = p.id) }}">{{ p.name }}</a></td>
|
||||||
|
<td>{{ p.tracks|length }}</td>
|
||||||
|
<td><input type="checkbox" disabled="true" {% if p.public %}checked="true"{% endif %} /></td>
|
||||||
|
<td><a href="{{ url_for('playlist_delete', uid = p.id) }}">X</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
{% if others.count() %}
|
||||||
|
<h2>Others' playslits</h2>
|
||||||
|
<table>
|
||||||
|
<tr><th>Playlist</th><th>Owner</th><th>Tracks</th></tr>
|
||||||
|
{% for p in others %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ url_for('playlist_details', uid = p.id) }}">{{ p.name }}</a></td>
|
||||||
|
<td>{{ p.user.name }}</td>
|
||||||
|
<td>{{ p.tracks|length }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
5
web.py
5
web.py
@ -42,6 +42,10 @@ def init_and_login_check():
|
|||||||
def teardown(exception):
|
def teardown(exception):
|
||||||
db.session.remove()
|
db.session.remove()
|
||||||
|
|
||||||
|
@app.template_filter('str')
|
||||||
|
def to_string(obj):
|
||||||
|
return str(obj)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
stats = {
|
stats = {
|
||||||
@ -53,6 +57,7 @@ def index():
|
|||||||
|
|
||||||
import user
|
import user
|
||||||
import folder
|
import folder
|
||||||
|
import playlist
|
||||||
|
|
||||||
import api.system
|
import api.system
|
||||||
import api.browse
|
import api.browse
|
||||||
|
Loading…
Reference in New Issue
Block a user