本文整理汇总了Python中flask_principal.Permission.union方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.union方法的具体用法?Python Permission.union怎么用?Python Permission.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_principal.Permission
的用法示例。
在下文中一共展示了Permission.union方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contact
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def contact(retailer_id, contact_id):
permisssion = Permission(RoleNeed('normal'))
need = ItemNeed('access', 'retailer', retailer_id)
if not permisssion.union(Permission(need)).can():
return abort(403)
retailer = Retailer.query.get(retailer_id)
contact = Contact.query.get(contact_id) if contact_id else Contact()
contact_form = ContactForm(obj=contact)
del contact_form.roles
if contact_form.validate_on_submit():
contact_form.populate_obj(contact)
contact.phone = contact_form.phone.data
if not contact.id:
retailer.contacts.append(contact)
db.session.commit()
flash(_('User updated.'), 'success')
kwargs = {
'retailer_id': retailer.id,
'contact_id': contact.id,
}
return redirect(url_for('retailers_bp.contact', **kwargs))
context = {
'user_id': contact.id,
'retailer': retailer,
'tab_counts': tab_counts(retailer),
'contact': contact,
'contact_form': contact_form,
}
return render_template('retailers/contact.html', **context)
示例2: test_permission_and
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def test_permission_and(self):
p1 = Permission(RoleNeed('boss'))
p2 = Permission(RoleNeed('lackey'))
p3 = p1 & p2
p4 = p1.union(p2)
assert p3.needs == p4.needs
示例3: index
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def index():
permisssion = Permission(RoleNeed('normal'))
retailers = Retailer.query.all()
for retailer in retailers[:]:
need = ItemNeed('access', 'retailer', retailer.id)
if not permisssion.union(Permission(need)).can():
retailers.remove(retailer)
context = {
'retailers': retailers,
}
return render_template('retailers/index.html', **context)
示例4: contacts
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def contacts(retailer_id):
permisssion = Permission(RoleNeed('normal'))
need = ItemNeed('access', 'retailer', retailer_id)
if not permisssion.union(Permission(need)).can():
return abort(403)
retailer = Retailer.query.get(retailer_id)
context = {
'retailer': retailer,
'contacts': retailer.contacts,
'tab_counts': tab_counts(retailer),
}
return render_template('retailers/contacts.html', **context)
示例5: index
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def index(retailer_id):
permisssion = Permission(RoleNeed('normal'))
need = ItemNeed('access', 'retailer', retailer_id)
if not permisssion.union(Permission(need)).can():
return abort(403)
retailer = Retailer.query.get(retailer_id)
context = {
'retailer': retailer,
'stocks': retailer.stocks.filter(RetailerProduct.sold_date.is_(None)),
'tab_counts': tab_counts(retailer),
}
return render_template('retailers/stocks.html', **context)
示例6: sell
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def sell(retailer_id, retailer_product_id):
permisssion = Permission(RoleNeed('normal'))
need = ItemNeed('access', 'retailer', retailer_id)
if not permisssion.union(Permission(need)).can():
return abort(403)
retailer = Retailer.query.get(retailer_id)
retailer_product = RetailerProduct.query.get(retailer_product_id)
if not retailer or not retailer_product or retailer.id != retailer_product.retailer_id:
return abort(404)
retailer_product.sold_date = date.today()
db.session.commit()
if tabapp.utils.request_wants_json():
return jsonify(success=_('Product sold.'), tab_counts=tab_counts(retailer))
flash(_('Product sold.'), 'success')
kwargs = {
'retailer_id': retailer.id,
}
return redirect(url_for('retailers_stocks_bp.index', **kwargs))
示例7: test_permission_union_denial
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
def test_permission_union_denial(self):
p1 = Permission(('a', 'b'))
p2 = Denial(('a', 'c'))
p3 = p1.union(p2)
assert p1.issubset(p3)
assert p2.issubset(p3)
示例8: SQLAlchemy
# 需要导入模块: from flask_principal import Permission [as 别名]
# 或者: from flask_principal.Permission import union [as 别名]
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from flask_principal import Principal, Permission, RoleNeed
principal = Principal(use_sessions=True)
pending_permission = Permission(RoleNeed(u'pending'))
new_permission = pending_permission.union(Permission(RoleNeed(u'new')))
dev_permission = Permission(RoleNeed(u'dev'))
admin_permission = dev_permission.union(Permission(RoleNeed(u'admin')))
user_permission = admin_permission.union(Permission(RoleNeed(u'user')))