本文整理汇总了Python中aleph.model.Collection.all_ids方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.all_ids方法的具体用法?Python Collection.all_ids怎么用?Python Collection.all_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Collection
的用法示例。
在下文中一共展示了Collection.all_ids方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_ids [as 别名]
def collections(action):
"""Pre-load collection authorisation info and cache the result.
This is the core authorisation function, and is called at least once per
request. It will query and cache the ID for all collections the current
user is authorised to read or write.
"""
if not hasattr(request, 'auth_collections'):
public_roles = get_public_roles()
request.auth_collections = {READ: set(), WRITE: set(), PUBLIC: set()}
q = db.session.query(Permission.collection_id,
Permission.role_id,
Permission.read,
Permission.write)
q = q.filter(Permission.deleted_at == None) # noqa
q = q.filter(Permission.role_id.in_(request.auth_roles))
q = q.filter(Permission.collection_id != None) # noqa
for collection_id, role_id, read, write in q:
if read or write:
request.auth_collections[READ].add(collection_id)
if role_id in public_roles:
request.auth_collections[PUBLIC].add(collection_id)
if write and request.logged_in:
request.auth_collections[WRITE].add(collection_id)
if is_admin():
q = Collection.all_ids().filter(Collection.deleted_at == None) # noqa
for collection_id, in q:
request.auth_collections[READ].add(collection_id)
request.auth_collections[WRITE].add(collection_id)
return list(request.auth_collections.get(action, []))
示例2: collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_ids [as 别名]
def collections(self, action):
if action in self._collections:
return self._collections.get(action)
prefix_key = cache.key(self.PREFIX)
key = cache.key(self.PREFIX, action, self.id)
collections = cache.get_list(key)
if len(collections):
collections = [int(c) for c in collections]
self._collections[action] = collections
log.debug("[C] Authz: %s (%s): %s", self, action, collections)
return collections
if self.is_admin:
q = Collection.all_ids()
else:
q = db.session.query(Permission.collection_id)
q = q.filter(Permission.deleted_at == None) # noqa
q = q.filter(Permission.role_id.in_(self.roles))
if action == self.READ:
q = q.filter(Permission.read == True) # noqa
if action == self.WRITE:
q = q.filter(Permission.write == True) # noqa
q = q.distinct()
# log.info("Query: %s", q)
collections = [c for (c,) in q.all()]
log.debug("Authz: %s (%s): %s", self, action, collections)
cache.kv.sadd(prefix_key, key)
cache.set_list(key, collections)
self._collections[action] = collections
return collections
示例3: collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_ids [as 别名]
def collections(action):
if not hasattr(request, 'auth_collections'):
request.auth_collections = {READ: set(), WRITE: set()}
if is_admin():
q = Collection.all_ids().filter(Collection.deleted_at == None) # noqa
for col_id, in q:
request.auth_collections[READ].add(col_id)
request.auth_collections[WRITE].add(col_id)
else:
q = Permission.all()
q = q.filter(Permission.role_id.in_(request.auth_roles))
q = q.filter(Permission.collection_id != None) # noqa
for perm in q:
if perm.read or perm.write:
request.auth_collections[READ].add(perm.collection_id)
if perm.write and request.logged_in:
request.auth_collections[WRITE].add(perm.collection_id)
return list(request.auth_collections.get(action, []))
示例4: collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import all_ids [as 别名]
def collections(action):
if not hasattr(request, 'auth_collections'):
public_roles = get_public_roles()
request.auth_collections = {READ: set(), WRITE: set(), PUBLIC: set()}
q = db.session.query(Permission.collection_id,
Permission.role_id,
Permission.read,
Permission.write)
q = q.filter(Permission.deleted_at == None) # noqa
q = q.filter(Permission.role_id.in_(request.auth_roles))
q = q.filter(Permission.collection_id != None) # noqa
for collection_id, role_id, read, write in q:
if read or write:
request.auth_collections[READ].add(collection_id)
if role_id in public_roles:
request.auth_collections[PUBLIC].add(collection_id)
if write and request.logged_in:
request.auth_collections[WRITE].add(collection_id)
if is_admin():
q = Collection.all_ids().filter(Collection.deleted_at == None) # noqa
for collection_id, in q:
request.auth_collections[READ].add(collection_id)
request.auth_collections[WRITE].add(collection_id)
return list(request.auth_collections.get(action, []))