本文整理匯總了Python中flask_security.RoleMixin方法的典型用法代碼示例。如果您正苦於以下問題:Python flask_security.RoleMixin方法的具體用法?Python flask_security.RoleMixin怎麽用?Python flask_security.RoleMixin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask_security
的用法示例。
在下文中一共展示了flask_security.RoleMixin方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_modify_permissions_unsupported
# 需要導入模塊: import flask_security [as 別名]
# 或者: from flask_security import RoleMixin [as 別名]
def test_modify_permissions_unsupported(app, datastore):
from tests.conftest import PonyUserDatastore
ds = datastore
if hasattr(datastore.role_model, "permissions"):
# already tested this
return
if isinstance(datastore, PonyUserDatastore):
# sigh - Pony doesn't use RoleMixin.
return
init_app_with_options(app, ds)
with app.app_context():
ds.create_role(name="test3")
ds.commit()
t3 = ds.find_role("test3")
with raises(NotImplementedError):
t3.add_permissions("whatever")
with raises(NotImplementedError):
t3.remove_permissions("whatever")
示例2: create_user_interface
# 需要導入模塊: import flask_security [as 別名]
# 或者: from flask_security import RoleMixin [as 別名]
def create_user_interface(db):
roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))
class Role(db.Model, RoleMixin):
id = db.Column(db.Integer(), primary_key=True) # pylint: disable=invalid-name
name = db.Column(db.String(80), unique=True)
description = db.Column(db.String(255))
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True) # pylint: disable=invalid-name
api_key = db.Column(db.String(255), default=_build_api_key, unique=True)
email = db.Column(db.String(255), unique=True)
password = db.Column(db.String(255))
active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime())
roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'))
return UserRoleDbInterface(db, User, Role)