本文整理汇总了Python中flask.ext.principal.Permission类的典型用法代码示例。如果您正苦于以下问题:Python Permission类的具体用法?Python Permission怎么用?Python Permission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Policy:
def __init__(self, name):
self.name = name
self._action_need = ActionNeed(name)
self._permission = Permission(self._action_need)
def __str__(self):
return self.name
def __repr__(self):
return '<Policy %s>' % self.name
def can(self):
return self._permission.can()
def require(self, *args, **kwargs):
return self._permission.require(*args, **kwargs)
@property
def permission(self):
return self._permission
@property
def action_need(self):
return self._action_need
示例2: consignment_product
def consignment_product(id_):
from flask.ext.principal import Permission
Permission.union(CargoClerkPermission, AccountantPermission).test()
import litefac.apis as apis
current_product = apis.delivery.ConsignmentProductWrapper.get_product(id_)
if current_product:
if request.method == "GET":
return dict(current=current_product,
product_types=apis.product.get_product_types(),
products=json.dumps(apis.product.get_products()),
team_list=apis.manufacture.get_team_list(),
titlename=u"发货产品详情")
else:
class ProductForm(Form):
team_id = IntegerField("team_id")
product_id = IntegerField("product_id")
weight = IntegerField("weight")
returned_weight = IntegerField("returned_weight")
spec = TextField("spec")
type = TextField("type")
unit = TextField("unit")
form = ProductForm(request.form)
current_product.update(**form.data)
return redirect(
request.form.get("url") or url_for("delivery.consignment",
id_=current_product.consignment.id))
else:
return _(u"没有该产品编号:%d" + id_), 404
示例3: test_permission_difference
def test_permission_difference():
p1 = Permission(('a', 'b'), ('a', 'c'))
p2 = Permission(('a', 'c'), ('d', 'e'))
p3 = p1.difference(p2)
assert p3.allow == set([('a', 'b')])
p4 = p2.difference(p1)
assert p4.allow == set([('d', 'e')])
示例4: consignment
def consignment(id_=None):
import litefac.apis as apis
from flask.ext.principal import Permission
Permission.union(CargoClerkPermission, AccountantPermission).test()
if request.method == "GET":
cons = apis.delivery.get_consignment(id_)
team_list = apis.manufacture.get_team_list()
if not cons:
abort(404)
else:
return dict(plate=cons.plate, consignment=cons, titlename=u'发货单详情',
team_list=team_list)
else:
if id_:
cons = apis.delivery.get_consignment(id_)
if not cons:
abort(404)
params = {}
if request.form:
params["pay_in_cash"] = request.form.get("pay_in_cash",
type=int)
params["notes"] = request.form.get("notes")
try:
cons.update(cons.id, **params)
if CargoClerkPermission.can():
flash(u"更新成功")
except ValueError, e:
flash(unicode(e.message), "error")
else:
if cons.pay_in_cash:
cons.paid()
flash(u"支付成功")
return redirect(url_for("delivery.consignment", id_=id_,
url=request.form.get("url")))
示例5: test_contains
def test_contains():
p1 = Permission(RolePermit('boss'), RolePermit('lackey'))
p2 = Permission(RolePermit('lackey'))
assert p2.issubset(p1)
assert p2 in p1
示例6: get
def get(self, user_id):
""" Get details for a given user. """
personal_details_view = Permission(UserNeed(user_id))
is_self = personal_details_view.can()
user = User.query.get_or_404(user_id)
return {
'user': user.to_json(include_personal_data=is_self),
}
示例7: test
def test(self, *records):
if self._model_view.permission_required:
def _get_edit_need(obj):
pk = self._model_view.modell.get_pk_value(obj)
return self._model_view.edit_need(pk)
needs = [_get_edit_need(record) for record in records]
perm = Permission(*needs).union(Permission(
self._model_view.edit_all_need))
return 0 if perm.can() else ACTION_IMPERMISSIBLE
示例8: test_permission_or
def test_permission_or():
p1 = Permission(RolePermit('boss'), RolePermit('lackey'))
p2 = Permission(RolePermit('lackey'), RolePermit('underling'))
p3 = p1 | p2
p4 = p1.difference(p2)
assert p3.allow == p4.allow
示例9: decorated_view
def decorated_view(*args, **kwargs):
perm = Permission(*[RoleNeed(role) for role in roles])
if perm.can():
return fn(*args, **kwargs)
r1 = [r for r in roles]
r2 = [r.name for r in current_user.roles]
_logger.debug('Current user does not provide a required role. '
'Accepted: %s Provided: %s' % (r1, r2))
return _get_unauthorized_view()
示例10: decorated_view
def decorated_view(*args, **kwargs):
iden = Identity(g.user.id)
for r in g.user.roles:
iden.provides.add(RoleNeed(r.name))
g.identity = iden
perm = Permission(*[RoleNeed(role) for role in roles])
if perm.can():
return fn(*args, **kwargs)
abort(403, message=u"Недостаточно прав!")
示例11: test_permission_and
def test_permission_and():
p1 = Permission(RolePermit('boss'))
p2 = Permission(RolePermit('lackey'))
p3 = p1 & p2
p4 = p1.union(p2)
assert p3.allow == p4.allow
示例12: test_identity_allowed
def test_identity_allowed():
p1 = Permission(RolePermit('boss'), RolePermit('lackey'))
p2 = Permission(RolePermit('lackey'))
i = Identity(1)
i.provides(RolePermit('boss'))
assert p1.allows(i) == True
assert p2.allows(i) == False
示例13: delete
def delete(self, entry_id):
""" Delete the entry with the given ID. """
entry = Entry.query.get(entry_id)
delete_permission = Permission(UserNeed(entry.stream.creator_id))
if delete_permission.can():
db.session.delete(entry)
return {'msg': 'Entry deleted.'}
else:
return {
'msg': 'Only the stream creator can delete entries.',
}, 403
示例14: delete
def delete(self, stream_id):
""" Delete the stream with the given ID. """
stream = Stream.query.get_or_404(stream_id)
delete_permission = Permission(UserNeed(stream.creator_id))
if delete_permission.can():
movie = stream.movie
movie.number_of_streams -= 1
db.session.delete(stream)
db.session.add(movie)
return {'msg': 'Stream deleted.'}
else:
return {
'msg': "You're not allowed to delete this stream."
}, 403
示例15: us_airline_delay_prediction
def us_airline_delay_prediction():
'''
choose
:return:
'''
# permission management
# 权限管理
perm1 = Permission(Need('need1', 'my_value'))
perm2 = Permission(Need('need2', 'my_value'))
return render_template('us_airline_delay_prediction/data_analysis.html',
permission1=perm1.can(),
permission2=perm2.can(),
user=session['username'],
)