mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-04 22:40:30 +00:00
is comparisons don't work with sqlalchemy! I love that silence ignorance!!! Not even a warning… Please, if you read this, consider rewriting in Rust and avoid ORMs.
This commit is contained in:
parent
7bbf0b861b
commit
99cc109cde
9 changed files with 21 additions and 19 deletions
|
@ -43,9 +43,9 @@ def deactivate_assistants():
|
||||||
user_ids_to_deactivate = db.session.scalars(
|
user_ids_to_deactivate = db.session.scalars(
|
||||||
select(Assistant.user_id)
|
select(Assistant.user_id)
|
||||||
.join(User)
|
.join(User)
|
||||||
.where(User.active is True)
|
.where(User.active == True)
|
||||||
.except_(
|
.except_(
|
||||||
select(Assistant.user_id).join(Assistant.semester_experiments).join(Semester).where(Semester.done is False)
|
select(Assistant.user_id).join(Assistant.semester_experiments).join(Semester).where(Semester.done == False)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -636,14 +636,14 @@ class GroupView(SecureAdminModelView):
|
||||||
if is_created:
|
if is_created:
|
||||||
|
|
||||||
def query_factory():
|
def query_factory():
|
||||||
return partStudentQueryFactory().where(PartStudent.group is None)
|
return partStudentQueryFactory().where(PartStudent.group == None)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def query_factory():
|
def query_factory():
|
||||||
return partStudentQueryFactory().where(
|
return partStudentQueryFactory().where(
|
||||||
or_(
|
or_(
|
||||||
and_(PartStudent.group is None, Part.program == group.program),
|
and_(PartStudent.group == None, Part.program == group.program),
|
||||||
PartStudent.group == group,
|
PartStudent.group == group,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -754,7 +754,7 @@ class ExperimentView(SecureAdminModelView):
|
||||||
|
|
||||||
|
|
||||||
def assistantQueryFactory():
|
def assistantQueryFactory():
|
||||||
return Assistant.query.join(User).where(User.active is True)
|
return Assistant.query.join(User).where(User.active == True)
|
||||||
|
|
||||||
|
|
||||||
def weighting_field(label: str, default: float):
|
def weighting_field(label: str, default: float):
|
||||||
|
@ -776,7 +776,7 @@ class SemesterExperimentView(SecureAdminModelView):
|
||||||
class CreateForm(FlaskForm):
|
class CreateForm(FlaskForm):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def experimentQueryFactory():
|
def experimentQueryFactory():
|
||||||
return Experiment.query.where(Experiment.active is True)
|
return Experiment.query.where(Experiment.active == True)
|
||||||
|
|
||||||
experiment = QuerySelectField(
|
experiment = QuerySelectField(
|
||||||
"Experiment",
|
"Experiment",
|
||||||
|
@ -937,7 +937,7 @@ class ExperimentRowFilter(FilterEqual):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
activeExperiments = db.session.scalars(select(Experiment).where(Experiment.active is True))
|
activeExperiments = db.session.scalars(select(Experiment).where(Experiment.active == True))
|
||||||
return tuple(
|
return tuple(
|
||||||
(
|
(
|
||||||
f"{activeExperiment.number},{activeExperiment.program_id}",
|
f"{activeExperiment.number},{activeExperiment.program_id}",
|
||||||
|
@ -1193,7 +1193,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
admins = db.session.scalars(select(Admin).join(User).where(User.active is True))
|
admins = db.session.scalars(select(Admin).join(User).where(User.active == True))
|
||||||
return tuple((admin.id, str(admin)) for admin in admins)
|
return tuple((admin.id, str(admin)) for admin in admins)
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
|
|
@ -88,7 +88,7 @@ def email_formatter(view, context, model, name: str):
|
||||||
|
|
||||||
def experiment_marks_missing_formatter(view, context, model, name: str):
|
def experiment_marks_missing_formatter(view, context, model, name: str):
|
||||||
experiment_marks_missing = getattr(model, name)
|
experiment_marks_missing = getattr(model, name)
|
||||||
if experiment_marks_missing is True:
|
if experiment_marks_missing == True:
|
||||||
return Markup("<span style='color: red;'>Yes</span>")
|
return Markup("<span style='color: red;'>Yes</span>")
|
||||||
|
|
||||||
return "No"
|
return "No"
|
||||||
|
|
|
@ -77,7 +77,7 @@ def mark_hists(markType, active_assistants):
|
||||||
|
|
||||||
|
|
||||||
def assistant_marks_analysis(cls):
|
def assistant_marks_analysis(cls):
|
||||||
active_assistants = db.session.scalars(select(Assistant).join(User).where(User.active is True)).all()
|
active_assistants = db.session.scalars(select(Assistant).join(User).where(User.active == True)).all()
|
||||||
|
|
||||||
if not active_assistants:
|
if not active_assistants:
|
||||||
flash("No active assistants!", "warning")
|
flash("No active assistants!", "warning")
|
||||||
|
|
|
@ -211,7 +211,7 @@ class AssistantUserView(SecureAssistantModelView):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def semesterQueryFactory():
|
def semesterQueryFactory():
|
||||||
# Show only last two semesters to assistants
|
# Show only last two semesters to assistants
|
||||||
return Semester.query.order_by(Semester.id.desc()).where(Semester.done is False).limit(2)
|
return Semester.query.order_by(Semester.id.desc()).where(Semester.done == False).limit(2)
|
||||||
|
|
||||||
active_semester = QuerySelectField(
|
active_semester = QuerySelectField(
|
||||||
"Active Semester",
|
"Active Semester",
|
||||||
|
|
|
@ -44,9 +44,9 @@ class SecureAdminIndexView(CustomIndexView):
|
||||||
.join(Assistant.semester_experiments)
|
.join(Assistant.semester_experiments)
|
||||||
.where(SemesterExperiment.semester == current_user.active_semester)
|
.where(SemesterExperiment.semester == current_user.active_semester)
|
||||||
.join(SemesterExperiment.group_experiments)
|
.join(SemesterExperiment.group_experiments)
|
||||||
.where(GroupExperiment.experiment_marks_missing is True)
|
.where(GroupExperiment.experiment_marks_missing == True)
|
||||||
.join(GroupExperiment.experiment_marks)
|
.join(GroupExperiment.experiment_marks)
|
||||||
.where(ExperimentMark.final_experiment_mark is None)
|
.where(ExperimentMark.final_experiment_mark == None)
|
||||||
.group_by(Assistant.id)
|
.group_by(Assistant.id)
|
||||||
.order_by(func.count().desc())
|
.order_by(func.count().desc())
|
||||||
)
|
)
|
||||||
|
@ -71,7 +71,7 @@ class SecureAssistantIndexView(CustomIndexView):
|
||||||
.where(SemesterExperiment.semester == current_user.active_semester)
|
.where(SemesterExperiment.semester == current_user.active_semester)
|
||||||
.join(SemesterExperiment.assistants)
|
.join(SemesterExperiment.assistants)
|
||||||
.where(Assistant.user == current_user)
|
.where(Assistant.user == current_user)
|
||||||
.where(ExperimentMark.final_experiment_mark is None)
|
.where(ExperimentMark.final_experiment_mark == None)
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.render(
|
return self.render(
|
||||||
|
@ -158,7 +158,7 @@ class CustomModelView(ModelView):
|
||||||
|
|
||||||
def update_model(self, form, model):
|
def update_model(self, form, model):
|
||||||
try:
|
try:
|
||||||
if self.customUpdateModel(form, model) is False:
|
if self.customUpdateModel(form, model) == False:
|
||||||
# Nothing changed
|
# Nothing changed
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -537,7 +537,7 @@ class Semester(db.Model):
|
||||||
if transferParts:
|
if transferParts:
|
||||||
semester.transferPartsFrom(oldSemester)
|
semester.transferPartsFrom(oldSemester)
|
||||||
|
|
||||||
for experiment in db.session.scalars(select(Experiment).where(Experiment.active is True)):
|
for experiment in db.session.scalars(select(Experiment).where(Experiment.active == True)):
|
||||||
newSemesterExperiment = SemesterExperiment(experiment=experiment, semester=semester)
|
newSemesterExperiment = SemesterExperiment(experiment=experiment, semester=semester)
|
||||||
|
|
||||||
if transferAssistants:
|
if transferAssistants:
|
||||||
|
@ -575,7 +575,7 @@ class Semester(db.Model):
|
||||||
.join(GroupExperiment)
|
.join(GroupExperiment)
|
||||||
.join(SemesterExperiment)
|
.join(SemesterExperiment)
|
||||||
.where(SemesterExperiment.semester == self)
|
.where(SemesterExperiment.semester == self)
|
||||||
.where(ExperimentMark.final_experiment_mark is None)
|
.where(ExperimentMark.final_experiment_mark == None)
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_done(self, next_semester=None):
|
def set_done(self, next_semester=None):
|
||||||
|
|
|
@ -13,7 +13,7 @@ def _reset_admin_password(manage):
|
||||||
app = create_app(create_for_server=False)
|
app = create_app(create_for_server=False)
|
||||||
|
|
||||||
with app.app_context(), db.session.begin():
|
with app.app_context(), db.session.begin():
|
||||||
admins = db.session.scalars(select(Admin).join(User).where(User.active is True)).all()
|
admins = db.session.scalars(select(Admin).join(User).where(User.active == True)).all()
|
||||||
activate_user = False
|
activate_user = False
|
||||||
|
|
||||||
if len(admins) == 0:
|
if len(admins) == 0:
|
||||||
|
|
|
@ -48,7 +48,9 @@ select = [
|
||||||
"RUF",
|
"RUF",
|
||||||
]
|
]
|
||||||
ignore = [
|
ignore = [
|
||||||
"E5",
|
"E501",
|
||||||
|
"E711",
|
||||||
|
"E712",
|
||||||
"S3",
|
"S3",
|
||||||
"S6",
|
"S6",
|
||||||
"RET504",
|
"RET504",
|
||||||
|
|
Loading…
Reference in a new issue