當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。