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)
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)
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)
def handle_invalid(exc): body = { 'status': 400, 'name': 'Invalid Data', 'message': unicode(exc), 'errors': exc.asdict() } return jsonify(body, status=400)
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 })
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)
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)
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)
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)
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)
def search(): authz.require(authz.logged_in()) query = cards_query(request.args) pager = Pager(search_cards(query)) return jsonify(pager, index=True)
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)
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)
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)
def view(id): authz.require(authz.logged_in()) card = obj_or_404(Card.by_id(id)) return jsonify(card)
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)
def categories(): authz.require(authz.logged_in()) return jsonify({'categories': Card.CATEGORIES}, index=True)
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)
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)
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()