def create_editor(name, password, email): user = User.create_user(name, email, password) profile = UserProfile() profile.save() user.profile = profile role = Role.query.filter_by(name='editor').first() if not role: role = Role('editor', 'editor role') role.save() user.roles.append(role) user.save()
def create_admin(name, password, email): user = User.create_user(name, email, password) profile = UserProfile() profile.save() user.profile = profile user.save() role = Role.query.filter_by(name='admin').first() if not role: role = Role() role.name = 'admin' role.description = 'admin role' role.save() user.roles.append(role) role = Role.query.filter_by(name='editor').first() if not role: role = Role() role.name = 'editor' role.description = 'editor role' role.save() user.roles.append(role) user.save()
def init_db(): try: role = Role(name="editor", description="editor role") role.save() role = Role(name="admin", description="admin role") role.save() create_admin("admin", "111111", "*****@*****.**") create_editor("editor1", "111111", "*****@*****.**") create_editor("editor2", "111111", "*****@*****.**") create_common_user("wangbin", "111111", "*****@*****.**") create_common_user("xx", "111111", "*****@*****.**") create_common_user("jiyu", "111111", "*****@*****.**") create_common_user("quwenyu", "111111", "*****@*****.**") from youjiao.test_data import book_list, activity_list from youjiao.teach_material.models import Book from youjiao.content.models import Activity for book in book_list: b = Book(**book._asdict()) b.save() for activity in activity_list: a = Activity(**activity._asdict()) a.save() except Exception as e: print(e)
def create_admin(name, password, email): user = User.create_user(name, email, password) profile = UserProfile() profile.save() user.profile = profile role = Role.query.filter_by(name="admin").first() if not role: role = Role("admin", "admin role") role.save() user.roles.append(role) role = Role.query.filter_by(name="editor").first() if not role: role = Role("editor", "editor role") role.save() user.roles.append(role) user.save()
def init_db(): try: role = Role(name='editor', description='editor role') role.save() role = Role(name='admin', description='admin role') role.save() create_admin('admin', '111111', '*****@*****.**') create_editor('editor1', '111111', '*****@*****.**') create_editor('editor2', '111111', '*****@*****.**') create_common_user('wangbin', '111111', '*****@*****.**') create_common_user('xx', '111111', '*****@*****.**') create_common_user('jiyu', '111111', '*****@*****.**') create_common_user('quwenyu', '111111', '*****@*****.**') from youjiao.test_data import book_list, activity_list from youjiao.teach_material.models import Book from youjiao.content.models import Activity for book in book_list: b = Book(**book._asdict()) b.save() for activity in activity_list: a = Activity(**activity._asdict()) a.save() except Exception as e: print(e)