Allow for grabbing of single kit if only one exists for submission type.
This commit is contained in:
@@ -683,6 +683,11 @@ class SubmissionType(BaseClass):
|
||||
"""
|
||||
return f"<SubmissionType({self.name})>"
|
||||
|
||||
@classmethod
|
||||
def retrieve_template_file(cls):
|
||||
submission_type = cls.query(name="Bacterial Culture")
|
||||
return submission_type.template_file
|
||||
|
||||
def get_template_file_sheets(self) -> List[str]:
|
||||
logger.debug(f"Submission type to get sheets for: {self.name}")
|
||||
"""
|
||||
@@ -779,6 +784,12 @@ class SubmissionType(BaseClass):
|
||||
tmap = {}
|
||||
yield item.tip_role.name, tmap
|
||||
|
||||
def get_default_kit(self) -> KitType | None:
|
||||
if len(self.kit_types) == 1:
|
||||
return self.kit_types[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_equipment(self, extraction_kit: str | KitType | None = None) -> Generator['PydEquipmentRole', None, None]:
|
||||
"""
|
||||
Returns PydEquipmentRole of all equipment associated with this SubmissionType
|
||||
|
||||
@@ -8,7 +8,7 @@ from pprint import pformat
|
||||
from sqlalchemy import Column, String, INTEGER, ForeignKey, Table
|
||||
from sqlalchemy.orm import relationship, Query
|
||||
from . import Base, BaseClass
|
||||
from tools import check_authorization, setup_lookup
|
||||
from tools import check_authorization, setup_lookup, yaml_regex_creator
|
||||
from typing import List
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
@@ -88,6 +88,7 @@ class Organization(BaseClass):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
yaml.add_constructor("!regex", yaml_regex_creator)
|
||||
if isinstance(filepath, str):
|
||||
filepath = Path(filepath)
|
||||
if not filepath.exists():
|
||||
@@ -97,7 +98,7 @@ class Organization(BaseClass):
|
||||
if filepath.suffix == ".json":
|
||||
import_dict = json.load(fp=f)
|
||||
elif filepath.suffix == ".yml":
|
||||
import_dict = yaml.safe_load(stream=f)
|
||||
import_dict = yaml.load(stream=f, Loader=yaml.Loader)
|
||||
else:
|
||||
raise Exception(f"Filetype {filepath.suffix} not supported.")
|
||||
data = import_dict['orgs']
|
||||
|
||||
@@ -1038,7 +1038,7 @@ class BasicSubmission(BaseClass):
|
||||
chronologic: bool = False,
|
||||
limit: int = 0,
|
||||
page: int = 1,
|
||||
page_size: int = 250,
|
||||
page_size: None | int = 250,
|
||||
**kwargs
|
||||
) -> BasicSubmission | List[BasicSubmission]:
|
||||
"""
|
||||
@@ -1059,6 +1059,7 @@ class BasicSubmission(BaseClass):
|
||||
"""
|
||||
# logger.debug(f"Incoming kwargs: {kwargs}")
|
||||
# NOTE: if you go back to using 'model' change the appropriate cls to model in the query filters
|
||||
# logger.debug(f"Page size: {page_size}")
|
||||
if submission_type is not None:
|
||||
model = cls.find_polymorphic_subclass(polymorphic_identity=submission_type)
|
||||
elif len(kwargs) > 0:
|
||||
@@ -1139,7 +1140,7 @@ class BasicSubmission(BaseClass):
|
||||
# if chronologic:
|
||||
# logger.debug("Attempting sort by date descending")
|
||||
query = query.order_by(cls.submitted_date.desc())
|
||||
if page_size is not None:
|
||||
if page_size > 0:
|
||||
query = query.limit(page_size)
|
||||
page = page - 1
|
||||
if page is not None:
|
||||
|
||||
Reference in New Issue
Block a user