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


Python Record.filter_by_access方法代码示例

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


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

示例1: collection_dump

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import filter_by_access [as 别名]
def collection_dump(user, identifier, stream=None, prefix=None):

    # export collection
    collection = filter_by_access(user, Collection).get(id=identifier)

    # export collection items and records
    collectionitems = list(
        CollectionItem.objects
        .select_related('record', 'collection')
        .filter(collection__id=identifier)
    )
    ids = [collectionitem.record_id for collectionitem in collectionitems]
    records = list(Record.filter_by_access(user, *ids).filter(owner=None))
    ids = [record.id for record in records]
    collectionitems = [collectionitem for collectionitem in collectionitems
                       if collectionitem.record_id in ids]

    # export all fieldvalues
    fieldvalues = FieldValue.objects.select_related('record', 'field').filter(
        record__id__in=ids)

    used_fields = set(fieldvalue.field_id for fieldvalue in fieldvalues)

    # export all used fields
    fields = list(Field.objects.filter(id__in=used_fields).distinct())

    # export equivalent fields
    more = True
    while more:
        eq_ids = set(
            id
            for field in fields
            for id in field.equivalent.values_list('id', flat=True)
            if id not in used_fields
        )
        more = len(eq_ids) > 0
        if more:
            eq_fields = Field.objects.filter(id__in=eq_ids)
            fields.extend(eq_fields)
            used_fields = used_fields.union(eq_ids)

    # export all used standards
    standards = MetadataStandard.objects.filter(id__in=set(
        field.standard_id for field in fields if field.standard_id
    ))

    objects = [collection]
    objects.extend(standards)
    objects.extend(fields)
    objects.extend(collectionitem.record for collectionitem in collectionitems)
    objects.extend(collectionitems)
    objects.extend(fieldvalues)

    serializer = RenamingSerializer(prefix)
    kwargs = dict()
    if stream:
        kwargs['stream'] = stream
    return serializer.serialize(objects, use_natural_keys=True, **kwargs)
开发者ID:hanleybrand,项目名称:rooibos,代码行数:60,代码来源:functions.py

示例2: checkAccess

# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import filter_by_access [as 别名]
 def checkAccess(self, record, reader, writer, manager, owner, admin, user=False):
     self.assertEqual(reader, Record.filter_by_access(self.collectionreader, record.id).count() == 1)
     self.assertEqual(writer, Record.filter_by_access(self.collectionwriter, record.id).count() == 1)
     self.assertEqual(manager, Record.filter_by_access(self.collectionmanager, record.id).count() == 1)
     self.assertEqual(owner, Record.filter_by_access(self.owner, record.id).count() == 1)
     self.assertEqual(admin, Record.filter_by_access(self.admin, record.id).count() == 1)
     self.assertEqual(user, Record.filter_by_access(self.user, record.id).count() == 1)
开发者ID:eResearchSandpit,项目名称:rooibos,代码行数:9,代码来源:tests.py


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