本文整理汇总了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)
示例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)