當前位置: 首頁>>代碼示例>>Python>>正文


Python urls.reverse_lazy方法代碼示例

本文整理匯總了Python中django.urls.reverse_lazy方法的典型用法代碼示例。如果您正苦於以下問題:Python urls.reverse_lazy方法的具體用法?Python urls.reverse_lazy怎麽用?Python urls.reverse_lazy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.urls的用法示例。


在下文中一共展示了urls.reverse_lazy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_post_checkout

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_post_checkout(self):
        """
        Test correctly posting to the checkout view
        """
        country = CountryFactory()
        request = RequestFactory().post(
            reverse_lazy('longclaw_checkout_view'),
            {
                'shipping-name': 'bob',
                'shipping-line_1': 'blah blah',
                'shipping-postcode': 'ytxx 23x',
                'shipping-city': 'London',
                'shipping-country': country.pk,
                'email': 'test@test.com'
            }
        )
        request.session = {}
        bid = basket_id(request)
        BasketItemFactory(basket_id=bid)
        response = CheckoutView.as_view()(request)
        self.assertEqual(response.status_code, 302) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:23,代碼來源:tests.py

示例2: get

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def get(self, request, instance, redirect_url, *args, **kwargs):
        itens_compra = instance.itens_compra.all()
        pagamentos = instance.parcela_pagamento.all()

        instance.pk = None
        instance.id = None
        instance.status = '0'
        instance.save()

        for item in itens_compra:
            item.pk = None
            item.id = None
            item.save()
            instance.itens_compra.add(item)

        for pagamento in pagamentos:
            pagamento.pk = None
            pagamento.id = None
            pagamento.save()
            instance.parcela_pagamento.add(pagamento)

        return redirect(reverse_lazy(redirect_url, kwargs={'pk': instance.id})) 
開發者ID:thiagopena,項目名稱:djangoSIGE,代碼行數:24,代碼來源:compras.py

示例3: get

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def get(self, request):
        area_slug = request.GET.get('area_slug')
        if area_slug:
            area = get_object_or_404(Area, slug=area_slug)
            area.set_for_request(request)
        else:
            Area.delete_for_request(request)

        next_url = self.request.GET.get('next') or reverse_lazy('django_classified:index')

        return redirect(next_url) 
開發者ID:slyapustin,項目名稱:django-classified,代碼行數:13,代碼來源:views.py

示例4: test_order_index_view

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_order_index_view(self):
        """
        Test the index view
        """
        name = self.model_admin.url_helper.get_action_url_name('index')
        response = self.client.get(reverse_lazy(name))
        self.assertEqual(response.status_code, 200) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:9,代碼來源:tests.py

示例5: test_order_detail_view

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_order_detail_view(self):
        order = OrderFactory()
        name = self.model_admin.url_helper.get_action_url_name('detail')
        response = self.client.get(reverse_lazy(name, kwargs={'instance_pk': order.pk}))
        self.assertEqual(response.status_code, 200) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:7,代碼來源:tests.py

示例6: get_test

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def get_test(self, urlname, urlkwargs=None, params=None, success_expected=True, **kwargs):
        """ Submit a GET request and assert the response status code is 200

        Arguments:
            urlname (str): The url name to pass to the 'reverse_lazy' function
            urlkwargs (dict): The `kwargs` parameter to pass to the `reverse_lazy` function
        """
        params = params or {}
        response = self.client.get(reverse_lazy(urlname, kwargs=urlkwargs), params, **kwargs)
        if success_expected:
            self.assertTrue(status.is_success(response.status_code), response.content)
        return response 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:14,代碼來源:utils.py

示例7: post_test

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def post_test(self, data, urlname, urlkwargs=None, success_expected=True, **kwargs):
        """ Submit a POST request and assert the response status code is 201

        Arguments:
            data (dict): The data to pass to the post request
            urlname (str): The url name to pass to the 'reverse_lazy' function
            urlkwargs (dict): The `kwargs` parameter to pass to the `reverse_lazy` function
        """
        response = self.client.post(reverse_lazy(urlname, kwargs=urlkwargs), data, **kwargs)
        if success_expected:
            self.assertTrue(status.is_success(response.status_code), response.content)
        return response 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:14,代碼來源:utils.py

示例8: patch_test

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def patch_test(self, data, urlname, urlkwargs=None, success_expected=True, **kwargs):
        """ Submit a PATCH request and assert the response status code is 200
        """
        response = self.client.patch(reverse_lazy(urlname, kwargs=urlkwargs), data, **kwargs)
        if success_expected:
            self.assertTrue(status.is_success(response.status_code), response.content)
        return response 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:9,代碼來源:utils.py

示例9: del_test

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def del_test(self, urlname, urlkwargs=None, success_expected=True, **kwargs):
        response = self.client.delete(reverse_lazy(urlname, kwargs=urlkwargs), **kwargs)
        if success_expected:
            self.assertTrue(status.is_success(response.status_code), response.content)
        return response 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:7,代碼來源:utils.py

示例10: test_get_checkout

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_get_checkout(self):
        """
        Test the checkout GET view
        """
        request = RequestFactory().get(reverse_lazy('longclaw_checkout_view'))
        response = CheckoutView.as_view()(request)
        self.assertEqual(response.status_code, 200) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:9,代碼來源:tests.py

示例11: test_post_checkout_billing

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_post_checkout_billing(self):
        """
        Test using an alternate shipping
        address in the checkout view
        """
        country = CountryFactory()
        request = RequestFactory().post(
            reverse_lazy('longclaw_checkout_view'),
            {
                'shipping-name': 'bob',
                'shipping-line_1': 'blah blah',
                'shipping-postcode': 'ytxx 23x',
                'shipping-city': 'London',
                'shipping-country': country.pk,
                'billing-name': 'john',
                'billing-line_1': 'somewhere',
                'billing-postcode': 'lmewrewr',
                'billing-city': 'London',
                'billing-country': country.pk,
                'email': 'test@test.com',
                'different_billing_address': True
            }
        )
        request.session = {}
        bid = basket_id(request)
        BasketItemFactory(basket_id=bid)
        response = CheckoutView.as_view()(request)
        self.assertEqual(response.status_code, 302) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:30,代碼來源:tests.py

示例12: test_post_checkout_invalid

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_post_checkout_invalid(self):
        """
        Test posting an invalid form.
        This should return a 200 response - rerendering
        the form page with the errors
        """
        request = RequestFactory().post(
            reverse_lazy('longclaw_checkout_view')
        )
        request.session = {}
        bid = basket_id(request)
        BasketItemFactory(basket_id=bid)
        response = CheckoutView.as_view()(request)
        self.assertEqual(response.status_code, 200) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:16,代碼來源:tests.py

示例13: test_missing_data

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def test_missing_data(self):
        """
        Test we get a message and 400 status if we dont send data
        """
        response = self.client.post(reverse_lazy('longclaw_basket_list'))
        self.assertEqual(response.status_code, 400) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:8,代碼來源:tests.py

示例14: post

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def post(self, request, *args, **kwargs):
        action = request.POST.get('action')
        mode = request.POST.get('mode')
        index = request.POST.getlist('index')
        objects = self.get_queryset().filter(pk__in=index)
        if mode == 'all':
            objects = self.get_queryset()
        redirect_to = reverse_lazy('idcops:list', args=[self.model_name])
        if action == 'config':
            postdata = request.POST.copy()
            self.user_config(postdata)
            return HttpResponseRedirect(redirect_to)
        if not objects.exists() and action != 'config':
            messages.warning(request, "您必須選中一些條目")
        else:
            try:
                current_action = import_string(
                    'idcops.actions.{}'.format(action))
                description = current_action.description
                metric = getattr(self.opts, 'metric', "條")
                mesg = format_html(
                    '您一共 <b>{0}</b> 了 <b>{1}</b> {2} <b>{3}</b>'.format(
                        description, objects.count(), metric, self.opts.verbose_name)
                )
                result = current_action(request, objects)
                # error has message.
                if isinstance(result, six.string_types):
                # if isinstance(result, (unicode, str)):
                    messages.warning(request, result)
                    redirect_to = redirect_to + self.get_query_string()
                    return HttpResponseRedirect(redirect_to)
                elif result:
                    return result
                else:
                    messages.success(request, mesg)
                return HttpResponseRedirect(redirect_to)
            except Exception as e:
                messages.warning(request, 'unknown your action: {}'.format(e))
        return HttpResponseRedirect(redirect_to) 
開發者ID:Wenvki,項目名稱:django-idcops,代碼行數:41,代碼來源:list.py

示例15: welcome

# 需要導入模塊: from django import urls [as 別名]
# 或者: from django.urls import reverse_lazy [as 別名]
def welcome(request):
    idc = Idc.objects.filter(actived=True)
    index_url = reverse_lazy('idcops:index')
    if idc.exists() and not settings.DEBUG:
        messages.warning(
            request, "Initialized, 已經初始化,不需要重新初始化。"
        )
        return HttpResponseRedirect(index_url)
    if request.method == 'POST':
        form = InitIdcForm(request.POST)
        if form.is_valid():
            form.instance.creator = request.user
            form.save()
            request.user.onidc = form.instance
            request.user.save()
            try:
                from django.core.management import call_command
                call_command('loaddata', 'initial_options.json')
            except:
                messages.error(
                    request, "loaddata initial_options.json 執行失敗..."
                )
            messages.success(
                request, "初始化完成,請開始使用吧..."
            )
        return HttpResponseRedirect(index_url)
    else:
        form = InitIdcForm()
    return render(request, 'welcome.html', {'form': form}) 
開發者ID:Wenvki,項目名稱:django-idcops,代碼行數:31,代碼來源:views.py


注:本文中的django.urls.reverse_lazy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。