コード例 #1
0
def add_to_order(request):
    cart = Cart(request)
    #user = models.UserManage.objects.get(name=request.user.username)
    userid = request.session['uuserid']
    user = models.UserManage.objects.get(id=userid)
    order = models.Order(user=user, createdat=datetime.datetime.now())
    order.save()
    email_messages = "您订购的内容如下: \n"
    for item in cart:
        models.OrderItem.objects.create(order=order,
                                        product=item.product,
                                        price=item.product.price,
                                        quantity=item.quantity)
        #total_price = item.total_price())

        email_messages = email_messages + "\n" + \
                                "{}, {}, {}".format(item.product, \
                                             item.product.price, item.quantity)
    email_messages = email_messages + \
                    "\n 以上共计{}元\nhttp://mshop.raffaele.com 感谢您的订购!".\
                    format(cart.summary())
    messages.add_message(request, messages.INFO, "订单已保存,我们会尽快处理。")
    emailboss = EmailMessage('有新的订单', email_messages, '*****@*****.**',
                             [user.email])
    emailboss.send()
    cart.clear()
    return JsonResponse({'status': 10091, 'message': 'Add to the order!!!'})
コード例 #2
0
def order(request):
    all_categories = models.Category.objects.all()
    cart = Cart(request)

    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        new_oreder = models.Order(user=user)
        order_form = forms.OrderForm(request.POST, instance=new_oreder)

        if order_form.is_valid():
            order = order_form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'order has been built')
            for item in cart:
                models.OrderItem.objects.create(order=order,
                                                product=item.product,
                                                price=item.product.price,
                                                quantity=item.quantity)
            cart.clear()
            return redirect(my_orders)

    else:
        order_form = forms.OrderForm()

    return render(request, 'order.html', locals())
コード例 #3
0
def order(request):
    all_categories = models.Category.objects.all()
    cart = Cart(request)
    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        new_order = models.Order(user=user)

        form = forms.OrderForm(request.POST, instance=new_order)
        if form.is_valid():
            order = form.save()
            email_messages = '您的购物车内容如下:\n'
            for item in cart:
                models.OrderItem.objects.create(order=order,
                                                product=item.product,
                                                price=item.product.price,
                                                quantity=item.quantity)
                email_messages = email_messages + "\n" + "{}, {}, {}".format(item.product,
                                                                             item.product.price, item.quantity)

            email_messages = email_messages + "\n以上共计{}元\nhttp://mshop.ichaungshun.com感谢您的订购!".format(cart.summary())

        cart.clear()
        messages.add_message(request, messages.INFO, "订单已保存,我们会尽快处理。")
        return redirect('/myorder/')
    else:
        form = forms.OrderForm()

    template = get_template('order.html')
    request_context = RequestContext(request)
    request_context.push(locals())
    html = template.render(request_context)

    return HttpResponse(html)
コード例 #4
0
ファイル: views.py プロジェクト: YotsuZZ/testforcsiewwwb
def order(request):
	all_categories = models.Category.objects.all()
	cart = Cart(requst)
	if request.method == 'POST':
		user = User.objects.get(username=request.user.username)
		new_order = models.Order(user=user)
		
		
		form = forms.OrderForm(request.POST, instance=new_order)
		if form.is_valid():
			order = form.save()
			email_messages = "您的購買物如下:\n"
			for item in cart:
				models.OrderItem.objects.create(order=order,
										product=item.product,
										price = item.product.price,
										quantity=item.quantity)
				email_messages = email_messages + "\n"+\"{},{},{}".format(itme.product, \item.product.price, item.quantity)
			email_messages = email_messages +\"\n以上總計為{}元\.感謝你的訂購,我們會盡速處理。")
			send_mail("感謝你的訂購", email_messages',http://locahost:8000/ 感謝您!!! [request.user.email],)
			send_mail("有人訂購產品", email_messages',['*****@*****.**'],)
			return redirect('/myorders/')
			
		else:
			form =forms.OrderForm()
			
	template = get_template('order.html')
	request_context = RequestContext(request)
	request_context.push(locals())
	html = template.render(request_context)
	return HttpResponse(html)
コード例 #5
0
def order(request):
    allcategories = models.Category.objects.all()
    cart = Cart(request)
    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        new_order = models.Order(user=user)

        form = forms.OrderForm(request.POST, instance=new_order)
        if form.is_valid():
            order = form.save()
            email_messages = "您订购的内容如下: \n"
            for item in cart:
                models.OrderItem.objects.create(order=order,
                                                product=item.product,
                                                price=item.product.price,
                                                quantity=item.quantity)
                email_messages = email_messages + "\n" + \
                                "{}, {}, {}".format(item.product, \
                                             item.product.price, item.quantity)
            email_messages = email_messages + \
                            "\n 以上共计{}元\nhttp://mshop.raffaele.com 感谢您的订购!".\
                            format(cart.summary())
            messages.add_message(request, messages.INFO, "订单已保存,我们会尽快处理。")
            #send_mail("感谢您的订购",
            #          email_messages,
            #          '迷销电商',
            #          [request.user.email],)
            #send_mail("有人订购产品",
            #          email_messages,
            #          '迷你电商',
            #          ['*****@*****.**'],)
            emailboss = EmailMessage('有新的订单', email_messages,
                                     '*****@*****.**', [request.user.email])
            emailboss.send()
            cart.clear()
            return redirect('/myorders/')
    else:
        form = forms.OrderForm()

    template = get_template('order.html')
    request_context = RequestContext(request)
    request_context.push(locals())
    html = template.render(request_context)
    return HttpResponse(html)
コード例 #6
0
ファイル: views.py プロジェクト: FLeader/MrFish
def order(request):
    all_categories = models.Category.objects.all()
    cart = Cart(request)
    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        new_order = models.Order(user=user)

        form = forms.OrderForm(request.POST, instance=new_order)
        if form.is_valid():
            order = form.save()
            email_messages = "您的購物內容如下:\n"
            for item in cart:
                models.OrderItem.objects.create(order=order,
                                                product=item.product,
                                                price=item.product.price,
                                                quantity=item.quantity)
                email_messages = email_messages + "\n" + \
                                "{}, {}, {}".format(item.product, item.product.price, item.quantity)
            email_messages = email_messages + \
                    "\n以上共計{}元\nhttp://mshop.min-haung.com感謝您的訂購!".format(cart.summary())
            messages.add_message(request, messages.INFO, "訂單已儲存,我們會儘快處理。")
            send_mail(
                "感謝您的訂購",
                email_messages,
                '迷你小電商<*****@*****.**>',
                [request.user.email],
            )
            send_mail(
                "有人訂購產品囉",
                email_messages,
                '迷你小電商<*****@*****.**>',
                ['*****@*****.**'],
            )
            cart.clear()
            return redirect('/myorders/')
    else:
        form = forms.OrderForm()

    template = get_template('order.html')
    request_context = RequestContext(request)
    request_context.push(locals())
    html = template.render(request_context)
    return HttpResponse(html)
コード例 #7
0
ファイル: views.py プロジェクト: tuchang/myDjango
def order(request):
    all_categories = models.Category.objects.all()
    cart = Cart(request)
    if request.method == 'POST':
        user = User.objects.get(username=request.user.username)
        new_order = models.Order(user=user)

        form = forms.OrderForm(request.POST, instance=new_order)
        if form.is_valid():
            order = form.save()
            email_messages = "您的购物內容如下:\n"
            for item in cart:
                models.OrderItem.objects.create(order=order,
                                                product=item.product,
                                                price=item.product.price,
                                                quantity=item.quantity)
                email_messages = email_messages + "\n" + \
                                "{}, {}, {}".format(item.product, item.product.price, item.quantity)
            email_messages = email_messages + \
                    "\n以上共计{}元\nhttp://127.0.0.1:8000/感谢您的订购!".format(cart.summary())
            messages.add_message(request, messages.INFO, "订单已储存,我們会尽快处理。")
            send_mail(
                "感谢您的订购",
                email_messages,
                '迷你小电商<*****@*****.**>',
                [request.user.email],
            )
            send_mail(
                "有人订购商品呦",
                email_messages,
                '迷你小电商<*****@*****.**>',
                ['*****@*****.**'],
            )
            cart.clear()
            return redirect('/myorders/')
    else:
        form = forms.OrderForm()

    template = get_template('order.html')
    html = template.render(context=locals(), request=request)
    return HttpResponse(html)