def extract_entities(parent): from storyweb.queue import index for offset, child in extract_multi(parent): log.info("Extraced: %r in %r", child, parent) data = { 'offset': offset, 'child': child } link = Link.find(parent, child) if link is None: link = Link() else: data['status'] = link.status link.save(data, parent, child.author) index.delay(parent.id)
def extract(card_id): parent = Card.by_id(card_id) if parent.category != Card.ARTICLE: log.info('Not extracting entities from "%s"...', parent.title) return log.info('Extracting entities from "%s"...', parent.title) try: for offset, child in extract_entities(parent.text): data = { 'offset': offset, 'child': child } link = Link.find(parent, child) if link is None: link = Link() else: data['status'] = link.status link.save(data, parent, child.author) index.delay(card_id) db.session.commit() except Exception, e: log.exception(e)
def delete(parent_id, id): authz.require(authz.logged_in()) link = obj_or_404(Link.by_id(id, parent_id=parent_id)) db.session.delete(link) db.session.commit() raise Gone()
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 create(parent_id): authz.require(authz.logged_in()) card = obj_or_404(Card.by_id(parent_id)) reference = Link().save(request_data(), card, g.user) db.session.commit() return jsonify(reference, status=201)