def delete_sample(sample_id): """ Delete sample, required admin role. :param sample_id: id of the sample :type sample_id: int :raises SampleNotFoundException: when sample id is not found :return: form to edit sample :rtype: dict """ from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Process or render form form = DeleteSampleForm(request.form) if form.validate_on_submit(): # Delete all files (sample, media info & additional files basedir = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'media', sample.sha + '.xml')) for extra in sample.extra_files: os.remove(os.path.join(basedir, 'extra', extra.filename)) os.remove(os.path.join(basedir, sample.filename)) g.db.delete(sample) g.db.commit() g.log.warning(f'sample with id: {sample_id} deleted') return redirect(url_for('.index')) return {'sample': sample, 'form': form} raise SampleNotFoundException( 'Sample with id {id} not found'.format(id=sample_id))
def delete_sample(sample_id): from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Process or render form form = DeleteSampleForm(request.form) if form.validate_on_submit(): # Delete all files (sample, media info & additional files basedir = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'media', sample.sha + '.xml')) for extra in sample.extra_files: os.remove(os.path.join(basedir, 'extra', extra.filename)) os.remove(os.path.join(basedir, sample.filename)) g.db.delete(sample) g.db.commit() return redirect(url_for('.index')) return {'sample': sample, 'form': form} raise SampleNotFoundException('Sample with id %s not found' % sample_id)
def delete_sample(sample_id): from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Process or render form form = DeleteSampleForm(request.form) if form.validate_on_submit(): # Delete all files (sample, media info & additional files basedir = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'media', sample.sha + '.xml')) for extra in sample.extra_files: os.remove(os.path.join(basedir, 'extra', extra.filename)) os.remove(os.path.join(basedir, sample.filename)) g.db.delete(sample) g.db.commit() return redirect(url_for('.index')) return { 'sample': sample, 'form': form } raise SampleNotFoundException('Sample with id {id} not found'.format(id=sample_id))