During code cleanup

This commit is contained in:
lwark
2024-05-23 15:06:22 -05:00
parent d1bf12e8d1
commit 2814be8980
10 changed files with 297 additions and 356 deletions

View File

@@ -2,6 +2,8 @@
Contains pydantic models and accompanying validators
'''
from __future__ import annotations
import sys
from operator import attrgetter
import uuid, re, logging
from pydantic import BaseModel, field_validator, Field, model_validator, PrivateAttr
@@ -431,10 +433,14 @@ class PydSubmission(BaseModel, extra='allow'):
value['value'] = None
if value['value'] is None:
value['missing'] = True
if "pytest" in sys.modules:
value['value'] = "Nosocomial"
return value
from frontend.widgets.pop_ups import ObjectSelector
dlg = ObjectSelector(title="Missing Submitting Lab",
message="We need a submitting lab. Please select from the list.",
obj_type=Organization)
if dlg.exec():
value['value'] = dlg.parse_form()
else:
@@ -651,9 +657,13 @@ class PydSubmission(BaseModel, extra='allow'):
logger.debug(f"Setting {key} to {value}")
match key:
case "reagents":
if code == 1:
instance.submission_reagent_associations = []
logger.debug(f"Looking through {self.reagents}")
for reagent in self.reagents:
reagent, assoc = reagent.toSQL(submission=instance)
if assoc is not None and assoc not in instance.submission_reagent_associations:
logger.debug(f"Association: {assoc}")
if assoc is not None:# and assoc not in instance.submission_reagent_associations:
instance.submission_reagent_associations.append(assoc)
# instance.reagents.append(reagent)
case "samples":
@@ -666,13 +676,13 @@ class PydSubmission(BaseModel, extra='allow'):
case "equipment":
logger.debug(f"Equipment: {pformat(self.equipment)}")
try:
if equip == None:
if equip is None:
continue
except UnboundLocalError:
continue
for equip in self.equipment:
equip, association = equip.toSQL(submission=instance)
if association != None:
if association is not None:
association.save()
logger.debug(
f"Equipment association SQL object to be added to submission: {association.__dict__}")
@@ -719,7 +729,7 @@ class PydSubmission(BaseModel, extra='allow'):
# We need to make sure there's a proper rsl plate number
logger.debug(f"We've got a total cost of {instance.run_cost}")
try:
logger.debug(f"Constructed instance: {instance.to_string()}")
logger.debug(f"Constructed instance: {instance}")
except AttributeError as e:
logger.debug(f"Something went wrong constructing instance {self.rsl_plate_num}: {e}")
logger.debug(f"Constructed submissions message: {msg}")