def put(self): set_id = self._request.matchdict['id'] try: dset = DBSession.query(DigitalSet).filter( DigitalSet.id_set == set_id).one() dset.set_from_dict(self._request.validated) old_groups = DBSession.query(GroupSet).filter( GroupSet.id_set == set_id).all() old_ids = [gs.id_group for gs in old_groups] new_ids = [ g['id_group'] for g in self._request.validated['groups'] ] new_groups = [ GroupSet(set_id, gid) for gid in new_ids if not gid in old_ids ] for new_group in new_groups: DBSession.add(new_group) for old_group in old_groups: if old_group.id_group not in new_ids: DBSession.delete(old_group) # metadata = [x for x in DBSession.query(Metadata).filter(Metadata.id == dset.id_set).all()] update_metadata(self._request.validated['metadata'], dset.id_set, 'set') DBSession.flush() return APIResponse( add_metadata_record(dset.get_dict(), dset.id_set, 'set')) except Exception as e: print(e) raise HTTPNotFound()
def delete(self): if not self._request.token: # this should never happen raise HTTPUnauthorized tok = DBSession.query(Token).filter( Token.id_token == self._request.token).one() DBSession.delete(tok) return APIResponse(None)
def delete(self): annotation_id = self._request.matchdict['annot_id'] q = DBSession.query(Link).filter(Link.id_link == annotation_id) if self._request.user.auth_level < RIGHTLevels.Editor: q = q.filter(Link.id_user == self._request.user.id_user) link = q.one() DBSession.delete(link) DBSession.flush() return APIResponse(True)
def delete(self): container_id = self._request.matchdict['container_id'] cnt = DBSession.query(Container).filter(Container.id_view == self._view_id).filter(Container.id_container == container_id).one() cntitems = DBSession.query(ContainerItem).filter(ContainerItem.id_container == container_id).all() for itm in cntitems: DBSession.delete(cnt) DBSession.delete(cnt) DBSession.flush() return APIResponse(True)
def group_item_service_func_del(request): group_id = request.matchdict['group_id'] item_id = request.matchdict['item_id'] gi = DBSession.query(GroupItem).filter( sqlalchemy.and_(GroupItem.id_group == group_id, GroupItem.id_item == item_id)).one() DBSession.delete(gi) DBSession.flush() req = Request.blank('/api/v1/dig/' + group_id) return request.invoke_subrequest(req)
def view_item_service_func2(request): view_id = request.matchdict['view_id'] container_id = request.matchdict['container_id'] item_id = request.matchdict['item_id'] ci = DBSession.query(ContainerItem, Container)\ .join(Container, Container.id_container == ContainerItem.id_container)\ .filter(Container.id_view == view_id)\ .filter(sqlalchemy.and_(ContainerItem.id_container == container_id, ContainerItem.id_item == item_id))\ .one() DBSession.delete(ci[0]) req = Request.blank('/api/v1/view/' + view_id + '/container/' + container_id) return request.invoke_subrequest(req)
def view_item_service_func2(request): view_id = request.matchdict['view_id'] item_id = request.matchdict['item_id'] vi = DBSession.query(ViewItem).filter( sqlalchemy.and_(ViewItem.id_view == view_id, ViewItem.id_item == item_id)).one() usages = DBSession.query(Container, ContainerItem)\ .join(ContainerItem, ContainerItem.id_container == Container.id_container)\ .filter(ContainerItem.id_item == item_id)\ .filter(Container.id_view == view_id)\ .count() if usages > 0: raise HTTPBadRequest() DBSession.delete(vi) req = Request.blank('/api/v1/view/' + view_id) return request.invoke_subrequest(req)
def update_links(new_links, item_id): old_links = [ x for x in DBSession.query(Link).filter(Link.id_item == item_id).all() ] for link in new_links: print(link) l = next((x for x in old_links if x.id_link == link['id_link']), None) if 'id_link' in link else None if not l: # Our link is a new one print('Creating new link') ll = Link(str(uuid4()), item_id, link['id_user'], link['type'], link['description'], link['uri']) DBSession.add(ll) else: # Update old link print('Updating link %s' % link['id_link']) l.set_from_dict(link) for link in old_links: l = next((x for x in new_links if x['id_link'] == link.id_link), None) if not l: # link was deleted print('Deleting link') DBSession.delete(link)