Ejemplo n.º 1
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.º 2
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.º 3
0
def update(id):
    authz.require(authz.list_write(id))
    lst = obj_or_404(List.by_id(id))
    lst.update(request_data(), current_user)
    db.session.add(lst)
    db.session.commit()
    return view(id)
Ejemplo n.º 4
0
def delete(id):
    authz.require(authz.list_write(id))
    lst = obj_or_404(List.by_id(id))
    selectors = lst.terms
    lst.delete()
    db.session.commit()
    refresh_selectors.delay(list(selectors))
    return jsonify({'status': 'ok'})
Ejemplo n.º 5
0
def delete(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.list_write(entity.list_id))
    selectors = entity.terms
    entity.delete()
    db.session.commit()
    refresh_selectors.delay(list(selectors))
    return jsonify({"status": "ok"})
Ejemplo n.º 6
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.º 7
0
def delete(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.list_write(entity.list_id))
    selectors = entity.terms
    entity.delete()
    db.session.commit()
    refresh_selectors.delay(list(selectors))
    return jsonify({'status': 'ok'})
Ejemplo n.º 8
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.º 9
0
def view(id):
    authz.require(authz.list_read(id))
    lst = obj_or_404(List.by_id(id))
    etag_cache_keygen(lst)
    data = lst.to_dict()
    data['can_write'] = authz.list_write(id)
    if data['can_write']:
        data['users'] = [u.id for u in lst.users]
    return jsonify(data)
Ejemplo n.º 10
0
def index():
    q = List.all_by_user(current_user)
    data = Pager(q).to_dict()
    results = []
    for lst in data.pop('results'):
        ldata = lst.to_dict()
        ldata['can_write'] = authz.list_write(lst.id)
        results.append(ldata)
    data['results'] = results
    return jsonify(data)