本文整理汇总了Python中orders.models.Order.from_request方法的典型用法代码示例。如果您正苦于以下问题:Python Order.from_request方法的具体用法?Python Order.from_request怎么用?Python Order.from_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orders.models.Order
的用法示例。
在下文中一共展示了Order.from_request方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cart
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import from_request [as 别名]
def cart(request):
order = Order.from_request(request)
country = Country.objects.get(country_code='RW')
if request.method == 'POST':
if 'add_product' in request.REQUEST:
product = Product.objects.get(id=request.REQUEST['add_product'], is_active=True)
order.add_single(product)
if set(('update', 'checkout', 'shop')).intersection(set(request.REQUEST.keys())):
for item in order.items.all():
if 'remove_%d' % item.id in request.REQUEST:
order.items.filter(pk=item.id).update(is_active=False)
for addon in item.product.addons.all():
exists_in_order = item.addons.filter(addon=addon)
form_name = 'addon_%d_%d' % (item.id, addon.id)
exists_in_form = form_name in request.REQUEST
if exists_in_order and not exists_in_form:
exists_in_order.update(is_active=False)
elif exists_in_form and not exists_in_order:
item.add_on(addon)
if 'checkout' in request.REQUEST:
return HttpResponseRedirect(reverse('public_checkout'))
elif 'shop' in request.REQUEST:
return HttpResponseRedirect("%s?password=iamhungry" % reverse('public_home'))
context = dict(cart=True, order=order, country=country, currency=country.currency)
return render_to_response('public/cart.html', context, context_instance=RequestContext(request))
示例2: login
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import from_request [as 别名]
def login(request):
user = request.session['customer']
if request.method == 'POST':
password_form = PasswordForm(request.POST, user=user)
customer_form = CustomerForm(request.POST)
if password_form.is_valid() and customer_form.is_valid():
customer = request.session['customer']
customer.first_name = customer_form.cleaned_data['first_name']
customer.last_name = customer_form.cleaned_data['last_name']
customer.email = customer_form.cleaned_data['email']
customer.save()
user = auth.authenticate(username=customer.username, password=password_form.cleaned_data['password'])
auth.login(request, user)
order = Order.from_request(request)
order.user = user
order.save()
if 'location' in request.session:
location = request.session['location']
return HttpResponseRedirect("%s?lat=%s&lng=%s" % (reverse('public.location_create'), location.lat, location.lng))
else:
return HttpResponseRedirect(reverse('public.location_create'))
else:
password_form = PasswordForm(user=user)
customer_form = CustomerForm(initial={'first_name':user.first_name, 'last_name':user.last_name, 'email': user.email})
context = dict(password_form=password_form, customer_form=customer_form, user=user)
return render_to_response('public/login.html', context, context_instance=RequestContext(request))
示例3: post_save
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import from_request [as 别名]
def post_save(self, obj):
obj = super(LocationCRUDL.Create, self).post_save(obj)
self.order = Order.from_request(self.request)
self.order.location = obj
self.order.stage = 'L'
self.order.save()
self.request.session['location'] = obj
return obj
示例4: get_context_data
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import from_request [as 别名]
def get_context_data(self, **kwargs):
context = super(LocationCRUDL.Create, self).get_context_data(**kwargs)
context['display_fields'] = ['hints', 'nickname']
context['order'] = Order.from_request(self.request)
# add our country and it's root locations
context['country'] = Country.objects.get(country_code='RW')
# set the country on our form's location picker
self.form.fields['coordinates'].set_country(context['country'])
return context
示例5: checkout
# 需要导入模块: from orders.models import Order [as 别名]
# 或者: from orders.models.Order import from_request [as 别名]
def checkout(request):
order = Order.from_request(request)
country = Country.objects.get(country_code='RW')
initial_data = dict()
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
phone_number = form.cleaned_data['phone_number']
phone_number = country.derive_international_number(phone_number)
customer = Customer.get_or_create_customer(phone_number)
customer.send_password()
request.session['customer'] = customer
return HttpResponseRedirect(reverse('public_login'))
else:
form=LoginForm(initial_data)
context = dict(order=order, country=country, currency=country.currency, form=form)
return render_to_response('public/checkout.html', context, context_instance=RequestContext(request))