-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulate_database.py
49 lines (42 loc) · 1.51 KB
/
populate_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from member_database import create_app, db
from member_database.authentication import ACCESS_LEVELS, AccessLevel, Role, User
from member_database.events.common_schemata import ABSOLVENTENFEIER, TOOLBOX
from member_database.events.models import Event
from member_database.models import Person
app = create_app()
app.app_context().push()
if Person.query.filter_by(email="[email protected]").first() is None:
print("Creating user admin")
p = Person(name="Albert Admin", email="[email protected]")
u = User(person=p, username="admin")
u.set_password("testdb")
access_levels = [db.session.get(AccessLevel, level) for level in ACCESS_LEVELS]
r = Role(id="admin", access_levels=access_levels)
u.roles.append(r)
db.session.add(p, u)
db.session.commit()
else:
print("user already exists")
if Event.query.first() is None:
print("creating event")
event = Event(
name="Toolbox Workshop 2019",
description="Toller Workshop",
max_participants=1,
registration_open=True,
registration_schema=TOOLBOX,
)
db.session.add(event)
db.session.commit()
else:
print("Event already exists")
if Event.query.filter_by(name="Absolventenfeier 2019").first() is None:
print("Adding ABSOLVENTENFEIER")
event = Event(
name="Absolventenfeier 2019",
description="Absolventenfeier des Jahres 2019",
registration_open=True,
registration_schema=ABSOLVENTENFEIER,
)
db.session.add(event)
db.session.commit()