Example #1
0
def comment_list(item_id=None):
    item = None

    if item_id:
        item = Item.query.filter_by(id=item_id).first()

        if item is None:
            return abort(404)
    else:
        if request.args.get('url'):
            item = Item.query.filter_by(url=request.args.get('url')).first()

            app.logger.debug('item by args[\'url\']: {0}'.format(item))

            if item:
                return redirect(url_for('comment_list', item_id=item.id))

        elif request.headers.get('Referer'):
            item = Item.query.filter_by(url=request.headers.get('Referer'))\
                    .first()

            if item:
                return redirect(url_for('comment_list', item_id=item.id))
            else:
                return abort(404)

    if item is None:
        return abort(404)

    comment_context = get_context(item)

    return render_template('talkatv/comment/list.html',
            comment_context=comment_context)
Example #2
0
def api_comments():
    if request.method == 'OPTIONS':
        # We're dealing with a pre-flight request
        return jsonify(status='OK', _allow_origin_cb=allow_all_origins)

    if request.method == 'POST':
        post_data = json.loads(request.data)

        item = Item.query.filter_by(id=post_data['item']).first()

        if not item:
            return abort(404)

        comment = post_comment(item, post_data, g.user)

        return jsonify(
                comment=comment.as_dict(),
                status='OK',
                _allow_origin_cb=allow_all_origins)

    if not request.args.get('item_url'):
        return abort(404)

    item = get_or_add_item(
            request.args.get('item_url'),
            request.args.get('item_title'))

    return_data = get_context(item)

    return jsonify(_allow_origin_cb=allow_all_origins,
            **return_data)