示例#1
0
def fork_playlist(user, playlist_id):
    try:
        playlist = Playlist.query.filter(Playlist.id == playlist_id).first()
        print playlist
        new_playlist = Playlist(uid=user.id, name=playlist.name, parent=playlist.id, key=playlist.key, description=playlist.description)
        db_session.add(new_playlist)
        db_session.commit()
        new_playlist.initGit()
        fork_activity = Activity(user.id, " forked <a href='#playlist?id=%d'>%s</a>" % (new_playlist.id, playlist.name))
        db_session.add(fork_activity)
        db_session.commit()
        return jsonify(success=True, playlist=new_playlist.toDict(with_songs=True))
    except Exception as e:
        return jsonify(success=False, error='%s' % repr(e))
示例#2
0
def create_playlist(user):
    print 'tt'
    try:
        print 'test'
        name = request.form['name']
        if 'parent' in request.form:
            parent = int(request.form['parent'])
        else:
            parent = None
        playlist = Playlist(uid=user.id, name=name, parent=parent)
        db_session.add(playlist)
        db_session.commit()
        playlist.initGit() # xxx might not work
        fork_activity = Activity(user.id, " created <a href='#playlist?id=%d'>%s</a>" % (playlist.id, name))
        db_session.add(fork_activity)
        db_session.commit()
        return jsonify(success=True, playlist=playlist.toDict())
    except Exception as e:
        return jsonify(success=False, error='%s' % repr(e))