def delete_sample_additional(sample_id, additional_id): from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Fetch additional info extra = ExtraFile.query.filter(ExtraFile.id == additional_id).first() if extra is not None: # Process or render form form = DeleteAdditionalSampleForm(request.form) if form.validate_on_submit(): basedir = os.path.join( config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'extra', extra.filename)) g.db.delete(extra) g.db.commit() return redirect(url_for('.sample_by_id', sample_id=sample.id)) return { 'sample': sample, 'extra': extra, 'form': form } raise SampleNotFoundException('Extra file %s for sample %s not ' 'found' % (additional_id, sample.id)) raise SampleNotFoundException('Sample with id %s not found' % sample_id)
def delete_sample_additional(sample_id, additional_id): """ Delete sample's additional, required admin role. :param sample_id: id of the sample :type sample_id: int :param additional_id: id of the sample's additional :type additional_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: extra = ExtraFile.query.filter(ExtraFile.id == additional_id).first() if extra is not None: form = DeleteAdditionalSampleForm(request.form) if form.validate_on_submit(): basedir = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'extra', extra.filename)) g.db.delete(extra) g.db.commit() g.log.warning( f"additional with id: {additional_id} for sample with id: {sample_id} deleted" ) return redirect(url_for('.sample_by_id', sample_id=sample.id)) return {'sample': sample, 'extra': extra, 'form': form} raise SampleNotFoundException( f"Extra file {additional_id} for sample {sample.id} not found") raise SampleNotFoundException(f"Sample with id {sample_id} not found")
def delete_sample_additional(sample_id, additional_id): from run import config sample = Sample.query.filter(Sample.id == sample_id).first() if sample is not None: # Fetch additional info extra = ExtraFile.query.filter(ExtraFile.id == additional_id).first() if extra is not None: # Process or render form form = DeleteAdditionalSampleForm(request.form) if form.validate_on_submit(): basedir = os.path.join(config.get('SAMPLE_REPOSITORY', ''), 'TestFiles') os.remove(os.path.join(basedir, 'extra', extra.filename)) g.db.delete(extra) g.db.commit() return redirect(url_for('.sample_by_id', sample_id=sample.id)) return { 'sample': sample, 'extra': extra, 'form': form } raise SampleNotFoundException('Extra file {f_id} for sample {s_id} not found'.format( f_id=additional_id, s_id=sample.id)) raise SampleNotFoundException('Sample with id {id} not found'.format(id=sample_id))