def __setup_db_context(self, well_id): c.well = Session.query(QLBWell).filter_by(id=well_id)\ .options(joinedload_all(QLBWell.channels, innerjoin=True), joinedload_all(QLBWell.plate, QLBPlate.plate)).first() if not c.well: abort(404) c.reprocess_config_id = self.form_result['reprocess_config_id'] c.analysis_group_id = self.form_result['analysis_group_id'] # check for thing in relational table if c.reprocess_config_id and c.analysis_group_id: rec = Session.execute(select([agr]).where(and_(agr.c.analysis_group_id==int(c.analysis_group_id), agr.c.reprocess_config_id==int(c.reprocess_config_id)))) # check for an existing record if rec.rowcount > 0: # awesome, get the reprocess config name c.reprocess_config = Session.query(ReprocessConfig).get(c.reprocess_config_id) c.analysis_group = Session.query(AnalysisGroup).get(c.analysis_group_id) # get the plate metric for the plate c.well_metric = Session.query(WellMetric)\ .join(PlateMetric)\ .filter(and_(WellMetric.well_id==c.well.id, PlateMetric.reprocess_config_id==c.reprocess_config_id))\ .options(joinedload_all(WellMetric.well_channel_metrics, innerjoin=True)).first() else: c.reprocess_config = None c.analysis_group = None else: c.reprocess_config = None c.analysis_group = None if not c.reprocess_config: # try to find an existing well metric c.well_metric = Session.query(WellMetric)\ .join(PlateMetric)\ .filter(and_(WellMetric.well_id==c.well.id, PlateMetric.reprocess_config_id==None))\ .options(joinedload_all(WellMetric.well_channel_metrics, innerjoin=True)).first() if not c.well_metric: c.cluster_calc_mode = False else: c.cluster_calc_mode = c.well_metric.cnv_calc_mode == QLWellChannelStatistics.CONC_CALC_MODE_CLUSTER