-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitial_data.py
29 lines (26 loc) · 1.37 KB
/
initial_data.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
from main import app
from application.models import db, Role
from werkzeug.security import generate_password_hash
from application.sec import datastore
with app.app_context():
db.create_all()
# librarian = Role(id="librarian", name="Librarian", description="Librarian Description")
# db.session.add(librarian)
# admin = Role(id="admin", name="Admin", description="Admin Description")
# db.session.add(admin)
# student = Role(id="student", name="Student", description="Student Description")
# db.session.add(student)
# try:
# db.session.commit()
# except:
# pass
datastore.find_or_create_role(name="Librarian", description="User is the Librarian")
datastore.find_or_create_role(name="Student", description="User is a Student")
db.session.commit()
if not datastore.find_user(email="[email protected]"):
datastore.create_user(email="[email protected]", password=generate_password_hash("librarian"), roles=['Librarian'])
if not datastore.find_user(email="[email protected]"):
datastore.create_user(email="[email protected]", password=generate_password_hash("student1"), roles=['Student'])
if not datastore.find_user(email="[email protected]"):
datastore.create_user(email="[email protected]", password=generate_password_hash("student2"),active=False, roles=['Student'])
db.session.commit()