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


Python Order.from_request方法代碼示例

本文整理匯總了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))
開發者ID:matsinvasion,項目名稱:motome,代碼行數:34,代碼來源:views.py

示例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))
開發者ID:matsinvasion,項目名稱:motome,代碼行數:34,代碼來源:views.py

示例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
開發者ID:matsinvasion,項目名稱:motome,代碼行數:11,代碼來源:views.py

示例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
開發者ID:matsinvasion,項目名稱:motome,代碼行數:14,代碼來源:views.py

示例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))
開發者ID:matsinvasion,項目名稱:motome,代碼行數:22,代碼來源:views.py


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