mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-09-19 18:31:16 +00:00
Apply SIM
This commit is contained in:
parent
029cc974e3
commit
b1d3c26b07
8 changed files with 245 additions and 273 deletions
|
@ -1084,8 +1084,7 @@ class GroupExperimentView(SecureAdminModelView):
|
||||||
self.session.add(appointment)
|
self.session.add(appointment)
|
||||||
|
|
||||||
def after_model_change(self, form, model, is_created):
|
def after_model_change(self, form, model, is_created):
|
||||||
if is_created:
|
if is_created and model.appointments:
|
||||||
if model.appointments:
|
|
||||||
flash(f"Appointments {model.appointments} added.", "success")
|
flash(f"Appointments {model.appointments} added.", "success")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,7 @@ def assistant_group_experiment_form_factory(current_user, group_experiment):
|
||||||
appointments = group_experiment.appointments
|
appointments = group_experiment.appointments
|
||||||
appointment_num = 1
|
appointment_num = 1
|
||||||
for appointment in appointments:
|
for appointment in appointments:
|
||||||
description = None
|
description = "Yes" if appointment.special else "No"
|
||||||
if appointment.special:
|
|
||||||
description = "Yes"
|
|
||||||
else:
|
|
||||||
description = "No"
|
|
||||||
|
|
||||||
setattr(
|
setattr(
|
||||||
AssistantGroupExperimentForm,
|
AssistantGroupExperimentForm,
|
||||||
|
|
|
@ -231,10 +231,7 @@ class Group(db.Model):
|
||||||
.order_by(Group.number.desc())
|
.order_by(Group.number.desc())
|
||||||
)
|
)
|
||||||
|
|
||||||
if highestGroupNumber is not None:
|
number = highestGroupNumber + 1 if highestGroupNumber is not None else 1
|
||||||
number = highestGroupNumber + 1
|
|
||||||
else:
|
|
||||||
number = 1
|
|
||||||
|
|
||||||
return Group(
|
return Group(
|
||||||
program=program,
|
program=program,
|
||||||
|
@ -529,8 +526,7 @@ class Semester(db.Model):
|
||||||
def __init__(self, label, year, **kwargs):
|
def __init__(self, label, year, **kwargs):
|
||||||
last_semester = Semester.lastSemester()
|
last_semester = Semester.lastSemester()
|
||||||
|
|
||||||
if last_semester is not None:
|
if last_semester is not None and (year < last_semester.year or (year == last_semester.year and label == "SS")):
|
||||||
if year < last_semester.year or (year == last_semester.year and label == "SS"):
|
|
||||||
raise DatabaseException(f"You can only create semesters later than the last semester {last_semester}!")
|
raise DatabaseException(f"You can only create semesters later than the last semester {last_semester}!")
|
||||||
|
|
||||||
super().__init__(label=label, year=year, **kwargs)
|
super().__init__(label=label, year=year, **kwargs)
|
||||||
|
|
|
@ -44,15 +44,9 @@ def post_login():
|
||||||
if current_active_semester.done:
|
if current_active_semester.done:
|
||||||
current_user.set_last_semester_as_active()
|
current_user.set_last_semester_as_active()
|
||||||
|
|
||||||
if current_user.has_role("admin"):
|
endpoint_base = "admin" if current_user.has_role("admin") else "assistant"
|
||||||
endpoint_base = "admin"
|
|
||||||
else:
|
|
||||||
endpoint_base = "assistant"
|
|
||||||
|
|
||||||
if current_user.login_count == 1:
|
url = url_for(endpoint_base + "_docs.index") if current_user.login_count == 1 else url_for(endpoint_base + ".index")
|
||||||
url = url_for(endpoint_base + "_docs.index")
|
|
||||||
else:
|
|
||||||
url = url_for(endpoint_base + ".index")
|
|
||||||
|
|
||||||
return redirect(url)
|
return redirect(url)
|
||||||
|
|
||||||
|
@ -60,10 +54,7 @@ def post_login():
|
||||||
@bp.route("/user-settings")
|
@bp.route("/user-settings")
|
||||||
@auth_required()
|
@auth_required()
|
||||||
def user_settings():
|
def user_settings():
|
||||||
if current_user.has_role("admin"):
|
role = "admin" if current_user.has_role("admin") else "assistant"
|
||||||
role = "admin"
|
|
||||||
else:
|
|
||||||
role = "assistant"
|
|
||||||
|
|
||||||
url = url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id)
|
url = url_for("main.index") + role + "/user/edit/?id=" + str(current_user.id)
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,7 @@ def _reset_admin_password(manage):
|
||||||
|
|
||||||
app = create_app(create_for_server=False)
|
app = create_app(create_for_server=False)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context(), db.session.begin():
|
||||||
with 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 is True)).all()
|
||||||
activate_user = False
|
activate_user = False
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ def _init_db(manage):
|
||||||
|
|
||||||
app = create_app(create_for_server=False)
|
app = create_app(create_for_server=False)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context(), db.session.begin():
|
||||||
with db.session.begin():
|
|
||||||
# Create new database
|
# Create new database
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
@ -54,9 +53,7 @@ def _init_db(manage):
|
||||||
|
|
||||||
admin_first_name = click.prompt("Enter the admin's first name")
|
admin_first_name = click.prompt("Enter the admin's first name")
|
||||||
admin_last_name = click.prompt("Enter the admin's last name")
|
admin_last_name = click.prompt("Enter the admin's last name")
|
||||||
admin_phone_number = click.prompt(
|
admin_phone_number = click.prompt("Enter the admin's phone number (optional)", default="", show_default=False)
|
||||||
"Enter the admin's phone number (optional)", default="", show_default=False
|
|
||||||
)
|
|
||||||
admin_mobile_phone_number = click.prompt(
|
admin_mobile_phone_number = click.prompt(
|
||||||
"Enter the admin's mobile phone number (optional)", default="", show_default=False
|
"Enter the admin's mobile phone number (optional)", default="", show_default=False
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,8 +45,7 @@ def _generate_test_db():
|
||||||
|
|
||||||
app = create_app(create_for_server=False)
|
app = create_app(create_for_server=False)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context(), db.session.begin():
|
||||||
with db.session.begin():
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
bs_prog = db_add(Program(label="BS"))
|
bs_prog = db_add(Program(label="BS"))
|
||||||
|
@ -83,10 +82,7 @@ def _generate_test_db():
|
||||||
semester_program_part_students[part.semester][part.program].append(part_student)
|
semester_program_part_students[part.semester][part.program].append(part_student)
|
||||||
|
|
||||||
for ind, name in enumerate(student_names):
|
for ind, name in enumerate(student_names):
|
||||||
if randint(0, 1) == 0: # nosec: B311
|
contact_email = f"{name[0]}-{name[1]}@private.de".lower() if ind % 2 == 0 else None
|
||||||
contact_email = f"{name[0]}-{name[1]}@private.de".lower()
|
|
||||||
else:
|
|
||||||
contact_email = None
|
|
||||||
|
|
||||||
student = db_add(
|
student = db_add(
|
||||||
Student(
|
Student(
|
||||||
|
@ -163,9 +159,7 @@ def _generate_test_db():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
semester_experiment = semester_experiments[ind % num_semester_experiments]
|
semester_experiment = semester_experiments[ind % num_semester_experiments]
|
||||||
group_experiment = db_add(
|
group_experiment = db_add(GroupExperiment(semester_experiment=semester_experiment, group=group))
|
||||||
GroupExperiment(semester_experiment=semester_experiment, group=group)
|
|
||||||
)
|
|
||||||
except DatabaseException as ex:
|
except DatabaseException as ex:
|
||||||
# Catch an error when a student becomes the same experiment for the second time.
|
# Catch an error when a student becomes the same experiment for the second time.
|
||||||
# Try the next experiment!
|
# Try the next experiment!
|
||||||
|
|
|
@ -27,7 +27,7 @@ requires = ["poetry-core>=1.0.0"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
select = ["E", "W", "F", "I", "UP", "YTT", "S", "B", "C4", "ICN", "PIE", "Q", "RET"]
|
select = ["E", "W", "F", "I", "UP", "YTT", "S", "B", "C4", "ICN", "PIE", "Q", "RET", "SIM"]
|
||||||
ignore = ["E5", "S3", "S6", "RET504"]
|
ignore = ["E5", "S3", "S6", "RET504"]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue