Bugfix for commenting submissions.

This commit is contained in:
Landon Wark
2023-11-16 09:06:19 -06:00
parent 9312a66bb7
commit 6e865f1551
7 changed files with 110 additions and 77 deletions

View File

@@ -20,6 +20,7 @@ class ControlType(Base):
"""
__tablename__ = '_control_types'
id = Column(INTEGER, primary_key=True) #: primary key
name = Column(String(255), unique=True) #: controltype name (e.g. MCS)
targets = Column(JSON) #: organisms checked for

View File

@@ -360,12 +360,16 @@ class BasicSubmission(Base):
logger.debug(f"Hello from {cls.__mapper_args__['polymorphic_identity']} PCR parser!")
return []
def save(self):
self.uploaded_by = getuser()
def save(self, original:bool=True):
if original:
self.uploaded_by = getuser()
self.metadata.session.add(self)
self.metadata.session.commit()
return None
def update(self):
pass
def delete(self):
backup = self.to_dict()
try:
@@ -408,7 +412,7 @@ class BasicSubmission(Base):
Returns:
models.BasicSubmission | List[models.BasicSubmission]: Submission(s) of interest
"""
logger.debug(kwargs)
logger.debug(f"kwargs coming into query: {kwargs}")
# NOTE: if you go back to using 'model' change the appropriate cls to model in the query filters
if submission_type == None:
model = cls.find_subclasses(attrs=kwargs)
@@ -651,7 +655,7 @@ class BacterialCulture(BasicSubmission):
outstr = super().enforce_name(instr=instr, data=data)
def construct(data:dict|None=None) -> str:
"""
DEPRECIATED due to slowness. Search for the largest rsl number and increment by 1
Create default plate name.
Returns:
str: new RSL number
@@ -912,9 +916,10 @@ class WastewaterArtic(BasicSubmission):
source_row = lookup_ssa.row
source_column = lookup_ssa.column
except AttributeError:
plate = ""
plate = "Error"
source_row = 0
source_column = 0
# continue
samples.append(dict(
sample=sample.submitter_id,
destination_column=destination_column,
@@ -931,7 +936,7 @@ class WastewaterArtic(BasicSubmission):
df = pd.DataFrame.from_records(samples).fillna(value="")
df.source_row = df.source_row.astype(int)
df.source_column = df.source_column.astype(int)
df.sort_values(by=['destination_column', 'destination_row'], inplace=True)
df.sort_values(by=['plate_number', 'source_column', 'source_row'], inplace=True)
input_dict['csv'] = df
return input_dict

View File

@@ -145,7 +145,7 @@ class SubmissionsSheet(QTableView):
index = (self.selectionModel().currentIndex())
value = index.sibling(index.row(),1).data()
logger.debug(f"Selected value: {value}")
dlg = SubmissionComment(rsl=value)
dlg = SubmissionComment(parent=self, rsl=value)
if dlg.exec():
dlg.add_comment()
@@ -455,8 +455,10 @@ class SubmissionDetails(QDialog):
super().__init__(parent)
# self.ctx = ctx
self.app = parent.parent().parent().parent().parent().parent().parent
print(f"App: {self.app}")
try:
self.app = parent.parent().parent().parent().parent().parent().parent
except AttributeError:
self.app = None
self.setWindowTitle("Submission Details")
# create scrollable interior
interior = QScrollArea()
@@ -605,10 +607,12 @@ class SubmissionComment(QDialog):
"""
a window for adding comment text to a submission
"""
def __init__(self, rsl:str) -> None:
def __init__(self, parent, rsl:str) -> None:
super().__init__()
super().__init__(parent)
# self.ctx = ctx
self.app = parent.parent().parent().parent().parent().parent().parent
print(f"App: {self.app}")
self.rsl = rsl
self.setWindowTitle(f"{self.rsl} Submission Comment")
# create text field
@@ -632,16 +636,18 @@ class SubmissionComment(QDialog):
commenter = getuser()
comment = self.txt_editor.toPlainText()
dt = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
full_comment = {"name":commenter, "time": dt, "text": comment}
full_comment = [{"name":commenter, "time": dt, "text": comment}]
logger.debug(f"Full comment: {full_comment}")
# sub = lookup_submission_by_rsl_num(ctx = self.ctx, rsl_num=self.rsl)
# sub = lookup_submissions(ctx = self.ctx, rsl_number=self.rsl)
sub = BasicSubmission.query(rsl_number=self.rsl)
try:
sub.comment.append(full_comment)
except AttributeError:
sub.comment = [full_comment]
logger.debug(sub.__dict__)
sub.save()
# For some reason .append results in new comment being ignores, so have to concatenate lists.
sub.comment = sub.comment + full_comment
except AttributeError as e:
logger.error(f"Hit error {e} creating comment")
sub.comment = full_comment
# logger.debug(sub.comment)
sub.save(original=False)
# logger.debug(f"Save result: {result}")

View File

@@ -400,7 +400,7 @@ class SubmissionFormContainer(QWidget):
# obj.ctx.database_session.add(sub)
logger.debug(f"Existing {type(sub.pcr_info)}: {sub.pcr_info}")
logger.debug(f"Inserting {type(json.dumps(parser.pcr))}: {json.dumps(parser.pcr)}")
sub.save()
sub.save(original=False)
logger.debug(f"Got {len(parser.samples)} samples to update!")
logger.debug(f"Parser samples: {parser.samples}")
for sample in sub.samples: