示例#1
0
def index(card_id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(card_id))
    references = db.session.query(Reference)
    references = references.filter(Reference.card == card)
    pager = Pager(references, card_id=card_id)
    return jsonify(pager, index=True)
示例#2
0
def update(id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(id))
    card.save(request_data(), g.user)
    db.session.commit()
    extract.delay(card.id)
    return jsonify(card)
示例#3
0
def index(parent_id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(parent_id))
    links = db.session.query(Link)
    links = links.filter(Link.parent == card)
    links = links.order_by(Link.offset.asc())
    pager = Pager(links, parent_id=parent_id)
    return jsonify(pager, index=True)
示例#4
0
文件: __init__.py 项目: 01-/storyweb
def handle_invalid(exc):
    body = {
        'status': 400,
        'name': 'Invalid Data',
        'message': unicode(exc),
        'errors': exc.asdict()
    }
    return jsonify(body, status=400)
示例#5
0
def get_session():
    return jsonify({
        'user':
        g.user if g.user.is_authenticated() else None,
        'logged_in':
        g.user.is_authenticated(),
        'is_admin':
        g.user.is_admin if g.user.is_authenticated() else False
    })
示例#6
0
def index():
    authz.require(authz.logged_in())
    cards = db.session.query(Card)
    if 'category' in request.args:
        cards = cards.filter(Card.category == request.args.get('category'))

    # TODO: find a better solution
    cards = cards.filter(Card.title != '')
    cards = cards.order_by(Card.created_at.desc())

    pager = Pager(cards)
    return jsonify(pager, index=True)
示例#7
0
def index():
    authz.require(authz.logged_in())
    cards = db.session.query(Card)
    if 'category' in request.args:
        cards = cards.filter(Card.category == request.args.get('category'))
    
    # TODO: find a better solution
    cards = cards.filter(Card.title != '')
    cards = cards.order_by(Card.created_at.desc())
    
    pager = Pager(cards)
    return jsonify(pager, index=True)
示例#8
0
def handle_exceptions(exc):
    if isinstance(exc, HTTPException):
        message = exc.get_description(request.environ)
        message = message.replace('<p>', '').replace('</p>', '')
        body = {'status': exc.code, 'name': exc.name, 'message': message}
        headers = exc.get_headers(request.environ)
    else:
        body = {
            'status': 500,
            'name': exc.__class__.__name__,
            'message': unicode(exc)
        }
        headers = {}
    return jsonify(body, status=body.get('status'), headers=headers)
示例#9
0
文件: __init__.py 项目: 01-/storyweb
def handle_exceptions(exc):
    if isinstance(exc, HTTPException):
        message = exc.get_description(request.environ)
        message = message.replace('<p>', '').replace('</p>', '')
        body = {
            'status': exc.code,
            'name': exc.name,
            'message': message
        }
        headers = exc.get_headers(request.environ)
    else:
        body = {
            'status': 500,
            'name': exc.__class__.__name__,
            'message': unicode(exc)
        }
        headers = {}
    return jsonify(body, status=body.get('status'),
                   headers=headers)
示例#10
0
def view(card_id, id):
    authz.require(authz.logged_in())
    reference = obj_or_404(Reference.by_id(id, card_id=card_id))
    return jsonify(reference)
示例#11
0
def create(card_id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(card_id))
    reference = Reference().save(request_data(), card, g.user)
    db.session.commit()
    return jsonify(reference, status=201)
示例#12
0
def search():
    authz.require(authz.logged_in())
    query = cards_query(request.args)
    pager = Pager(search_cards(query))
    return jsonify(pager, index=True)
示例#13
0
def update(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    link.save(request_data(), link.parent, g.user)
    db.session.commit()
    return jsonify(link)
示例#14
0
def view(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    return jsonify(link)
示例#15
0
def view(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    return jsonify(link)
示例#16
0
def suggest():
    authz.require(authz.logged_in())
    options = Card.suggest(request.args.get('prefix'),
                           categories=request.args.getlist('category'))
    return jsonify({'options': options}, index=True)
示例#17
0
def view(id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(id))
    return jsonify(card)
示例#18
0
def create():
    authz.require(authz.logged_in())
    card = Card().save(request_data(), g.user)
    db.session.commit()
    extract.delay(card.id)
    return jsonify(card, status=201)
示例#19
0
def categories():
    authz.require(authz.logged_in())
    return jsonify({'categories': Card.CATEGORIES}, index=True)
示例#20
0
def categories():
    authz.require(authz.logged_in())
    return jsonify({'categories': Card.CATEGORIES}, index=True)
示例#21
0
def search():
    authz.require(authz.logged_in())
    query = cards_query(request.args)
    pager = Pager(search_cards(query))
    return jsonify(pager, index=True)
示例#22
0
def suggest():
    authz.require(authz.logged_in())
    options = Card.suggest(request.args.get("prefix"), categories=request.args.getlist("category"))
    return jsonify({"options": options}, index=True)
示例#23
0
def update(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    link.save(request_data(), link.parent, g.user)
    db.session.commit()
    return jsonify(link)
示例#24
0
def update(card_id, id):
    authz.require(authz.logged_in())
    reference = obj_or_404(Reference.by_id(id, card_id=card_id))
    reference.save(request_data(), reference.card, g.user)
    db.session.commit()
    return jsonify(reference)
示例#25
0
def view(id):
    authz.require(authz.logged_in())
    card = obj_or_404(Card.by_id(id))
    return jsonify(card)
示例#26
0
def create():
    authz.require(authz.logged_in())
    card = Card().save(request_data(), g.user)
    db.session.commit()
    extract.delay(card.id)
    return jsonify(card, status=201)
示例#27
0
文件: auth.py 项目: 01-/storyweb
def get_session():
    return jsonify({
        'user': g.user if g.user.is_authenticated() else None,
        'logged_in': g.user.is_authenticated(),
        'is_admin': g.user.is_admin if g.user.is_authenticated() else False
    })
示例#28
0
    try:
        since = request.args.get('since')
        if since is not None:
            since = dateutil.parser.parse(since)

            child = aliased(Card)
            links = links.join(child, link.child)
            links = links.filter(or_(link.updated_at > since,
                                     child.updated_at > since))
    except (AttributeError, ValueError), e:
        response['status'] = 'ok'
        response['error'] = unicode(e)

    response['updated'] = [l.id for l in links]
    return jsonify(response)


@blueprint.route('/api/1/cards/<parent_id>/links/<id>', methods=['GET'])
def view(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    return jsonify(link)


@blueprint.route('/api/1/cards/<parent_id>/links/<id>', methods=['POST', 'PUT'])
def update(parent_id, id):
    authz.require(authz.logged_in())
    link = obj_or_404(Link.by_id(id, parent_id=parent_id))
    link.save(request_data(), link.parent, g.user)
    db.session.commit()