本文整理汇总了Python中flask.ext.principal.Permission.can方法的典型用法代码示例。如果您正苦于以下问题:Python Permission.can方法的具体用法?Python Permission.can怎么用?Python Permission.can使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.principal.Permission
的用法示例。
在下文中一共展示了Permission.can方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def index():
perm1 = Permission(Need('need1', 'my_value'))
perm2 = Permission(Need('need2', 'my_value'))
perm3 = Permission(Need('need3', 'my_value'))
return render_template('index.html',
# rate_graph_dianshang_list=rate_graph_dianshang_list,
# rate_graph_work_list = rate_graph_work_list,
# rate_graph_others_list = rate_graph_others_list,
permission1=perm1.can(),
permission2=perm2.can(),
permission3=perm3.can(),
user=session['username']
)
示例2: __init__
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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
示例3: has_permission
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def has_permission(self, permission_type, objectId):
if objectId is None:
return True
admin = Permission(RoleNeed(ROLE_ADMIN))
if isinstance(permission_type, tuple):
for permission_type_item in permission_type:
permission = permission_type_item(unicode(objectId))
if permission.can() or admin.can():
return True
else:
permission = permission_type(unicode(objectId))
if permission.can() or admin.can():
return True
return False
示例4: us_airline_delay_prediction
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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'],
)
示例5: housing_price
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def housing_price():
'''
controller layer for housing_price
:return:
'''
# 与界面交互
now = datetime.datetime.utcnow() - datetime.timedelta(days=1)
last_day = now - datetime.timedelta(days=80)
now_str = str(now)[:10]
last_day_str = str(last_day)[:10]
date_begin = request.args.get('begin', last_day_str, type=str)
date_end = request.args.get('end', now_str, type=str)
smooth_days = request.args.get('day', 0, type=int)
# get city name
city_name = request.args.get('city', 'Beijing', type=str)
# get housing_price_list
housing_price_model = HousingPriceModel()
housing_price_list = housing_price_model.get_housing_price_list(date_end,date_begin,smooth_days,city_name)
print housing_price_list
# list to json
housing_price_list_json = json.dumps(housing_price_list,encoding='utf-8')
# permission
perm1 = Permission(Need('need1', 'my_value'))
perm2 = Permission(Need('need2', 'my_value'))
perm3 = Permission(Need('need3', 'my_value'))
if perm2.can():
return render_template('housing_price/housing_price.html',
title=("{0} HousingPrice ".format(city_name)).decode('utf8'),
smooth=u'smooth days',
city_name=city_name,
module_list=housing_price_list_json,
smooth_num_list=smooth_num_list,
user=session['username'],
permission1=perm1.can(),
permission2=perm2.can(),
permission3=perm3.can(),
date_begin=date_begin,
date_end=date_end
)
return redirect(url_for('housing_price', _external=True, _scheme='http'))
示例6: get
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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: decorated_view
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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()
示例8: test
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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
示例9: decorated_view
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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"Недостаточно прав!")
示例10: delete
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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
示例11: minneapolis_simple_analysis
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def minneapolis_simple_analysis():
'''
choose housing price city
:return:
'''
# permission manage
perm1 = Permission(Need('need1', 'my_value'))
perm2 = Permission(Need('need2', 'my_value'))
# get the parameter from the form
lat = request.args.get('lati',44.977276 , type=float)
lon = request.args.get('long', -93.232266, type=float)
date = request.args.get('date', '', type=str)
time = request.args.get('time', "12:00", type=str)
global crime_model
top_2_result = crime_model.predict_from_rf(lat,lon,date,time,2)
maker_box = "Latitude:{0}<br>Longtitude:{1}<br>Time:{2}<br>Predictions: <ol>{3} for {4}</ol><ol>{5} for {6}</ol>".format(lat,lon,time,
top_2_result[0][0],top_2_result[0][1],top_2_result[1][0],top_2_result[1][1])
sndmap = Map(
identifier="sndmap",
varname="sndmap",
zoom=11,
lat=44.977276,
lng=-93.232266,
style="height:600px;width:1200px;margin:0;",
markers={
# icons.dots.green: [(37.4419, -122.1419), (37.4500, -122.1350)],
icons.dots.blue: [(lat, lon, maker_box)]
}
)
return render_template(
'minneapolis_crime_prediction/data_analysis_crimes.html',
permission1=perm1.can(),
permission2=perm2.can(),
user=session['username'],
sndmap=sndmap,
)
示例12: first_tier_city_list
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def first_tier_city_list():
'''
choose housing price city
:return:
'''
# 权限管理
city_list = { x for x in LIANJIA_MAP}
city_dict = {}
for pos,x in enumerate(city_list):
city_dict[pos+1] = x
perm1 = Permission(Need('need1', 'my_value'))
perm2 = Permission(Need('need2', 'my_value'))
return render_template('housing_price/city_dict.html',
title='Choose City',
permission1=perm1.can(),
permission2=perm2.can(),
user=session['username'],
city_dict=city_dict
)
示例13: delete
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
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
示例14: put
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def put(self, stream_id):
""" Update the stream with the given ID. """
stream = Stream.query.get_or_404(stream_id)
edit_permission = Permission(UserNeed(stream.creator_id))
if edit_permission.can():
form = StreamForm(obj=stream)
if form.validate_on_submit():
form.populate_obj(stream)
return {
'msg': 'Stream updated.',
'stream': stream.to_json(),
}
return {
'msg': 'Some attributes did not pass validation.',
'errors': form.errors,
}, 400
else:
return {
'msg': "You're not allowed to edit this stream"
}, 403
示例15: put
# 需要导入模块: from flask.ext.principal import Permission [as 别名]
# 或者: from flask.ext.principal.Permission import can [as 别名]
def put(self, entry_id):
""" Update the entry with the given ID. """
entry = Entry.query.get_or_404(entry_id)
put_permission = Permission(UserNeed(entry.stream.creator_id))
if put_permission.can():
form = EntryForm(obj=entry)
if form.validate_on_submit():
form.populate_obj(entry)
return {
'msg': 'Entry updated.',
'entry': entry.to_json(),
}
return {
'msg': 'Some attributes did not pass validation.',
'errors': form.errors,
}, 400
else:
return {
'msg': "Only the stream creator can edit it's entries.",
}, 403