Attempting fix of failure to update reagent on edit.
This commit is contained in:
@@ -70,5 +70,5 @@ def update_log(mapper, connection, target):
|
||||
logger.info(f"No changes detected, not updating logs.")
|
||||
|
||||
|
||||
event.listen(LogMixin, 'after_update', update_log, propagate=True)
|
||||
event.listen(LogMixin, 'after_insert', update_log, propagate=True)
|
||||
# event.listen(LogMixin, 'after_update', update_log, propagate=True)
|
||||
# event.listen(LogMixin, 'after_insert', update_log, propagate=True)
|
||||
|
||||
@@ -182,7 +182,7 @@ class BaseClass(Base):
|
||||
query: Query = cls.__database_session__.query(model)
|
||||
# logger.debug(f"Grabbing singles using {model.get_default_info}")
|
||||
singles = model.get_default_info('singles')
|
||||
logger.info(f"Querying: {model}, with kwargs: {kwargs}")
|
||||
# logger.info(f"Querying: {model}, with kwargs: {kwargs}")
|
||||
for k, v in kwargs.items():
|
||||
logger.info(f"Using key: {k} with value: {v}")
|
||||
try:
|
||||
|
||||
@@ -273,7 +273,7 @@ class Control(BaseClass):
|
||||
except StopIteration as e:
|
||||
raise AttributeError(
|
||||
f"Couldn't find existing class/subclass of {cls} with all attributes:\n{pformat(attrs.keys())}")
|
||||
logger.info(f"Recruiting model: {model}")
|
||||
# logger.info(f"Recruiting model: {model}")
|
||||
return model
|
||||
|
||||
@classmethod
|
||||
@@ -535,8 +535,8 @@ class IridaControl(Control):
|
||||
except AttributeError:
|
||||
consolidate = False
|
||||
report = Report()
|
||||
# logger.debug(f"settings: {pformat(chart_settings)}")
|
||||
controls = cls.query(sub_type=chart_settings['sub_type'], start_date=chart_settings['start_date'],
|
||||
logger.debug(f"settings: {pformat(chart_settings)}")
|
||||
controls = cls.query(subtype=chart_settings['sub_type'], start_date=chart_settings['start_date'],
|
||||
end_date=chart_settings['end_date'])
|
||||
# logger.debug(f"Controls found: {controls}")
|
||||
if not controls:
|
||||
|
||||
@@ -12,7 +12,7 @@ from tools import check_authorization, setup_lookup, Report, Result, check_regex
|
||||
from typing import List, Literal, Generator, Any
|
||||
from pandas import ExcelFile
|
||||
from pathlib import Path
|
||||
from . import Base, BaseClass, Organization
|
||||
from . import Base, BaseClass, Organization, LogMixin
|
||||
from io import BytesIO
|
||||
|
||||
logger = logging.getLogger(f'submissions.{__name__}')
|
||||
@@ -797,7 +797,7 @@ class SubmissionType(BaseClass):
|
||||
fmap = item.uses
|
||||
if fmap is None:
|
||||
fmap = {}
|
||||
yield getattr(item, f"{field}_role"), fmap
|
||||
yield getattr(item, f"{field}_role").name, fmap
|
||||
|
||||
def get_default_kit(self) -> KitType | None:
|
||||
if len(self.kit_types) == 1:
|
||||
@@ -1361,7 +1361,7 @@ class Equipment(BaseClass):
|
||||
def __repr__(self) -> str:
|
||||
"""
|
||||
Returns:
|
||||
str: represenation of this Equipment
|
||||
str: representation of this Equipment
|
||||
"""
|
||||
return f"<Equipment({self.name})>"
|
||||
|
||||
@@ -1502,7 +1502,7 @@ class Equipment(BaseClass):
|
||||
equipment_role = EquipmentRole.query(name=equipment_role)
|
||||
equipment = cls.query()
|
||||
options = "\n".join([f"{ii}. {item.name}" for ii, item in enumerate(equipment)])
|
||||
choices = input(f"Enter equipment numbers to add to {equipment_role.name} (space seperated):\n{options}\n\n")
|
||||
choices = input(f"Enter equipment numbers to add to {equipment_role.name} (space separated):\n{options}\n\n")
|
||||
output = []
|
||||
for choice in choices.split(" "):
|
||||
try:
|
||||
|
||||
@@ -618,6 +618,17 @@ class BasicSubmission(BaseClass, LogMixin):
|
||||
result = assoc.save()
|
||||
return result
|
||||
|
||||
def update_reagentassoc(self, reagent: Reagent, role: str):
|
||||
from backend.db import SubmissionReagentAssociation
|
||||
# NOTE: get the first reagent assoc that fills the given role.
|
||||
try:
|
||||
assoc = next(item for item in self.submission_reagent_associations if item.reagent and role in [role.name for role in item.reagent.role])
|
||||
assoc.reagent = reagent
|
||||
except StopIteration as e:
|
||||
logger.error(f"Association for {role} not found, creating new association.")
|
||||
assoc = SubmissionReagentAssociation(submission=self, reagent=reagent)
|
||||
self.submission_reagent_associations.append(assoc)
|
||||
|
||||
def to_pydantic(self, backup: bool = False) -> "PydSubmission":
|
||||
"""
|
||||
Converts this instance into a PydSubmission
|
||||
@@ -758,7 +769,7 @@ class BasicSubmission(BaseClass, LogMixin):
|
||||
except StopIteration as e:
|
||||
raise AttributeError(
|
||||
f"Couldn't find existing class/subclass of {cls} with all attributes:\n{pformat(attrs.keys())}")
|
||||
logger.info(f"Recruiting model: {model}")
|
||||
# logger.info(f"Recruiting model: {model}")
|
||||
return model
|
||||
|
||||
# Child class custom functions
|
||||
@@ -1414,7 +1425,7 @@ class BacterialCulture(BasicSubmission):
|
||||
extends parent
|
||||
"""
|
||||
template = super().filename_template()
|
||||
template += "_{{ submitting_lab }}_{{ submitter_plate_num }}"
|
||||
template += "_{{ submitting_lab.name }}_{{ submitter_plate_num }}"
|
||||
return template
|
||||
|
||||
@classmethod
|
||||
@@ -2356,7 +2367,7 @@ class BasicSample(BaseClass):
|
||||
except Exception as e:
|
||||
logger.error(f"Could not get polymorph {polymorphic_identity} of {cls} due to {e}, using {cls}")
|
||||
model = cls
|
||||
logger.info(f"Recruiting model: {model}")
|
||||
# logger.info(f"Recruiting model: {model}")
|
||||
return model
|
||||
else:
|
||||
model = cls
|
||||
@@ -2370,7 +2381,7 @@ class BasicSample(BaseClass):
|
||||
except StopIteration as e:
|
||||
raise AttributeError(
|
||||
f"Couldn't find existing class/subclass of {cls} with all attributes:\n{pformat(attrs.keys())}")
|
||||
logger.info(f"Recruiting model: {model}")
|
||||
# logger.info(f"Recruiting model: {model}")
|
||||
return model
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user