本文整理匯總了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()