本文整理汇总了Python中flask.ext.principal.Permission.description方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.description方法的具体用法?Python Permission.description怎么用?Python Permission.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.principal.Permission
的用法示例。
在下文中一共展示了Permission.description方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unauthorized_callback
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import description [as 别名]
@login_manager.unauthorized_handler
def unauthorized_callback():
flash('Login first')
return redirect(url_for('.login'))
class UserNotFoundError(Exception):
pass
# Needs
be_admin = RoleNeed('admin')
be_editor = RoleNeed('editor')
to_sign_in = ActionNeed('sign in')
# Permissions
user = Permission(to_sign_in)
user.description = "User's permissions"
editor = Permission(be_editor)
editor.description = "Editor's permissions"
admin = Permission(be_admin)
admin.description = "Admin's permissions"
apps_needs = [be_admin, be_editor, to_sign_in]
apps_permissions = [user, editor, admin]
#Permissions for more granular access control
modifyPost = namedtuple('posts', ['method', 'value'])
modifyPostNeed = partial(modifyPost, 'modifyPost')
class ModifyPostPermission(Permission):
def __init__(self, post_id):
need = modifyPostNeed(unicode(post_id))
示例2: init_login
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import description [as 别名]
from lightningwolf_smp.models import User
return db.session.query(User).get(user_id)
init_login()
# Flask-Principal
Principal(app, skip_static=True)
# Needs
admin_need = RoleNeed('admin')
user_need = RoleNeed('user')
# Permissions
user_permission = Permission(user_need)
user_permission.description = "User permission"
admin_permission = Permission(admin_need)
admin_permission.description = "Admin permission"
app_needs = {'admin': admin_need, 'user': user_need}
app_permissions = {'user': user_permission, 'admin': admin_permission}
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
# Set the identity user object
identity.user = current_user
# Add the UserNeed to the identity
if hasattr(current_user, 'id'):
identity.provides.add(UserNeed(current_user.id))
示例3: SQLAStorage
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import description [as 别名]
sql_storage = SQLAStorage(engine, metadata=meta)
blog = BloggingEngine(app, sql_storage)
mail = Mail(app)
babel = Babel(app)
sentry = Sentry(app)
# Needs
be_admin = RoleNeed('admin')
be_user = RoleNeed('user')
be_guest = RoleNeed('quest')
be_blogger = RoleNeed('blogger')
# Permissions
guest_per = Permission(be_guest)
guest_per.description = "Guest's permissions"
user_per = Permission(be_user)
user_per.description = "User's permissions"
blogger_per = Permission(be_blogger)
blogger_per.description = "Blogger's permissions"
admin_per = Permission(be_admin)
admin_per.description = "Admin's permissions"
apps_needs = [
be_admin, be_user, be_guest, be_blogger
]
apps_permissions = [
示例4: RoleNeed
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import description [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Blueprint
from flask.ext.principal import RoleNeed, Permission
# needs
be_super_admin = RoleNeed('super_admin')
be_admin = RoleNeed('admin')
# роли приложения
super_admin = Permission(be_admin, be_super_admin)
super_admin.description = "Super Administrator"
admin = Permission(be_admin)
admin.description = "Administrator"
app_roles = [super_admin, admin]
def get_roles_list():
result = list()
for roles in app_roles:
need = next(iter(roles.needs))
result.append({'role': need.value,
'description': roles.description})
return result
示例5: BloggingEngine
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import description [as 别名]
blog = BloggingEngine(app, sql_storage)
mail = Mail(app)
babel = Babel(app)
sentry = Sentry(app)
# Needs
be_admin = RoleNeed('admin')
be_user = RoleNeed('user')
be_guest = RoleNeed('quest')
be_blogger = RoleNeed('blogger')
be_performer = RoleNeed('performer')
# Permissions
guest_per = Permission(be_guest)
guest_per.description = "Guest's permissions"
user_per = Permission(be_user)
user_per.description = "User's permissions"
blogger_per = Permission(be_blogger)
blogger_per.description = "Blogger's permissions"
performer_per = Permission(be_performer)
performer_per.description = "Performer's permissions"
admin_per = Permission(be_admin)
admin_per.description = "Admin's permissions"
admin_or_performer_per = Permission(be_admin, be_performer)
admin_or_performer_per.description = "Admin's or Performer's permissions"