From 4beb2d677489e7ad3101ef17c72d3a0907402229 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 8 Dec 2013 16:20:43 +0100 Subject: [PATCH] Handle client prefs changes --- templates/profile.html | 7 +++++-- user.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/templates/profile.html b/templates/profile.html index 2bed2f3..9477138 100755 --- a/templates/profile.html +++ b/templates/profile.html @@ -19,8 +19,11 @@
  • Change password
  • -{% if clients %} -

    Known streaming clients

    +{% if clients.count() %} +

    Clients

    +

    Here's a list of clients you used to stream music. If you want to use transcoding or downsampling with one of them (for instance using a low bitrate on + mobile connections to reduce used bandwidth), but the client doesn't provide options to do so, you can set default values here. They'll only be used if no + transcoding/downsampling is requested by the client.

    diff --git a/user.py b/user.py index 8b38919..4edbcb5 100755 --- a/user.py +++ b/user.py @@ -26,6 +26,26 @@ def user_profile(): prefs = ClientPrefs.query.filter(ClientPrefs.user_id == uuid.UUID(session.get('userid'))) return render_template('profile.html', user = UserManager.get(session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs) +@app.route('/user/me', methods = [ 'POST' ]) +def update_clients(): + clients_opts = {} + for client in set(map(lambda k: k.rsplit('_', 1)[0],request.form.keys())): + clients_opts[client] = { k.rsplit('_', 1)[1]: v for k, v in filter(lambda (k, v): k.startswith(client), request.form.iteritems()) } + app.logger.debug(clients_opts) + + for client, opts in clients_opts.iteritems(): + prefs = ClientPrefs.query.get((uuid.UUID(session.get('userid')), client)) + if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]: + db_sess.delete(prefs) + continue + + prefs.format = opts['format'] if 'format' in opts and opts['format'] else None + prefs.bitrate = int(opts['bitrate']) if 'bitrate' in opts and opts['bitrate'] else None + + db_sess.commit() + flash('Clients preferences updated.') + return user_profile() + @app.route('/user/changemail', methods = [ 'GET', 'POST' ]) def change_mail(): user = UserManager.get(session.get('userid'))[1]
    ClientFormatMax bitrateForget