コード例 #1
0
def add_coupon(request):
    now = timezone.now()
    form = AddCouponForm(request.POST)
    if form.is_valid():
        code = form.cleaned_data['code']

        try:
            coupon = Coupon.objects.get(code__iexact=code,
                                        use_from__lte=now,
                                        use_to__gte=now,
                                        active=True)
            request.session['coupon_id'] = coupon.id
        except Coupon.DoesNotExist:
            request.session['coupon_id'] = None
    return redirect('cart:detail')
コード例 #2
0
def detail(request):
    cart = Cart(request)
    add_coupon = AddCouponForm()
    for product in cart:
        product['quantity_form'] = AddProductForm(initial={'quantity':product['quantity'], 'is_update':True})

    return render(request, 'cart/detail.html', {'cart':cart, 'add_coupon':add_coupon})
コード例 #3
0
ファイル: views.py プロジェクト: devtenny/shopping-mall
def detail(request):  # 장바구니 페이지 뷰
    cart = Cart(request)
    add_coupon = AddCouponForm()  # !!! AddCouponForm
    for product in cart:  # 장바구니에 담긴 상품마다 (수량 수정 가능하도록) AddProductForm 생성
        product['quantity_form'] = AddProductForm(
            initial={'quantity': product['quantity'], 'is_update': True}
        )
    return render(request, 'cart/detail.html', {'cart': cart, 'add_coupon': add_coupon}) # !!! AddCouponForm
コード例 #4
0
def detail(request):
    cart = Cart(request)
    add_coupon = AddCouponForm()
    #카트 객체로부터 노출 시킬 제품을 가져옴. 제품 수량을 수정하기 위해 AddProductForm을 제품마다 하나씩 추가
    for product in cart:
        product['quantity_form'] = AddProductForm(initial = {'quantity':product['quantity'], 'is_update':True})

        return render(request, 'cart/detail.html', {'cart': cart, 'add_coupon': add_coupon}) #템플릿 변수로 카트와 쿠폰 전달
コード例 #5
0
 def post(self, request):
     form = AddCouponForm(request.POST)
     now = timezone.now()
     user = request.user
     cart = Cart.objects.get(user=user)
     if form.is_valid():
         code = form.cleaned_data['code']
         try:
             coupon = Coupon.objects.get(code=code,
                                         valid_from__lte=now,
                                         valid_to__gte=now,
                                         active=True)
             cart.coupon = coupon
         except Coupon.DoesNotExist:
             cart.coupon = None
             messages.error(
                 request,
                 "Podany kupon rabatowy jest nieprawidłowy albo nie jest obecnie aktywny"
             )
         cart.save()
     return redirect('cart_detail')
コード例 #6
0
ファイル: views.py プロジェクト: seungjohan/webeingfruits
def product_in_restaurant(request, restaurant_slug=None):
    current_restaurant = None
    restaurants = Restaurant.objects.all()
    categories = Category.objects.all()
    products = Product.objects.filter(available_display=True)
    cart = Cart(request)
    add_coupon = AddCouponForm()
    add_to_cart = AddProductForm(initial={'quantity': 1})

    for product in cart:
        product['quantity_form'] = AddProductForm(initial={'quantity': product['quantity'], 'is_update': True})

    if restaurant_slug:
        current_restaurant = get_object_or_404(Restaurant, slug=restaurant_slug)
        products = products.filter(restaurant=current_restaurant).order_by('-id')[:3]
        for product_price in products:
            product_price.discount = 100 - (product_price.price / product_price.origin_price) * 100
            product_price.save()

    if request.method == 'POST':
        user = request.user
        post = Comment()
        post.restaurant = current_restaurant
        post.user_id = user.id
        post.owner = user.email
        post.body = request.POST['body']
        post.pub_date = timezone.datetime.now()
        post.save()

    user = request.user
    err = 1
    posts = Comment.objects.filter(restaurant=current_restaurant).order_by('-id')
    post_paginator = Paginator(posts, 3)
    page = request.GET.get('page')
    page_posts = post_paginator.get_page(page)

    if user.is_authenticated == True:
        err = 0

    return render(
        request, 'shop/product_list.html',
        {'current_restaurant': current_restaurant,
         'categories': categories,
         'restaurants': restaurants,
         'products': products,
         'cart': cart,
         'add_coupon': add_coupon,
         'add_to_cart': add_to_cart,
         'page_posts': page_posts,
         'err': err
         }
    )
コード例 #7
0
def detail(request):
    cart = Cart(request)
    add_coupon = AddCouponForm()
    for product in cart:
        product["quantity_form"] = AddProductForm(
            initial={
                "quantity": product["quantity"],
                "is_update": True
            })
    return render(request, "cart/detail.html", {
        "cart": cart,
        "add_coupon": add_coupon
    })
コード例 #8
0
ファイル: views.py プロジェクト: estry/onlineshop
def detail(request):
    cart = Cart(request)
    add_coupon = AddCouponForm()
    # 제품 수량 수정을 위해서 폼을 제품마다 하나씩 추가, 수량은 수정하는 대로 반영해야 하기 때문에 is_update를 True로 설정
    for product in cart:
        product['quantity_form'] = AddProductForm(
            initial={
                'quantity': product['quantity'],
                'is_update': True
            })
    return render(request, 'cart/detail.html', {
        'cart': cart,
        'add_coupon': add_coupon
    })
コード例 #9
0
ファイル: views.py プロジェクト: Sungchul-P/django_onlineshop
def detail(request):
    cart = Cart(request)
    add_coupon = AddCouponForm()  # 장바구니 페이지에 쿠폰 폼을 출력합니다.

    for product in cart:
        # 제품 수량 수정을 위해서 제품마다 폼을 하나씩 추가해 줍니다.
        # 수량은 수정하는 대로 반영해야 하기 때문에 is_update 값을 True로 설정했습니다.
        product['quantity_form'] = AddProductForm(
            initial={
                'quantity': product['quantity'],
                'is_update': True
            })

    return render(request, 'cart/detail.html', {
        'cart': cart,
        'add_coupon': add_coupon
    })
コード例 #10
0
 def get(self, request):
     user = request.user
     cart, created = Cart.objects.get_or_create(user=user)
     items = cart.cartproduct_set.all()
     form_coupon = AddCouponForm()
     cart.total_price = 0
     for item in items:
         item.update_quantity_form = CartAddProductForm(
             initial={
                 'quantity': item.quantity,
                 'override_quantity': True
             })
         item.total_price = item.quantity * item.product.price
         cart.total_price += item.total_price
     return render(request, 'cart/cart_detail.html', {
         'items': items,
         'cart': cart,
         'form_coupon': form_coupon
     })