Beispiel #1
0
    RouteHelper.finish_attach(route_id, attachment_id)
    return redirect(url_for('route.route_page', route_id=route_id))


@route_blueprint.route('/route/<route_id>/rate/', methods=['POST'])
@login_required
def rate(route_id):
    try:
        route_id = ObjectId(route_id)
        assert 'score' in request.form
        score = int(request.form['score'])
        assert RouteHelper.get(route_id)
    except AssertionError, e:
        return redirect(url_for('home.home'))

    RouteHelper.rate(route_id, score)
    return redirect(url_for('route.route_page', route_id=route_id))


@route_blueprint.route('/route/<route_id>/attach/<attachment_id>/like/', methods=['POST'])
@login_required
def like_attach(route_id, attachment_id):
    try:
        route_id = ObjectId(route_id)
        attachment_id = ObjectId(attachment_id)
        assert RouteHelper.get(route_id)
        assert AttachmentHelper.get(attachment_id)
        state, number = AttachmentHelper.toggle_vote(attachment_id)
    except AssertionError:
        return jsonify({'code': 0})