mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-22 23:51:03 +00:00
150 lines
4.6 KiB
Python
150 lines
4.6 KiB
Python
from datetime import date
|
|
|
|
from flask_security import hash_password
|
|
|
|
from ... import app, db, user_datastore
|
|
from ...models import *
|
|
|
|
|
|
def main():
|
|
with app.app_context():
|
|
with db.session.begin():
|
|
db.drop_all()
|
|
db.create_all()
|
|
|
|
program1 = Program(label="BS")
|
|
program2 = Program(label="MS")
|
|
program3 = Program(label="BE")
|
|
|
|
db.session.add(program1)
|
|
db.session.add(program2)
|
|
db.session.add(program3)
|
|
|
|
sem1 = Semester(label="SS", year=22)
|
|
sem2 = Semester(label="WS", year=22)
|
|
|
|
db.session.add(sem1)
|
|
db.session.add(sem2)
|
|
|
|
partKwargs = [
|
|
{"program": program1, "number": 1},
|
|
{"program": program1, "number": 2},
|
|
{"program": program2, "number": 1},
|
|
{"program": program2, "number": 2},
|
|
{"program": program3, "number": 1},
|
|
]
|
|
for kwargs in partKwargs:
|
|
db.session.add(Part(semester=sem1, **kwargs))
|
|
|
|
sem2.transferPartsFrom(sem1)
|
|
|
|
part1 = sem2.parts[0]
|
|
part2 = sem2.parts[2]
|
|
|
|
student1 = Student(student_number=123, first_name="Mo", last_name="Bit", uni_email="m@test.com")
|
|
student2 = Student(student_number=1232, first_name="Mo2", last_name="Bit", uni_email="m2@test.com")
|
|
student3 = Student(student_number=1233, first_name="Mo3", last_name="Bit3", uni_email="m3@test.com")
|
|
|
|
db.session.add(student1)
|
|
db.session.add(student2)
|
|
db.session.add(student3)
|
|
|
|
ps1 = PartStudent(student=student1, part=part1)
|
|
ps2 = PartStudent(student=student2, part=part1)
|
|
ps3 = PartStudent(student=student3, part=part2)
|
|
|
|
db.session.add(ps1)
|
|
db.session.add(ps2)
|
|
db.session.add(ps3)
|
|
|
|
g1 = Group.customInit(part_students=[ps1, ps2])
|
|
g2 = Group.customInit(part_students=[ps3])
|
|
|
|
db.session.add(g1)
|
|
db.session.add(g2)
|
|
|
|
ex1 = Experiment(
|
|
number=1,
|
|
program=program1,
|
|
title="exp",
|
|
room="123",
|
|
building="phy",
|
|
responsibility="none",
|
|
duration_in_days=2,
|
|
)
|
|
|
|
ex2 = Experiment(
|
|
number=1,
|
|
program=program2,
|
|
title="exp2",
|
|
room="123",
|
|
building="phy",
|
|
responsibility="none",
|
|
duration_in_days=2,
|
|
)
|
|
|
|
db.session.add(ex1)
|
|
db.session.add(ex2)
|
|
|
|
sx1 = SemesterExperiment(experiment=ex1, semester=sem2)
|
|
sx2 = SemesterExperiment(experiment=ex2, semester=sem2)
|
|
|
|
db.session.add(sx1)
|
|
db.session.add(sx2)
|
|
|
|
gx1 = GroupExperiment(semester_experiment=sx1, group=g1)
|
|
gx2 = GroupExperiment(semester_experiment=sx2, group=g2)
|
|
|
|
db.session.add(gx1)
|
|
db.session.add(gx2)
|
|
|
|
adminRole = user_datastore.create_role(name="admin")
|
|
assistantRole = user_datastore.create_role(name="assistant")
|
|
|
|
admin_user = user_datastore.create_user(
|
|
email="admin@advlabdb.de",
|
|
password=hash_password("admin"),
|
|
roles=[adminRole],
|
|
first_name="Peter",
|
|
last_name="Blümler",
|
|
)
|
|
|
|
admin = Admin(user=admin_user)
|
|
|
|
db.session.add(admin)
|
|
|
|
us1 = user_datastore.create_user(
|
|
email="test@protonmail.com",
|
|
password=hash_password("h1"),
|
|
roles=[assistantRole],
|
|
first_name="As1",
|
|
last_name="l",
|
|
phone_number="012333212",
|
|
mobile_phone_number="012334123",
|
|
)
|
|
us2 = user_datastore.create_user(
|
|
email="test2@protonmail.com",
|
|
password=hash_password("h2"),
|
|
roles=[assistantRole],
|
|
first_name="As2",
|
|
last_name="l",
|
|
)
|
|
|
|
as1 = Assistant(user=us1)
|
|
as2 = Assistant(user=us2)
|
|
|
|
as1.semester_experiments.append(sx1)
|
|
as2.semester_experiments.append(sx2)
|
|
|
|
db.session.add(as1)
|
|
db.session.add(as2)
|
|
|
|
ap1 = Appointment(date=date(2021, 3, 21), special=True, group_experiment=gx1, assistant=as1)
|
|
ap2 = Appointment(date=date(2021, 3, 22), special=True, group_experiment=gx2, assistant=as2)
|
|
|
|
db.session.add(ap1)
|
|
db.session.add(ap2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|