本文整理汇总了Python中share.util.IDObfuscator.decode方法的典型用法代码示例。如果您正苦于以下问题:Python IDObfuscator.decode方法的具体用法?Python IDObfuscator.decode怎么用?Python IDObfuscator.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类share.util.IDObfuscator
的用法示例。
在下文中一共展示了IDObfuscator.decode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_object
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import decode [as 别名]
def get_object(self):
queryset = self.filter_queryset(self.get_queryset())
# Perform the lookup filtering.
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
assert lookup_url_kwarg in self.kwargs, (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwarg)
)
try:
(model, decoded_pk) = IDObfuscator.decode(self.kwargs[lookup_url_kwarg])
concrete_model = self.serializer_class.Meta.model._meta.concrete_model
if model is not concrete_model:
raise serializers.ValidationError('The specified ID refers to an {}. Expected {}'.format(model._meta.model_name, concrete_model._meta.model_name))
except InvalidID:
raise serializers.ValidationError('Invalid ID')
filter_kwargs = {self.lookup_field: decoded_pk}
obj = get_object_or_404(queryset, **filter_kwargs)
# May raise a permission denied
self.check_object_permissions(self.request, obj)
return obj
示例2: get_raws
# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import decode [as 别名]
def get_raws(obj):
if isinstance(obj, str):
model, id = IDObfuscator.decode(obj)
else:
model = obj._meta.model
id = obj.id
return RawData.objects.filter(
normalizeddata__changeset__changes__target_id=id,
normalizeddata__changeset__changes__target_type=ContentType.objects.get_for_model(model, for_concrete_model=True)
)