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


Python reverse.reverse方法代码示例

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


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

示例1: test_it_serves_actions

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_it_serves_actions(self, api_client):
        action = ActionFactory(
            name="foo", implementation="foobar", arguments_schema={"type": "object"}
        )

        res = api_client.get("/api/v1/action/")
        action_url = reverse(
            "recipes:v1:action-implementation",
            kwargs={"name": action.name, "impl_hash": action.implementation_hash},
        )
        assert res.status_code == 200
        assert res.data == [
            {
                "name": "foo",
                "implementation_url": Whatever.endswith(action_url),
                "arguments_schema": {"type": "object"},
            }
        ] 
开发者ID:mozilla,项目名称:normandy,代码行数:20,代码来源:test_api.py

示例2: test_it_serves_actions

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_it_serves_actions(self, api_client):
        action = ActionFactory(
            name="foo", implementation="foobar", arguments_schema={"type": "object"}
        )

        res = api_client.get("/api/v3/action/")
        action_url = reverse(
            "recipes:v1:action-implementation",
            kwargs={"name": action.name, "impl_hash": action.implementation_hash},
        )
        assert res.status_code == 200
        assert res.data == {
            "count": 1,
            "next": None,
            "previous": None,
            "results": [
                {
                    "id": action.id,
                    "name": "foo",
                    "implementation_url": Whatever.endswith(action_url),
                    "arguments_schema": {"type": "object"},
                }
            ],
        } 
开发者ID:mozilla,项目名称:normandy,代码行数:26,代码来源:test_api.py

示例3: get

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def get(self, request, *_):
        if self.request.user.is_authenticated:
            routes = {
                'account': {
                    'show': reverse('account', request=request),
                    'delete': reverse('account-delete', request=request),
                    'change-email': reverse('account-change-email', request=request),
                    'reset-password': reverse('account-reset-password', request=request),
                },
                'logout': reverse('logout', request=request),
                'tokens': reverse('token-list', request=request),
                'domains': reverse('domain-list', request=request),
            }
        else:
            routes = {
                'register': reverse('register', request=request),
                'login': reverse('login', request=request),
                'reset-password': reverse('account-reset-password', request=request),
            }
        return Response(routes) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:22,代码来源:views.py

示例4: post

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def post(self, request, *args, **kwargs):
        # Check password and extract email
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        new_email = serializer.validated_data['new_email']

        action = models.AuthenticatedChangeEmailUserAction(user=request.user, new_email=new_email)
        verification_code = serializers.AuthenticatedChangeEmailUserActionSerializer(action).data['code']
        request.user.send_email('change-email', recipient=new_email, context={
            'confirmation_link': reverse('confirm-change-email', request=request, args=[verification_code]),
            'old_email': request.user.email,
            'new_email': new_email,
        })

        # At this point, we know that we are talking to the user, so we can tell that we sent an email.
        return Response(data={'detail': 'Please check your mailbox to confirm email address change.'},
                        status=status.HTTP_202_ACCEPTED) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:19,代码来源:views.py

示例5: test_create_donation

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_create_donation(self):
        url = reverse('v1:donation')
        data = {
            'name': 'Komplizierter Vörnämü-ßßß 马大为',
            'iban': 'DE89370400440532013000',
            'bic': 'BYLADEM1SWU',
            'amount': 123.45,
            'message': 'hi there, thank you. Also, some random chars:  ™ • ½ ¼ ¾ ⅓ ⅔ † ‡ µ ¢ £ € « » ♤ ♧ ♥ ♢ ¿ ',
            'email': 'email@example.com',
        }
        response = self.client.post(url, data)
        self.assertTrue(mail.outbox)
        email_internal = str(mail.outbox[0].message())
        direct_debit = str(mail.outbox[0].attachments[0][1])
        self.assertStatus(response, status.HTTP_201_CREATED)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(response.data['iban'], data['iban'])
        self.assertTrue('Komplizierter Vornamu' in direct_debit)
        self.assertTrue(data['iban'] in email_internal) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:21,代码来源:test_donations.py

示例6: test_status_create_with_img_and_desc

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_status_create_with_img_and_desc(self):
        self.status_user_token()
        url = api_reverse('api-status:list')
        # (w, h) = (800, 1280)
        # (255, 255, 255)
        image_item  = Image.new('RGB', (800, 1280), (0, 124, 174))
        tmp_file    = tempfile.NamedTemporaryFile(suffix='.jpg')
        image_item.save(tmp_file, format='JPEG')
        with open(tmp_file.name, 'rb') as file_obj:
            data = {
                'content': None,
                'image': file_obj
            }
            response = self.client.post(url, data, format='multipart')
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)
            

            self.assertEqual(Status.objects.count(), 2)
        temp_img_dir = os.path.join(settings.MEDIA_ROOT, 'status', 'testcfeuser')
        if os.path.exists(temp_img_dir):
            shutil.rmtree(temp_img_dir) 
开发者ID:codingforentrepreneurs,项目名称:REST-API,代码行数:23,代码来源:tests.py

示例7: test_status_delete

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_status_delete(self):
        data = self.create_item()
        data_id = data.get("id")
        rud_url = api_reverse('api-status:detail', kwargs={"id": data_id})
        rud_data = {
            'content': "another new content"
        }
        '''
        delete method / delete
        '''
        del_response = self.client.delete(rud_url, format='json')
        self.assertEqual(del_response.status_code, status.HTTP_204_NO_CONTENT)
        '''
        Not found
        '''
        get_response = self.client.get(rud_url, format='json')
        self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND) 
开发者ID:codingforentrepreneurs,项目名称:REST-API,代码行数:19,代码来源:tests.py

示例8: get

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def get(self, request, *args, **kwargs):
        ret = {}

        # Get the version namespace
        namespace = getattr(request.resolver_match, "namespace", "")
        for ns in namespace.split(":"):
            if re.match(r"v[0-9]+", ns, re.I):
                namespace = ns
                break

        if self.urlconf:
            urlconf = self.urlconf
        else:
            urlconf = import_module(settings.ROOT_URLCONF)
        endpoints = get_api_endpoints(urlconf.urlpatterns)

        for endpoint in sorted(endpoints, key=lambda e: e["pattern"].name):
            name = endpoint["pattern"].name
            if endpoint["method"] == "GET" and namespace in endpoint["namespace"].split(":"):
                allow_cdn = getattr(endpoint["pattern"], "allow_cdn", True)

                if not allow_cdn and settings.APP_SERVER_URL:
                    base = settings.APP_SERVER_URL
                else:
                    base = request.build_absolute_uri()

                try:
                    full_name = (
                        f'{endpoint["namespace"]}:{name}' if endpoint["namespace"] else name
                    )
                    path = reverse(full_name, *args, **kwargs)
                except NoReverseMatch:
                    continue

                full_url = urljoin(base, path)
                ret[name] = full_url

        return Response(ret) 
开发者ID:mozilla,项目名称:normandy,代码行数:40,代码来源:views.py

示例9: get_url

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def get_url(self, obj, view_name, request, format):
        if not obj.implementation:
            return None
        kwargs = {"name": obj.name, "impl_hash": obj.implementation_hash}

        if settings.CDN_URL is None:
            return reverse(view_name, kwargs=kwargs, request=request, format=format)
        else:
            request = None
            url = reverse(view_name, kwargs=kwargs, request=request, format=format)
            assert url[0] == "/"
            return settings.CDN_URL + url[1:] 
开发者ID:mozilla,项目名称:normandy,代码行数:14,代码来源:fields.py

示例10: get_absolute_url

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def get_absolute_url(self):
        return reverse("action-detail", args=[self.name]) 
开发者ID:mozilla,项目名称:normandy,代码行数:4,代码来源:models.py

示例11: cached_get

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def cached_get(self, request, format=None):
        data = {'links': {
            'user_offerings': reverse('api:MyOfferings', request=request)
        }}
        return Response(data) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:7,代码来源:api_views.py

示例12: setUp

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def setUp(self):
        super(ThreadViewTests, self).setUp()
        self.url = reverse('rest_messaging:threads-list') 
开发者ID:raphaelgyory,项目名称:django-rest-messaging,代码行数:5,代码来源:test_views.py

示例13: test_viewset_list_url

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_viewset_list_url(self):
        url = reverse("v1:contract-list")
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK) 
开发者ID:Code4PuertoRico,项目名称:contratospr-api,代码行数:6,代码来源:test_viewsets.py

示例14: test_viewset_detail_url

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_viewset_detail_url(self):
        url = reverse("v1:document-detail", args=[self.test_document.pk])
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK) 
开发者ID:Code4PuertoRico,项目名称:contratospr-api,代码行数:6,代码来源:test_viewsets.py

示例15: test_can_obtain_instance

# 需要导入模块: from rest_framework import reverse [as 别名]
# 或者: from rest_framework.reverse import reverse [as 别名]
def test_can_obtain_instance(self):
        entity = models.Entity(name="Test Entity", source_id=1)
        entity.save()
        url = reverse("v1:entity-detail", args=[entity.slug])
        response = self.client.get(url)
        for key in ("contracts_total", "contracts_count"):
            self.assertIn(key, response.data) 
开发者ID:Code4PuertoRico,项目名称:contratospr-api,代码行数:9,代码来源:test_viewsets.py


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