本文整理汇总了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)
示例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}))
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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})