Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
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()
Exemple #4
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)
Exemple #5
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)
Exemple #6
0
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()
Exemple #7
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)
Exemple #8
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)
Exemple #9
0
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)