Exemplo n.º 1
0
def vote_up():
    """Records a vote in the up direction for the logged-in user.
    
    :param pqe: The ID of the :class:`~partify.models.PlayQueueEntry`
    :type pqe: integer
    :returns: The status of the request.
    :rtype: JSON string 
    """
    if 'pqe' in request.form:
        pqe = PlayQueueEntry.query.get(request.form['pqe'])
        if pqe is None:
            return jsonify(status="error",
                           message="A PQE by that ID does not exist!")
        if pqe.user_id == session['user']['id']:
            return jsonify(status="error",
                           message="You cannot vote on your own track!")
        vote = Vote.query.filter(
            and_(Vote.pqe_id == request.form['pqe'],
                 Vote.user_id == session['user']['id'])).first()
        if vote is None:
            vote = Vote(pqe_id=request.form['pqe'],
                        user_id=session['user']['id'],
                        direction=1)
            db.session.add(vote)
            db.session.commit()
        vote.direction = 1
        db.session.commit()
        ensure_mpd_playlist_consistency()
        return jsonify(status="ok")
    else:
        return jsonify(
            status="error",
            message=
            "You must specify the id of the PlayQueueEntry to vote for it!")
Exemplo n.º 2
0
def vote_down():
    """Records a vote in the down direction for the logged-in user.

    :param pqe: The ID of the :class:`~partify.models.PlayQueueEntry`
    :type pqe: integer
    :returns: The status of the request.
    :rtype: JSON string 
    """
    if 'pqe' in request.form:
        pqe = PlayQueueEntry.query.get(request.form['pqe'])
        if pqe is None:
            return jsonify(status="error", message="A PQE by that ID does not exist!")
        if pqe.user_id == session['user']['id']:
            return jsonify(status="error", message="You cannot vote on your own track!")
        vote = Vote.query.filter(and_(Vote.pqe_id == request.form['pqe'], Vote.user_id == session['user']['id'])).first()
        if vote is None:
            vote = Vote(pqe_id=request.form['pqe'], user_id=session['user']['id'], direction=-1)
            db.session.add(vote)
            db.session.commit()
        vote.direction = -1
        db.session.commit()
        ensure_mpd_playlist_consistency()
        return jsonify(status="ok")
    else:
        return jsonify(status="error", message="You must specify the id of the PlayQueueEntry to vote for it!")
Exemplo n.º 3
0
def on_startup():
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    mpd_event_listener = Process(target=on_playlist_update)
    mpd_event_listener.start()
Exemplo n.º 4
0
def on_startup():
    """Performs all of the actions needed to get the web server up and running."""
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    if not app.config['TESTING']:
        mpd_event_listener = Process(target=on_playlist_update)
        mpd_event_listener.start()
Exemplo n.º 5
0
def on_startup():
    """Performs all of the actions needed to get the web server up and running."""
    try:
        load_config_from_db()
    except:
        init_db()
        load_config_from_db()
    ipc.init_times()
    ipc.init_desired_player_state()
    ipc.init_mpd_lock()
    ensure_mpd_playlist_consistency()
    ipc.update_time('playlist', time.time())

    # Start the process which subscribes to MPD events using the IDLE command
    if not app.config['TESTING']:
        mpd_event_listener = Process(target=on_playlist_update)
        mpd_event_listener.start()