本文整理汇总了Python中app.models.Role.insert_roles方法的典型用法代码示例。如果您正苦于以下问题:Python Role.insert_roles方法的具体用法?Python Role.insert_roles怎么用?Python Role.insert_roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Role
的用法示例。
在下文中一共展示了Role.insert_roles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_general
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setup_general():
"""Runs the set-up needed for both local development and production.
Also sets up first admin user."""
Role.insert_roles()
admin_query = Role.query.filter_by(name='Administrator')
if admin_query.first() is not None:
if User.query.filter_by(email=Config.ADMIN_EMAIL).first() is None:
user = User(
first_name='Radha',
last_name='Krishna',
password=Config.ADMIN_PASSWORD,
confirmed=True,
email=Config.ADMIN_EMAIL)
db.session.add(user)
db.session.commit()
print('Added administrator {}'.format(user.full_name()))
示例2: setup_general
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setup_general():
"""Runs the set-up needed for both local development and production.
Also sets up first admin user."""
Role.insert_roles()
admin_query = Role.query.filter_by(name='Administrator')
if admin_query.first() is not None:
if User.query.filter_by(email=Config.ADMIN_EMAIL).first() is None:
user = User(
first_name='Admin',
last_name='Account',
password=Config.ADMIN_PASSWORD,
confirmed=True,
email=Config.ADMIN_EMAIL)
db.session.add(user)
db.session.commit()
print('Added administrator {}'.format(user.full_name()))
示例3: deploy
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
"""Run deployment tasks."""
from flask_migrate import upgrade
from app.models import Role, User
# migrate database to latest revision
upgrade()
# create user roles
Role.insert_roles()
# create self-follows for all users
User.add_self_follows()
示例4: setUp
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
self.client = self.app.test_client()
示例5: setUp
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
示例6: setUpClass
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUpClass(cls):
# start Chrome
try:
cls.client = webdriver.Chrome(service_args=["--verbose", "--log-path=test-reports/chrome.log"])
except:
pass
# skip these tests if the browser could not be started
if cls.client:
# create the application
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
# suppress logging to keep unittest output clean
import logging
logger = logging.getLogger('werkzeug')
logger.setLevel("ERROR")
# create the database and populate with some fake data
db.create_all()
Role.insert_roles()
User.generate_fake(10)
Post.generate_fake(10)
# add an administrator user
admin_role = Role.query.filter_by(permissions=0xff).first()
admin = User(email='john@example.com',
username='john', password='cat',
role=admin_role, confirmed=True)
db.session.add(admin)
db.session.commit()
# start the Flask server in a thread
threading.Thread(target=cls.app.run).start()
# give the server a second to ensure it is up
time.sleep(1)
示例7: setUp
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
self.client = self.app.test_client(use_cookies=True)
示例8: deploy
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
from flask_migrate import upgrade
from app.models import Role
# 迁移数据库到最新修订版本
upgrade()
# 创建用户角色
Role.insert_roles()
示例9: test_roles_and_permissions
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_roles_and_permissions(self):
Role.insert_roles()
u = User(email='john@example.com', password='cat')
self.assertTrue(u.operation(Permission.WRITE_ARTICLES))
self.assertFalse(u.operation(Permission.MODERATE_COMMENTS))
示例10: test_roles_and_permissions
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_roles_and_permissions(self):
Role.insert_roles()
u = User(email='user@example.com', password='password')
self.assertTrue(u.can(Permission.GENERAL))
self.assertFalse(u.can(Permission.ADMINISTER))
示例11: test_make_administrator
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_make_administrator(self):
Role.insert_roles()
u = User(email='user@example.com', password='password')
self.assertFalse(u.can(Permission.ADMINISTER))
u.role = Role.query.filter_by(
permissions=Permission.ADMINISTER).first()
self.assertTrue(u.can(Permission.ADMINISTER))
示例12: test_administrator
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def test_administrator(self):
Role.insert_roles()
r = Role.query.filter_by(permissions=Permission.ADMINISTER).first()
u = User(email='user@example.com', password='password', role=r)
self.assertTrue(u.can(Permission.ADMINISTER))
self.assertTrue(u.can(Permission.GENERAL))
self.assertTrue(u.is_admin())
示例13: setUpClass
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def setUpClass(cls):
# start Firefox
try:
cls.client = webdriver.Firefox()
except:
pass
# skip these tests if the browser could not be started
if cls.client:
# create the application
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
# suppress logging to keep unittest output clean
import logging
logger = logging.getLogger('werkzeug')
logger.setLevel("ERROR")
# create the database and populate with some fake data
db.create_all()
Role.insert_roles()
User.generate_fake(10)
Post.generate_fake(10)
# add an administrator user
admin_role = Role.query.filter_by(permissions=0xff).first()
admin = User(email='john@example.com',
username='john', password='cat',
role=admin_role, confirmed=True)
db.session.add(admin)
db.session.commit()
# start the Flask server in a thread
threading.Thread(target=cls.app.run).start()
# give the server a second to ensure it is up
time.sleep(1)
示例14: deploy
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
"""Run deployment tasks."""
from flask.ext.migrate import upgrade
from app.models import Role, User
# migrate database to latest revision
upgrade()
# create user roles
Role.insert_roles()
# create self-follows for all users
User.add_self_follows()
示例15: deploy
# 需要导入模块: from app.models import Role [as 别名]
# 或者: from app.models.Role import insert_roles [as 别名]
def deploy():
"""Run deployment tasks."""
# 插入角色
Role.insert_roles()
# 插入管理员
User.insert_admin()