Exemple #1
0
def update_clients(uid):
	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)

	if uid == 'me':
		userid = uuid.UUID(session.get('userid'))
	else:
		if not UserManager.get(store, session.get('userid'))[1].admin or not UserManager.get(store, uid)[0] is UserManager.SUCCESS:
			return redirect(url_for('index'))
		userid = uuid.UUID(uid)

	for client, opts in clients_opts.iteritems():
		prefs = store.get(ClientPrefs, (userid, client))
		if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
			store.remove(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

	store.commit()
	flash('Clients preferences updated.')
	return user_profile(uid)
Exemple #2
0
def update_clients(uid, user):
    clients_opts = {}
    for key, value in request.form.iteritems():
        if '_' not in key:
            continue
        parts = key.split('_')
        if len(parts) != 2:
            continue
        client, opt = parts
        if not client or not opt:
            continue

        if client not in clients_opts:
            clients_opts[client] = { opt: value }
        else:
            clients_opts[client][opt] = value
    app.logger.debug(clients_opts)

    for client, opts in clients_opts.iteritems():
        prefs = store.get(ClientPrefs, (user.id, client))
        if not prefs:
            continue

        if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
            store.remove(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

    store.commit()
    flash('Clients preferences updated.')
    return user_profile(uid, user)
Exemple #3
0
def update_clients(uid, user):
    clients_opts = {}
    for key, value in request.form.iteritems():
        if '_' not in key:
            continue
        parts = key.split('_')
        if len(parts) != 2:
            continue
        client, opt = parts
        if not client or not opt:
            continue

        if client not in clients_opts:
            clients_opts[client] = { opt: value }
        else:
            clients_opts[client][opt] = value
    app.logger.debug(clients_opts)

    for client, opts in clients_opts.iteritems():
        prefs = store.get(ClientPrefs, (user.id, client))
        if not prefs:
            continue

        if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
            store.remove(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

    store.commit()
    flash('Clients preferences updated.')
    return user_profile(uid, user)
Exemple #4
0
def delete_playlist():
    status, res = get_entity(request, Playlist)
    if not status:
        return res

    if res.user_id != request.user.id and not request.user.admin:
        return request.error_formatter(50, "You're not allowed to delete a playlist that isn't yours")

    store.remove(res)
    store.commit()
    return request.formatter({})
Exemple #5
0
def delete_playlist():
    status, res = get_entity(request, Playlist)
    if not status:
        return res

    if res.user_id != request.user.id and not request.user.admin:
        return request.error_formatter(
            50, "You're not allowed to delete a playlist that isn't yours")

    store.remove(res)
    store.commit()
    return request.formatter({})
Exemple #6
0
def playlist_delete(uid):
	try:
		uid = uuid.UUID(uid)
	except:
		flash('Invalid playlist id')
		return redirect(url_for('playlist_index'))

	playlist = store.get(Playlist, 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:
		store.remove(playlist)
		store.commit()
		flash('Playlist deleted')

	return redirect(url_for('playlist_index'))
Exemple #7
0
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 = store.get(ClientPrefs, (uuid.UUID(session.get('userid')), client))
		if 'delete' in opts and opts['delete'] in [ 'on', 'true', 'checked', 'selected', '1' ]:
			store.remove(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

	store.commit()
	flash('Clients preferences updated.')
	return user_profile()