1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-09-19 18:31:16 +00:00

Declare static methods

This commit is contained in:
Mo 2022-07-03 00:48:05 +02:00
parent 6bd7b4d910
commit ae665add07
4 changed files with 31 additions and 4 deletions

View file

@ -108,12 +108,15 @@ class UserView(SecureAdminModelView):
return query.where(User.active_semester_id == int(value))
class CreateForm(FlaskForm):
@staticmethod
def roleQueryFactory():
return Role.query
@staticmethod
def semesterQueryFactory():
return Semester.query
@staticmethod
def default_roles():
return [user_datastore.find_role("assistant")]
@ -271,6 +274,7 @@ class UserView(SecureAdminModelView):
class SemesterView(SecureAdminModelView):
class CreateForm(FlaskForm):
@staticmethod
def defaultFormLabel():
last_semester = Semester.lastSemester()
if last_semester.label == "WS":
@ -278,6 +282,7 @@ class SemesterView(SecureAdminModelView):
else:
return "WS"
@staticmethod
def defaultFormYear():
last_semester = Semester.lastSemester()
if last_semester.label == "WS":
@ -374,7 +379,7 @@ def programQueryFactory():
class PartView(SecureAdminModelView):
column_display_all_relations = True
column_sortable_list = []
column_sortable_list: list[str] = []
column_list = [
"program",
"number",
@ -448,6 +453,7 @@ class StudentView(SecureAdminModelView):
"part_students": part_student_part_formatter,
}
@staticmethod
def part_students_export_formatter(view, context, model, name):
part_students = deep_getattr(model, name)
if part_students is None:
@ -483,6 +489,7 @@ class PartStudentView(SecureAdminModelView):
return query.where(PartStudent.part_id == int(value))
class CreateForm(FlaskForm):
@staticmethod
def studentQueryFactory():
return Student.query
@ -559,6 +566,7 @@ class GroupView(SecureAdminModelView):
def apply(self, query, value, alias=None):
return query.where(Group.program_id == int(value))
@staticmethod
def formFactory(is_created, group):
if is_created:
@ -700,6 +708,7 @@ class SemesterExperimentView(SecureAdminModelView):
return query.join(Experiment).where(Experiment.program_id == int(value))
class CreateForm(FlaskForm):
@staticmethod
def experimentQueryFactory():
return Experiment.query.where(Experiment.active == True)
@ -790,6 +799,7 @@ def userHasRoleFilterFactory(column, role_name):
class AssistantView(SecureAdminModelView):
@staticmethod
def assistantUserQueryFactory():
return User.query.join(User.roles).where(Role.name == "assistant")
@ -870,6 +880,7 @@ class ExperimentRowFilter(FilterEqual):
for activeExperiment in activeExperiments
)
@staticmethod
def get_values(value):
values = value.split(",")
experimentNumber = int(values[0])
@ -976,6 +987,7 @@ class GroupExperimentView(SecureAdminModelView):
"experiment_marks_missing": experiment_marks_missing_formatter,
}
@staticmethod
def appointments_export_formatter(view, context, model, name):
appointments = deep_getattr(model, name)
if appointments is None:
@ -1227,7 +1239,7 @@ class ProgramView(SecureAdminModelView):
column_details_exclude_list = [
"groups",
]
column_sortable_list = []
column_sortable_list: list[str] = []
form_excluded_columns = [
"parts",
"experiments",
@ -1306,12 +1318,14 @@ class AnalysisView(SecureAdminBaseView):
label="Final part marks",
)
@staticmethod
def htmlFig(fig):
buf = BytesIO()
fig.savefig(buf, format="png")
return b64encode(buf.getbuffer()).decode("ascii")
@staticmethod
def markHist(data, title):
fig = Figure()
ax = fig.subplots()
@ -1336,6 +1350,7 @@ class AnalysisView(SecureAdminBaseView):
return AnalysisView.htmlFig(fig)
@staticmethod
def get_experiment_marks(assistant, attr):
data = []
@ -1346,6 +1361,7 @@ class AnalysisView(SecureAdminBaseView):
return np.array(data)
@staticmethod
def markHists(markType, activeAssistants):
attr = markType.lower() + "_mark"
markTypeTitleAddition = f" | {markType} marks"
@ -1368,6 +1384,7 @@ class AnalysisView(SecureAdminBaseView):
return hists
@staticmethod
def get_final_part_marks(part):
data = []
for partStudent in part.part_students:

View file

@ -66,6 +66,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
)
]
@staticmethod
def part_students_formatter(view, context, model, name):
part_students = deep_getattr(model, name)
if part_students is not None:
@ -73,6 +74,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
return ""
@staticmethod
def appointments_formatter(view, context, model, name):
appointments = deep_getattr(model, name)
if appointments is not None:
@ -193,7 +195,7 @@ class AssistantUserView(SecureAssistantModelView):
can_view_details = True
column_display_actions = True
column_sortable_list = []
column_sortable_list: list[str] = []
column_list = [
"email",

View file

@ -105,7 +105,7 @@ class CustomModelView(ModelView):
# Should not be a copy of column_formatters
# because of link formatting.
column_formatters_export = {}
column_formatters_export: dict = {}
# Used in the UserView because of create_user
# Should not be touched in other views

View file

@ -83,6 +83,7 @@ class PartStudent(db.Model):
def __str__(self):
return f"<{self.str()}>"
@staticmethod
def check(part, group):
if group is not None and group.program != part.program:
raise DataBaseException(
@ -180,6 +181,7 @@ class Group(db.Model):
def __str__(self):
return f"<{self.str()}>"
@staticmethod
def check(part_students, program=None):
commonProgram = part_students[0].part.program
@ -190,6 +192,7 @@ class Group(db.Model):
if partStudent.part.program != commonProgram:
raise DataBaseException(f"Part Students {part_students} are not in the same program!")
@staticmethod
def customInit(part_students):
Group.check(part_students)
@ -419,6 +422,7 @@ class Appointment(db.Model):
def __str__(self):
return f"<{self.str()}>"
@staticmethod
def checkAndGetAssistant(groupExperiment, assistant=None):
semesterExperiment = groupExperiment.semester_experiment
semesterExperimentAssistants = semesterExperiment.assistants
@ -507,6 +511,7 @@ class Semester(db.Model):
super().__init__(label=label, year=year)
@staticmethod
def initFromOldSemester(label, year, oldSemester, transferParts, transferAssistants):
semester = Semester(label=label, year=year)
@ -529,6 +534,7 @@ class Semester(db.Model):
for part in oldSemester.parts:
db.session.add(Part(program=part.program, number=part.number, semester=self))
@staticmethod
def sortedSemestersStartingWithNewest(limit=0):
# Inserting an older semester is not allowed!
# Therefore, the id is enough.
@ -539,6 +545,7 @@ class Semester(db.Model):
return db.session.execute(stmt).scalars()
@staticmethod
def lastSemester():
return Semester.sortedSemestersStartingWithNewest(limit=1).first()
@ -586,6 +593,7 @@ class ExperimentMark(db.Model):
def __str__(self):
return self.str()
@staticmethod
def check(part_student, group_experiment):
if not part_student.group:
raise DataBaseException("The part student does not have a group yet!")