1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/advlabdb/actions.py

44 lines
1.2 KiB
Python
Raw Normal View History

2022-09-24 14:16:48 +00:00
from flask import flash
from flask_login import current_user
from sqlalchemy import select
from .models import Assistant, Semester, User, db
def update_final_experiment_and_part_marks():
for semesterExperiment in current_user.active_semester.semester_experiments:
semesterExperiment.updateFinalExperimentAndPartMarks()
flash("Manually updated all final experiment and part marks.", "success")
def deactivate_assistants():
user_ids_to_deactivate = db.session.scalars(
select(Assistant.user_id)
.join(User)
.where(User.active == True)
.except_(
select(Assistant.user_id).join(Assistant.semester_experiments).join(Semester).where(Semester.done == False)
)
)
no_users_deactivated = True
try:
for user_id in user_ids_to_deactivate:
user = db.session.get(User, user_id)
user.active = False
flash(f"User {user} deactivated!", "warning")
no_users_deactivated = False
db.session.commit()
except Exception as ex:
flash(str(ex), "danger")
db.session.rollback()
no_users_deactivated = True
if no_users_deactivated:
flash("No users to deactivate.", "info")