Created Sample verification before import.

This commit is contained in:
lwark
2025-03-27 15:02:18 -05:00
parent f215972b9d
commit e355aee5de
9 changed files with 179 additions and 416 deletions

View File

@@ -0,0 +1,67 @@
import logging
from pathlib import Path
from typing import List
from PyQt6.QtCore import Qt, pyqtSlot
from PyQt6.QtWebChannel import QWebChannel
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWidgets import (QDialog, QPushButton, QVBoxLayout,
QDialogButtonBox, QTextEdit, QGridLayout)
from backend.validators import PydSubmission
from tools import get_application_from_parent, jinja_template_loading
env = jinja_template_loading()
logger = logging.getLogger(f"submissions.{__name__}")
class SampleChecker(QDialog):
def __init__(self, parent, title:str, pyd: PydSubmission):
super().__init__(parent)
self.pyd = pyd
self.setWindowTitle(title)
self.app = get_application_from_parent(parent)
self.webview = QWebEngineView(parent=self)
self.webview.setMinimumSize(900, 500)
self.webview.setMaximumWidth(900)
self.layout = QGridLayout()
self.layout.addWidget(self.webview, 0, 0, 10, 10)
# NOTE: setup channel
self.channel = QWebChannel()
self.channel.registerObject('backend', self)
# NOTE: Used to maintain javascript functions.
# self.webview.page().setWebChannel(self.channel)
template = env.get_template("sample_checker.html")
template_path = Path(template.environment.loader.__getattribute__("searchpath")[0])
with open(template_path.joinpath("css", "styles.css"), "r") as f:
css = f.read()
html = template.render(samples=pyd.sample_list, css=css)
self.webview.setHtml(html)
QBtn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
self.buttonBox = QDialogButtonBox(QBtn)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.layout.addWidget(self.buttonBox, 11, 9, 1, 1, alignment=Qt.AlignmentFlag.AlignRight)
self.setLayout(self.layout)
self.webview.page().setWebChannel(self.channel)
@pyqtSlot(str, str, str)
def text_changed(self, submission_rank: str, key: str, new_value: str):
logger.debug(f"Name: {submission_rank}, Key: {key}, Value: {new_value}")
match key:
case "row" | "column":
value = [new_value]
case _:
value = new_value
try:
item = next((sample for sample in self.pyd.samples if int(submission_rank) in sample.submission_rank))
except StopIteration:
logger.error(f"Unable to find sample {submission_rank}")
item.__setattr__(key, value)

View File

@@ -22,6 +22,8 @@ from .omni_add_edit import AddEdit
from typing import List, Tuple
from datetime import date
from .sample_checker import SampleChecker
logger = logging.getLogger(f"submissions.{__name__}")
@@ -135,8 +137,16 @@ class SubmissionFormContainer(QWidget):
except AttributeError:
self.prsr = SheetParser(filepath=fname)
self.pyd = self.prsr.to_pydantic()
self.form = self.pyd.to_form(parent=self)
self.layout().addWidget(self.form)
# logger.debug(f"Samples: {pformat(self.pyd.samples)}")
checker = SampleChecker(self, "Sample Checker", self.pyd)
if checker.exec():
logger.debug(pformat(self.pyd.samples))
self.form = self.pyd.to_form(parent=self)
self.layout().addWidget(self.form)
else:
message = "Submission cancelled."
logger.warning(message)
report.add_result(Result(msg=message, owner=self.__class__.__name__, status="Warning"))
return report
@report_result