def remove_sharing(project=None, project_id=None): if project is None: project = DBSession.query(Project).filter( Project.id == project_id).first() for rc in project._circle_right: DBSession.delete(rc) DBSession.flush()
def delete(project=None, project_id=None): if project is None: project = DBSession.query(Project).filter( Project.id == project_id).first() remove_sharing(project=project) DBSession.delete(project) DBSession.flush()
def change_rights(project_id, circle_id, rights=None): ''' Modify the right associated to a project to a group. If any right is added, automatically add read right. @param project_id : the project id @param circle_id : the circle id @param rights : the right to update ''' project = DBSession.query(Project).filter(Project.id == project_id).first() rc_assocs = get_circle_right_assocs(circle_id, project_id) for rc in rc_assocs: if rc.circle.id == int(circle_id): project._circle_right.remove(rc) DBSession.delete(rc) DBSession.flush() if rights is not None: _add_read_right(project, circle_id) for right_name in rights: if right_name != constants.right_read: right = DBSession.query(Right).filter( Right.name == right_name).first() cr_assoc = _get_circle_right_assoc(right, circle_id, project_id) project._circle_right.append(cr_assoc) DBSession.add(project) DBSession.flush()
def after_sha1(self, fname, sha1, force, callback_url, track_id, old_task_id, mail, key, sequence_id, extension, trackname): """ Called after a sha1 where calculated on a file. If the sha1 already exist, only the databases operations are done. Else the input will go in the second part of the process. The input can be 'forced' to be recomputed """ try: _input = DBSession.query(Input).filter(Input.sha1 == sha1).first() do_process = True if util.str2bool(force) and _input is not None: handler.track.delete_input(_input.sha1) DBSession.delete(_input) DBSession.flush() elif _input is not None: do_process = False handler.track.update(track_id=track_id, params={'new_input_id': _input.id}) handler.track.finalize_track_creation(track_id=track_id) if do_process: handler.track.update(track_id=track_id, params={'sha1': sha1}) sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first() async = tasks.track_process.delay(mail, key, old_task_id, fname, sha1, callback_url, track_id, sequence.name, extension, trackname, callback_url) handler.track.update(track_id=track_id, params={'new_task_id': async.task_id}) return {'success': 'to second process'} except Exception as e: etype, value, tb = sys.exc_info() traceback.print_exception(etype, value, tb) return {'error': str(e)}
def change_rights(project_id, circle_id, rights=None): ''' Modify the right associated to a project to a group. If any right is added, automatically add read right. @param project_id : the project id @param circle_id : the circle id @param rights : the right to update ''' project = DBSession.query(Project).filter(Project.id == project_id).first() rc_assocs = get_circle_right_assocs(circle_id, project_id) for rc in rc_assocs: if rc.circle.id == int(circle_id) : project._circle_right.remove(rc) DBSession.delete(rc) DBSession.flush() if rights is not None: _add_read_right(project, circle_id) for right_name in rights: if right_name != constants.right_read : right = DBSession.query(Right).filter(Right.name == right_name).first() cr_assoc = _get_circle_right_assoc(right, circle_id, project_id) project._circle_right.append(cr_assoc) DBSession.add(project) DBSession.flush()
def e(project=None, project_id=None, name=None, track_ids=None, circle_ids=None): if project is None: project = DBSession.query(Project).filter(Project.id == project_id).first() if name is not None: project.name = name if track_ids is not None: project.tracks = [] for tid in track_ids: t = DBSession.query(Track).filter(Track.id == tid).first() project.tracks.append(t) if circle_ids is not None: if not isinstance(circle_ids, list): circle_ids = [circle_ids] circle_ids = [int(i) for i in circle_ids] to_del = [] for shared in project._circle_right: if shared.circle.id not in circle_ids: to_del.append(shared) for d in to_del: DBSession.delete(d) project._circle_right.remove(d) DBSession.flush() shared_ids = [c.id for c in project.shared_circles] read_right = DBSession.query(Right).filter(Right.id == constants.rights['read']['id']).first() for new_id in circle_ids: if new_id not in shared_ids: add_right(project=project, circle_id=new_id, right=read_right) DBSession.flush() DBSession.add(project) DBSession.flush() return project
def delete(self, _id): user = handler.user.get_user_in_session(request) if not checker.can_edit_job(user.id, _id): return {'error': "You have don't have the right to delete this job"} job = DBSession.query(Job).filter(Job.id == _id).first() # TODO delete results (DB + filesystem) DBSession.delete(job) raise redirect('/jobs')
def delete(self, circle_id, *args, **kw): user = handler.user.get_user_in_session(request) if not checker.user_own_circle(user.id, circle_id): flash('you have no right to delete this circle: you are not the creator of it') raise redirect('/circles') circle = DBSession.query(Circle).filter(Circle.id == circle_id).first() DBSession.delete(circle) DBSession.flush() raise redirect('/circles/')
def after_process(self, mail, key, old_task_id, track_id, datatype): print '[x] after process [x] %s' % track_id task = DBSession.query(Task).filter(Task.task_id == old_task_id).first() if task is not None: DBSession.delete(task) DBSession.flush() if not track_id == 'None': handler.track.update(track_id=track_id, params={'datatype': datatype}) handler.track.finalize_track_creation(track_id=track_id) return {'success': 'end'}
def delete(self, _id): user = handler.user.get_user_in_session(request) if not checker.can_edit_job(user.id, _id): return { 'error': "You have don't have the right to delete this job" } job = DBSession.query(Job).filter(Job.id == _id).first() # TODO delete results (DB + filesystem) DBSession.delete(job) raise redirect('/jobs')
def delete(self, project_id, selection_id): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash('You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'delete': 'failed'} selection = DBSession.query(Selection).filter(Selection.id == selection_id).first() if not selection.project_id == project_id: flash('Bad project_id: %s' % project_id, 'error') return {'delete': 'failed'} DBSession.delete(selection) DBSession.flush() return {'delete': 'success'}
def save(self, project_id, color, description, locations): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash( 'You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'save': 'failed'} #print "save %s, color %s, desc %s loc %s" % (project_id, color, description, locations) ''' For the moment, there is only one selection per project''' sel = DBSession.query(Selection).filter( Selection.project_id == project_id).first() if sel is None: sel = Selection() sel.project_id = project_id sel.description = description sel.color = color DBSession.add(sel) DBSession.flush() locations_ids = [] # add locations for loc in json.loads(locations): obj = None if 'id' in loc: obj = DBSession.query(Location).join( Selection.locations).filter( and_(Selection.id == sel.id, Location.id == loc.get('id'))).first() if obj is None: obj = Location() obj.chromosome = loc.get('chr') obj.start = loc.get('start') obj.end = loc.get('end') obj.description = loc.get('desc', 'No description') obj.selection = sel DBSession.add(obj) DBSession.flush() locations_ids.append(obj.id) # remove not saved ones loc_to_remove = DBSession.query(Location).filter( not_(Location.id.in_(locations_ids))).all() for l in loc_to_remove: DBSession.delete(l) DBSession.flush() return {"saved": "ok"}
def delete_track(track=None, track_id=None): ''' Delete the track and the input associated if this is the only track with this input. ''' if track is None: track = DBSession.query(Track).filter(Track.id == track_id).first() if track is None: return _input = track.input if _input is not None: if len(_input.tracks) == 1: delete_input(_input.sha1) DBSession.delete(_input) DBSession.delete(track) DBSession.flush()
def delete(self, project_id, selection_id): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash( 'You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'delete': 'failed'} selection = DBSession.query(Selection).filter( Selection.id == selection_id).first() if not selection.project_id == project_id: flash('Bad project_id: %s' % project_id, 'error') return {'delete': 'failed'} DBSession.delete(selection) DBSession.flush() return {'delete': 'success'}
def save(self, project_id, color, description, locations): user = handler.user.get_user_in_session(request) if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id): flash('You must have %s permission to delete the project.' % constants.right_upload, 'error') return {'save': 'failed'} #print "save %s, color %s, desc %s loc %s" % (project_id, color, description, locations) ''' For the moment, there is only one selection per project''' sel = DBSession.query(Selection).filter(Selection.project_id == project_id).first() if sel is None: sel = Selection() sel.project_id = project_id sel.description = description sel.color = color DBSession.add(sel) DBSession.flush() locations_ids = [] # add locations for loc in json.loads(locations): obj = None if 'id' in loc: obj = DBSession.query(Location).join(Selection.locations).filter( and_(Selection.id == sel.id, Location.id == loc.get('id'))).first() if obj is None: obj = Location() obj.chromosome = loc.get('chr') obj.start = loc.get('start') obj.end = loc.get('end') obj.description = loc.get('desc', 'No description') obj.selection = sel DBSession.add(obj) DBSession.flush() locations_ids.append(obj.id) # remove not saved ones loc_to_remove = DBSession.query(Location).filter(not_(Location.id.in_(locations_ids))).all() for l in loc_to_remove: DBSession.delete(l) DBSession.flush() return {"saved": "ok"}
def e(project=None, project_id=None, name=None, track_ids=None, circle_ids=None): if project is None: project = DBSession.query(Project).filter( Project.id == project_id).first() if name is not None: project.name = name if track_ids is not None: project.tracks = [] for tid in track_ids: t = DBSession.query(Track).filter(Track.id == tid).first() project.tracks.append(t) if circle_ids is not None: if not isinstance(circle_ids, list): circle_ids = [circle_ids] circle_ids = [int(i) for i in circle_ids] to_del = [] for shared in project._circle_right: if shared.circle.id not in circle_ids: to_del.append(shared) for d in to_del: DBSession.delete(d) project._circle_right.remove(d) DBSession.flush() shared_ids = [c.id for c in project.shared_circles] read_right = DBSession.query(Right).filter( Right.id == constants.rights['read']['id']).first() for new_id in circle_ids: if new_id not in shared_ids: add_right(project=project, circle_id=new_id, right=read_right) DBSession.flush() DBSession.add(project) DBSession.flush() return project
def delete(project=None, project_id=None): if project is None: project = DBSession.query(Project).filter(Project.id == project_id).first() remove_sharing(project=project) DBSession.delete(project) DBSession.flush()
def remove_sharing(project=None, project_id=None): if project is None: project = DBSession.query(Project).filter(Project.id == project_id).first() for rc in project._circle_right: DBSession.delete(rc) DBSession.flush()