50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
from imgui_bundle import hello_imgui
|
|
from model import *
|
|
from datetime import datetime
|
|
|
|
class AppState:
|
|
current_class_id: int
|
|
current_lecture_id: int
|
|
current_student_id: int
|
|
current_submission_id: int
|
|
|
|
def __init__(self):
|
|
self.current_class_id = None
|
|
self.current_lecture_id = None
|
|
self.current_student_id = None
|
|
self.current_submission_id = None
|
|
|
|
def update(self):
|
|
|
|
clas = Class.select()
|
|
self.current_class_id = clas[0].id if clas else None
|
|
|
|
lectures = Lecture.select().where(Lecture.class_id == self.current_class_id)
|
|
self.current_lecture_id = lectures[0].id if lectures else None
|
|
|
|
students = Student.select().where(Student.class_id == self.current_class_id)
|
|
self.current_student_id = students[0].id if students else None
|
|
|
|
submissions = Submission.select().where(Submission.lecture_id == self.current_lecture_id and Submission.student_id == self.current_student_id)
|
|
self.current_submission_id = submissions[0].id if submissions else None
|
|
|
|
LOG_DEBUG(f"Updated App State {repr(self)}")
|
|
|
|
def __repr__(self):
|
|
return f'''
|
|
Class ID: {self.current_class_id}
|
|
Lecture ID: {self.current_lecture_id}
|
|
Student ID: {self.current_student_id}
|
|
Submission ID: {self.current_submission_id}
|
|
'''
|
|
|
|
def log(log_level: hello_imgui.LogLevel, msg: str) -> None:
|
|
time = datetime.now().strftime("%X")
|
|
hello_imgui.log(log_level, f"[{time}] {msg}")
|
|
|
|
LOG_DEBUG = lambda msg: log(hello_imgui.LogLevel.debug, msg)
|
|
LOG_INFO = lambda msg: log(hello_imgui.LogLevel.info, msg)
|
|
LOG_WARNING = lambda msg: log(hello_imgui.LogLevel.warning, msg)
|
|
LOG_ERROR = lambda msg: log(hello_imgui.LogLevel.error, msg)
|
|
|