def get(self, project_key=None, project_id=None, **kw): # get all user projects if not project_key and not project_id: user = handler.user.get_user_in_session(request) projects = DBSession.query(Project).filter( Project.user_id == user.id).all() return reply.normal(request, 'You can upload track on these projects', '/tracks', {'projects': projects}) project = None # get one specific user project if project_id is not None and project_id: user = handler.user.get_user_in_session(request) project = DBSession.query(Project).filter( Project.id == int(project_id)).first() if project is not None and not project.user_id == user.id: reply.error(request, 'Not your project', '/tracks', {}) return reply.normal(request, 'You can upload track on this project', '/tracks', {'project': project}) # get a project by it's key project = DBSession.query(Project).filter( Project.key == project_key).first() if project is None: return reply.error(request, 'Wrong key', '/tracks', {}) return reply.normal(request, 'You can upload track on this project', '/tracks', {'project': project})
def copy(self, track_id): user = handler.user.get_user_in_session(request) if not checker.can_download_track(user.id, track_id): return reply.error(request, 'You have no right to copy this track in your profile.', './', {}) t = DBSession.query(Track).filter(Track.id == track_id).first() if not t: return reply.error(request, 'No track with this id.', './', {}) handler.track.copy_track(user.id, t) return reply.normal(request, 'Copy successfull', './', {})
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) if len(args) > 0: project_id = args[0] if not checker.check_permission(user=user, project_id=project_id, right_id=constants.right_upload_id) and not checker.is_admin(user=user): return reply.error(request, "You must have %s permission to delete the project." % constants.right_upload, '/tracks', {'error': 'wrong credentials'}) handler.project.delete(project_id=project_id) return reply.normal(request, 'Project successfully deleted.', '/tracks', {'success': 'project deleted'})
def get(self, project_key=None, project_id=None, **kw): # get all user projects if not project_key and not project_id: user = handler.user.get_user_in_session(request) projects = DBSession.query(Project).filter(Project.user_id == user.id).all() return reply.normal(request, 'You can upload track on these projects', '/tracks', {'projects': projects}) project = None # get one specific user project if project_id is not None and project_id: user = handler.user.get_user_in_session(request) project = DBSession.query(Project).filter(Project.id == int(project_id)).first() if project is not None and not project.user_id == user.id: reply.error(request, 'Not your project', '/tracks', {}) return reply.normal(request, 'You can upload track on this project', '/tracks', {'project': project}) # get a project by it's key project = DBSession.query(Project).filter(Project.key == project_key).first() if project is None: return reply.error(request, 'Wrong key', '/tracks', {}) return reply.normal(request, 'You can upload track on this project', '/tracks', {'project': project})
def delete(self, track_id, **kw): user = handler.user.get_user_in_session(request) if track_id is not None: if not checker.can_edit_track(user, track_id): return reply.error(request, "You haven't the right to delete any tracks which is not yours", '/tracks', {'error': 'wrong credential'}) handler.track.delete_track(track_id=track_id) red = '/tracks' if 'pid' in kw: red += '?pid=%s' % kw['pid'] return reply.normal(request, 'Track successfully deleted.', red, {'success': 'track deleted'})
def create(self, *args, **kw): print 'create %s, %s' % (args, kw) user = handler.user.get_user_in_session(request) if not 'name' in kw: return reply.error(request, 'Missing project `name`.', url('/tracks'), {}) if not 'assembly' in kw: return reply.error(request, 'Missing project `assembly` identifier.', url('/tracks'), {}) sequence = DBSession.query(Sequence).filter(Sequence.id == int(kw.get('assembly'))).first() if sequence is None: return reply.error(request, "Assembly doesn't exist in GDV.", './', {}) project = handler.project.create(kw['name'], kw['assembly'], user.id) return reply.normal(request, 'Project successfully created.', url('/tracks'), {'project': project})
def delete(self, *args, **kw): user = handler.user.get_user_in_session(request) if len(args) > 0: project_id = args[0] if not checker.check_permission( user=user, project_id=project_id, right_id=constants.right_upload_id ) and not checker.is_admin(user=user): return reply.error( request, "You must have %s permission to delete the project." % constants.right_upload, '/tracks', {'error': 'wrong credentials'}) handler.project.delete(project_id=project_id) return reply.normal(request, 'Project successfully deleted.', '/tracks', {'success': 'project deleted'})
def create(self, *args, **kw): print 'create %s, %s' % (args, kw) user = handler.user.get_user_in_session(request) if not 'name' in kw: return reply.error(request, 'Missing project `name`.', url('/tracks'), {}) if not 'assembly' in kw: return reply.error(request, 'Missing project `assembly` identifier.', url('/tracks'), {}) sequence = DBSession.query(Sequence).filter( Sequence.id == int(kw.get('assembly'))).first() if sequence is None: return reply.error(request, "Assembly doesn't exist in GDV.", './', {}) project = handler.project.create(kw['name'], kw['assembly'], user.id) return reply.normal(request, 'Project successfully created.', url('/tracks'), {'project': project})
def create(self, *args, **kw): user = handler.user.get_user_in_session(request) # get sequence sequence = None project_id = None debug('Create track %s' % kw) debug('Find sequence', 1) if 'assembly' in kw and kw.get('assembly'): assembly = int(kw.get('assembly')) sequence = DBSession.query(Sequence).filter(Sequence.id == assembly).first() elif 'sequence_id' in kw and kw.get('sequence_id'): sequence_id = int(kw.get('sequence_id')) sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first() elif 'sequence_id' in kw and kw.get('sequence_id'): sequence_id = int(kw.get('sequence_id')) sequence = DBSession.query(Sequence).filter(Sequence.id == sequence_id).first() elif 'project_id' in kw and kw.get('project_id'): project_id = int(kw.get('project_id')) project = DBSession.query(Project).filter(Project.id == project_id).first() if project is None: return reply.error(request, 'Project with id %s not found on GDV.' % project_id, tg.url('./new', {'pid': project_id}), {}) sequence = DBSession.query(Sequence).filter(Sequence.id == project.sequence_id).first() if not sequence: return reply.error(request, 'Sequence not found on GDV.', tg.url('./new'), {'pid': project_id}) debug('%s' % sequence.name, 2) # know if file is comming from url, fileupload or filsystem filetoget = None inputtype = None debug('Find inputtype', 1) if 'url' in kw and kw.get('url'): debug('from url', 2) filetoget = kw.get('url') if not filetoget.startswith('http://'): filetoget = 'http://%s' % filetoget inputtype = 'url' elif 'fsys' in kw and kw.get('fsys'): debug('fsys', 2) filetoget = kw.get('fsys') inputtype = 'fsys' elif 'file_upload' in kw and kw.get('file_upload') is not None and kw['file_upload'] != '': debug('file upload %s' % kw.get('file_upload'), 2) filetoget = kw.get('file_upload') inputtype = 'fu' if filetoget is None: return reply.error(request, 'No file to upload', tg.url('./new'), {'pid': project_id}) debug('file2get: %s, intype: %s' % (filetoget, inputtype), 2) # get file name debug('Find track name', 1) trackname = None if 'trackname' in kw and kw.get('trackname'): debug('i params', 2) trackname = kw.get('trackname') else: if inputtype == 'url': debug('trackname from url', 2) trackname = os.path.split(filetoget)[1].split('?')[0] elif inputtype == 'fsys': debug('trackname from fsys', 2) trackname = os.path.split(filetoget)[-1] elif inputtype == 'fu': debug('trackname from fu', 2) trackname = filetoget.filename if trackname is None: return reply.error(request, 'No trackname found', tg.url('./new'), {'pid': project_id}) debug('%s' % trackname, 2) # get extension extension = None if 'extension' in kw and kw.get('extension'): extension = kw.get('extension') elif 'ext' in kw and kw.get('ext'): extension = kw.get('ext') else: extension = os.path.splitext(trackname)[-1] if extension is None or extension == '': if inputtype == 'url': debug('extension from url', 2) extension = os.path.splitext(os.path.split(filetoget)[1].split('?')[0])[-1] elif inputtype == 'fsys': debug('extension from fsys', 2) extension = os.path.splitext(os.path.split(filetoget)[-1])[-1] elif inputtype == 'fu': debug('extension from fu', 2) extension = os.path.splitext(filetoget.filename)[-1] if extension is None or extension == '': return reply.error(request, 'No extension found', tg.url('./new'), {'pid': project_id}) if extension.startswith('.'): extension = extension[1:] extension = extension.lower() # is the track "admin" admin = False if 'track_admin' in kw and kw.get('track_admin'): # check if really admin group_admin = DBSession.query(Group).filter(Group.id == constants.group_admins_id).first() if user in group_admin.users: admin = True debug('admin: %s' % admin, 1) #store information in a dummy object out = os.path.join(filemanager.temporary_directory(), trackname) fileinfo = filemanager.FileInfo(inputtype=inputtype, inpath=filetoget, trackname=trackname, extension=extension, outpath=out, admin=admin) debug('fileinfo: %s' % fileinfo, 1) # get additionnal information user_info = {'id': user.id, 'name': user.name, 'email': user.email} sequence_info = {'id': sequence.id, 'name': sequence.name} #upload the track it's from file_upload if inputtype == 'fu': debug('Download', 1) fileinfo.download() debug('fileinfo: %s' % fileinfo, 1) # create a track that the user can see something t = Track() t.name = fileinfo.trackname t.sequence_id = sequence.id t.user_id = user.id DBSession.add(t) DBSession.flush() # send task async = tasks.new_input.delay(user_info, fileinfo, sequence_info, t.id, project_id) t.task_id = async.task_id DBSession.add(t) DBSession.flush() debug('End create') return reply.normal(request, 'Processing launched.', '/tracks/', {'track_id': t.id, 'pid': project_id})