本文整理汇总了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)