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


Python IDObfuscator.decode_id方法代码示例

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


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

示例1: _resolve_ref

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import decode_id [as 别名]
 def _resolve_ref(self, ref):
     model = apps.get_model('share', model_name=ref['@type'])
     ct = ContentType.objects.get_for_model(model, for_concrete_model=True)
     try:
         if ref['@id'].startswith('_:'):
             return next(
                 change.target
                 for change in self._changes_cache
                 if change.target_type == ct
                 and change.node_id == ref['@id']
                 and change.target
             )
         return model._meta.concrete_model.objects.get(pk=IDObfuscator.decode_id(ref['@id']))
     except (StopIteration, model.DoesNotExist) as ex:
         raise Exception('Could not resolve reference {}'.format(ref)) from ex
开发者ID:Stevenholloway,项目名称:SHARE,代码行数:17,代码来源:change.py

示例2: get_search_results

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import decode_id [as 别名]
    def get_search_results(self, request, queryset, search_term):
        try:
            return queryset.filter(id=IDObfuscator.decode_id(search_term)), False
        except InvalidID:
            pass

        # Overriden because there is no way to opt out of a case insensitive search
        search_fields = self.get_search_fields(request)
        use_distinct = bool(search_term)
        if search_fields and search_term:
            orm_lookups = ['{}__startswith'.format(search_field) for search_field in search_fields]
            for bit in search_term.split():
                or_queries = [models.Q(**{orm_lookup: bit}) for orm_lookup in orm_lookups]
                queryset = queryset.filter(reduce(operator.or_, or_queries))

        return queryset, use_distinct
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:18,代码来源:share_objects.py

示例3: test_successful_post_no_home_page

# 需要导入模块: from share.util import IDObfuscator [as 别名]
# 或者: from share.util.IDObfuscator import decode_id [as 别名]
    def test_successful_post_no_home_page(self, client, source_add_user, mock_icon_urls):
        test_data = get_post_body()
        resp = client.post(
            self.endpoint,
            json.dumps(test_data),
            content_type='application/vnd.api+json',
            HTTP_AUTHORIZATION=source_add_user.authorization(),
        )
        assert resp.status_code == 201
        data = flatten_write_response(resp)

        created_label = data['source']['longTitle'].replace(' ', '_').lower()
        created_user = ShareUser.objects.get(pk=IDObfuscator.decode_id(data['user']['id']))

        assert data['source']['longTitle'] == test_data['data']['attributes']['long_title']
        assert data['source']['name'] == created_label
        assert data['source']['homePage'] is None
        assert data['user']['username'] == created_label
        assert data['user']['token'] == created_user.accesstoken_set.first().token
        assert created_user.is_trusted is True
开发者ID:CenterForOpenScience,项目名称:SHARE,代码行数:22,代码来源:test_sources_endpoint.py


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