本文整理汇总了Python中share.util.IDObfuscator.encode_id方法的典型用法代码示例。如果您正苦于以下问题:Python IDObfuscator.encode_id方法的具体用法?Python IDObfuscator.encode_id怎么用?Python IDObfuscator.encode_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类share.util.IDObfuscator
的用法示例。
在下文中一共展示了IDObfuscator.encode_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate_types
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode_id [as 别名]
def populate_types(data):
model = apps.get_model(data['type'])
data['id'] = IDObfuscator.encode_id(data['id'], model)
data['type'] = model._meta.verbose_name
data['types'] = []
for parent in model.mro():
if not parent._meta.proxy:
break
data['types'].append(parent._meta.verbose_name)
return data
示例2: create
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode_id [as 别名]
def create(self, request, *args, **kwargs):
serializer = self.get_serializer_class()(data=request.data, context={'request': request})
serializer.is_valid(raise_exception=True)
with transaction.atomic():
# Hack for back-compat: Ingest halfway synchronously, then apply changes asynchronously
ingester = Ingester(serializer.validated_data['data']).as_user(request.user).ingest(apply_changes=False)
ingester.job.reschedule(claim=True)
nd_id = models.NormalizedData.objects.filter(
raw=ingester.raw,
ingest_jobs=ingester.job
).order_by('-created_at').values_list('id', flat=True).first()
async_result = ingest.delay(job_id=ingester.job.id, urgent=True)
# TODO Use an actual serializer
return Response({
'id': IDObfuscator.encode_id(nd_id, models.NormalizedData),
'type': 'NormalizedData',
'attributes': {
'task': async_result.id,
'ingest_job': request.build_absolute_uri(reverse('api:ingestjob-detail', args=[IDObfuscator.encode(ingester.job)])),
}
}, status=status.HTTP_202_ACCEPTED)
示例3: encode_id
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode_id [as 别名]
def encode_id(resource_id, resource_type):
return encoding.force_text(IDObfuscator.encode_id(resource_id, apps.get_model('share', resource_type)))
示例4: post_process
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode_id [as 别名]
def post_process(self, data):
return {'id': IDObfuscator.encode_id(data['id'], models.Tag), 'type': 'tag', 'name': data['name']}
示例5: oai_identifier
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import encode_id [as 别名]
def oai_identifier(self, work):
if isinstance(work, int):
share_id = IDObfuscator.encode_id(work, AbstractCreativeWork)
else:
share_id = IDObfuscator.encode(work)
return 'oai{delim}{repository}{delim}{id}'.format(id=share_id, repository=self.REPOSITORY_IDENTIFIER, delim=self.IDENTIFER_DELIMITER)