當前位置: 首頁>>代碼示例>>Python>>正文


Python principal.Permission類代碼示例

本文整理匯總了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
開發者ID:Scille,項目名稱:kalon,代碼行數:25,代碼來源:permissions.py

示例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
開發者ID:xiechao06,項目名稱:litefac,代碼行數:32,代碼來源:views.py

示例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')])
開發者ID:baijum,項目名稱:flask-principal,代碼行數:7,代碼來源:test_principal.py

示例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")))
開發者ID:xiechao06,項目名稱:litefac,代碼行數:35,代碼來源:views.py

示例5: test_contains

def test_contains():

    p1 = Permission(RolePermit('boss'), RolePermit('lackey'))
    p2 = Permission(RolePermit('lackey'))

    assert p2.issubset(p1)
    assert p2 in p1
開發者ID:baijum,項目名稱:flask-principal,代碼行數:7,代碼來源:test_principal.py

示例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),
     }
開發者ID:streamr,項目名稱:marvin,代碼行數:8,代碼來源:users.py

示例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
開發者ID:PuZheng,項目名稱:Flask-DataBrowser,代碼行數:9,代碼來源:action.py

示例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
開發者ID:baijum,項目名稱:flask-principal,代碼行數:9,代碼來源:test_principal.py

示例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()
開發者ID:gothm,項目名稱:flask-security,代碼行數:9,代碼來源:decorators.py

示例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"Недостаточно прав!")
開發者ID:StasEvseev,項目名稱:adminbuy,代碼行數:9,代碼來源:decorators.py

示例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
開發者ID:baijum,項目名稱:flask-principal,代碼行數:9,代碼來源:test_principal.py

示例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
開發者ID:baijum,項目名稱:flask-principal,代碼行數:10,代碼來源:test_principal.py

示例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
開發者ID:streamr,項目名稱:marvin,代碼行數:11,代碼來源:entries.py

示例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
開發者ID:streamr,項目名稱:marvin,代碼行數:14,代碼來源:streams.py

示例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'],
                           )
開發者ID:TMAC135,項目名稱:data-monitor,代碼行數:16,代碼來源:monitor_HousingPrice.py


注:本文中的flask.ext.principal.Permission類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。