Ejemplo n.º 1
0
def create():
    data = EntityForm().deserialize(request_data())
    watchlist = data.get("watchlist")
    authz.require(watchlist)
    authz.require(authz.watchlist_write(watchlist.id))
    entity = Entity.create(data)
    watchlist.touch()
    db.session.commit()
    analyze_entity.delay(entity.id)
    return view(entity.id)
Ejemplo n.º 2
0
def update(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.watchlist_write(entity.watchlist_id))
    data = EntityForm().deserialize(request_data())
    watchlist = data.get("watchlist")
    authz.require(watchlist)
    authz.require(authz.watchlist_write(watchlist.id))
    entity.update(data)
    watchlist.touch()
    db.session.commit()
    analyze_entity.delay(entity.id)
    return view(entity.id)
Ejemplo n.º 3
0
def create():
    data = EntityForm().deserialize(request_data())
    authz.require(data['list'])
    authz.require(authz.list_write(data['list'].id))
    entity = Entity.create(data, current_user)
    db.session.commit()
    refresh_selectors.delay(list(entity.terms))
    return view(entity.id)
Ejemplo n.º 4
0
    def update(self, data):
        data = EntityForm().deserialize(data)
        self.label = data.get('label')
        self.list = data.get('list')
        self.category = data.get('category')

        selectors = set(data.get('selectors'))
        selectors.add(self.label)
        existing = list(self.selectors)
        for sel in list(existing):
            if sel.text in selectors:
                selectors.remove(sel.text)
                existing.remove(sel)
        for sel in existing:
            db.session.delete(sel)
        for text in selectors:
            sel = Selector()
            sel.entity = self
            sel.text = text
            db.session.add(sel)
Ejemplo n.º 5
0
def update(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.list_write(entity.list_id))
    data = EntityForm().deserialize(request_data())
    authz.require(data['list'])
    authz.require(authz.list_write(data['list'].id))
    old_selectors = entity.terms
    entity.update(data)
    db.session.commit()
    selectors = old_selectors.symmetric_difference(entity.terms)
    refresh_selectors.delay(list(selectors))
    return view(entity.id)
Ejemplo n.º 6
0
    def update(self, data):
        data = EntityForm().deserialize(data)
        self.label = data.get('label')
        self.list = data.get('list')
        self.category = data.get('category')

        selectors = set(data.get('selectors'))
        selectors.add(self.label)
        existing = list(self.selectors)
        for sel in list(existing):
            if sel.text in selectors:
                selectors.remove(sel.text)
                existing.remove(sel)
        for sel in existing:
            db.session.delete(sel)
        for text in selectors:
            sel = Selector()
            sel.entity = self
            sel.text = text
            db.session.add(sel)
Ejemplo n.º 7
0
    def update(self, data):
        data = EntityForm().deserialize(data)
        self.name = data.get("name")
        self.watchlist = data.get("watchlist")
        self.foreign_id = data.get("foreign_id")
        self.category = data.get("category")
        self.data = data.get("data")
        db.session.add(self)
        db.session.flush()

        selectors = set(data.get("selectors", []))
        selectors.add(self.name)
        existing = list(self.selectors)
        for sel in list(existing):
            if sel.text in selectors:
                selectors.remove(sel.text)
                existing.remove(sel)
        for sel in existing:
            db.session.delete(sel)
        for text in selectors:
            sel = Selector()
            sel.entity = self
            sel.text = text
            db.session.add(sel)