当前位置: 首页>>代码示例>>Python>>正文


Python User.db方法代码示例

本文整理汇总了Python中assembl.models.User.db方法的典型用法代码示例。如果您正苦于以下问题:Python User.db方法的具体用法?Python User.db怎么用?Python User.db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assembl.models.User的用法示例。


在下文中一共展示了User.db方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: put_global_roles_for_user

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import db [as 别名]
def put_global_roles_for_user(request):
    user_id = request.matchdict['user_id']
    user = User.get_instance(user_id)
    session = User.db()
    if not user:
        raise HTTPNotFound("User id %s does not exist" % (user_id,))
    try:
        data = json.loads(request.body)
    except Exception as e:
        raise HTTPBadRequest("Malformed Json")
    if not isinstance(data, list):
        raise HTTPBadRequest("Not a list")
    if data and frozenset((type(x) for x in data)) != frozenset((str,)):
        raise HTTPBadRequest("not strings")
    roles = set(session.query(Role).filter(name in data).all())
    data = set(data)
    if len(roles) != len(data):
        raise HTTPBadRequest("Not valid roles: %s" % (repr(
            data - set((p.name for p in roles))),))
    known_gu_roles = session.query(UserRole).join(Role).filter(
        user=user).all()
    gur_by_role = {gur.role.name: gur for gur in known_gu_roles}
    known_roles = set(gur_by_role.keys())
    for role in known_roles - roles:
        session.query.delete(gur_by_role(role))
    for role in roles - known_roles:
        session.add(UserRole(user=user, role=role))
    return {"added": list(roles - known_roles),
            "removed": list(known_roles - roles)}
开发者ID:hellsingblack,项目名称:assembl,代码行数:31,代码来源:auth.py

示例2: get_global_roles_for_user

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import db [as 别名]
def get_global_roles_for_user(request):
    user_id = request.matchdict['user_id']
    session = User.db()
    if not session.query(User).get(user_id):
        raise HTTPNotFound("User id %s does not exist" % (user_id,))
    rolenames = session.query(Role.name).join(
        UserRole).filter(UserRole.user_id == user_id)
    return [x[0] for x in rolenames]
开发者ID:hellsingblack,项目名称:assembl,代码行数:10,代码来源:auth.py


注:本文中的assembl.models.User.db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。