示例#1
0
def product_detail(request, id, slug):
    p = get_object_or_404(Product, id=id, slug=slug)
    c = p.categories.filter(is_active=True)
    cart_product_form = CartAddProductForm()
    meta_description = p.meta_description
    stats.log_product_view(request, p)
    return render(request, "product/detail.html", {'c': c, 'p': p, 'cart_product_form': cart_product_form, })
示例#2
0
def show_product(request, product_slug, template_name="catalog/product.html"):
    p = get_object_or_404(Product, slug=product_slug)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    stats.log_product_view(request, p) # add to product view
    product_reviews = ProductReview.approved.filter(product=p).order_by('-date') 
    review_form = ProductReviewForm()  
    if request.method == 'POST':
        # add to cart…create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        #check if posted data is valid
        if form.is_valid():
        #add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(url)  
    else:
        # it’s a GET, create the unbound form. Note request as a kwarg
        form = ProductAddToCartForm(request=request, label_suffix=':')
        # assign the hidden input the product slug
        form.fields['product_slug'].widget.attrs['value'] = product_slug
        # set the test cookie on our first GET request
        request.session.set_test_cookie()
        return render_to_response("catalog/product.html", locals(), context_instance=RequestContext(request)) 
        
    return render_to_response(template_name, locals(),context_instance=RequestContext(request))  
示例#3
0
文件: views.py 项目: mathuin/pyment
def show_product(request, product_slug, template_name="meadery/product.html"):
    p = get_object_or_404(Product, slug=product_slug)
    cname = [name for (value, name) in Product.MEAD_VIEWS if value == p.category][0]
    page_title = p.name
    # need to evaluate the HTTP method
    if request.method == 'POST':
        # add to cart...create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = reverse('cart:show_cart')
            return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound form. Note request as a kwarg
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    # log product view
    stats.log_product_view(request, p)
    # don't forget product reviews
    product_reviews = ProductReview.approved.filter(product=p).order_by('-date')
    review_form = ProductReviewForm()

    return render(request, 'meadery/product.html', locals())
示例#4
0
def show_product(request, product_slug, template_name="catalog/product.html"):
    product = get_object_or_404(Product, slug=product_slug)
    categories = product.categories.all()
    page_title = product.name
    stats.log_product_view(request, product)

    meta_keywords = product.meta_keywords
    meta_description = product.meta_description
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
   
        if form.is_valid():
            cart.add_to_cart(request)
        # if test cookie worked, get rid of it
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
        url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(url)
    else:
        form = ProductAddToCartForm(request=request, label_suffix=':')
        
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    request.session.set_test_cookie()
    product_reviews = ProductReview.approved.filter(product=product).order_by('-date')
    review_form = ProductReviewForm()
    return render_to_response("catalog/product.html", locals(),
        context_instance=RequestContext(request))
def show_product(request, product_slug, template_name="catalog/product.html"):
    p = get_object_or_404(Product, slug=product_slug)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description

    if request.method == 'POST':
        # add to cart
        post_data = request.POST.copy()
        form = ProductAddToCartForm(request, post_data)
        if form.is_valid():
            # add to cart and redirect to cart page
            carts.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return redirect('cart:show_cart')
    else:
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    stats.log_product_view(request, p)
    # product review
    product_reviews = ProductReview.approved.filter(
        product=p).order_by('-date')
    review_form = ProductReviewForm()

    return render(request, template_name, context=locals())
示例#6
0
def product(request, category_slug, product_slug, template_name="spiritbuzz/product.html"):
    # Request our context from the request passed to us.

    p = get_object_or_404(Product, slug = product_slug)
    #categories = p.categories.all()
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    stats.log_product_view(request, p)
    product_reviews = ProductReview.approved.filter(product = p).order_by('-date')
    review_form = ProductReviewForm()
    #form = ProductAddToCartForm()
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        if form.is_valid():

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            cart.add_to_cart(request)
            url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(url)


    else:
        form = ProductAddToCartForm(request = request, label_suffix = ':')
    form.fields['product_slug'].widget.attrs['value'] = product_slug


    request.session.set_test_cookie()


    return render_to_response(template_name, locals(), context_instance = RequestContext(request))
示例#7
0
文件: views.py 项目: mathuin/pyment
def show_product(request, product_slug, template_name="meadery/product.html"):
    p = get_object_or_404(Product, slug=product_slug)
    cname = [
        name for (value, name) in Product.MEAD_VIEWS if value == p.category
    ][0]
    page_title = p.name
    # need to evaluate the HTTP method
    if request.method == "POST":
        # add to cart...create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = reverse("cart:show_cart")
            return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound form. Note request as a kwarg
        form = ProductAddToCartForm(request=request, label_suffix=":")
    # assign the hidden input the product slug
    form.fields["product_slug"].widget.attrs["value"] = product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    # log product view
    stats.log_product_view(request, p)
    # don't forget product reviews
    product_reviews = ProductReview.approved.filter(
        product=p).order_by("-date")
    review_form = ProductReviewForm()

    return render(request, "meadery/product.html", locals())
示例#8
0
def show_product(request, product_slug, template_name="catalog/product.html"):
    product = get_object_or_404(Product, slug=product_slug)
    categories = product.categories.all()
    page_title = product.name
    stats.log_product_view(request, product)

    meta_keywords = product.meta_keywords
    meta_description = product.meta_description
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)

        if form.is_valid():
            cart.add_to_cart(request)
        # if test cookie worked, get rid of it
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
        url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(url)
    else:
        form = ProductAddToCartForm(request=request, label_suffix=':')

    form.fields['product_slug'].widget.attrs['value'] = product_slug
    request.session.set_test_cookie()
    product_reviews = ProductReview.approved.filter(
        product=product).order_by('-date')
    review_form = ProductReviewForm()
    return render_to_response("catalog/product.html",
                              locals(),
                              context_instance=RequestContext(request))
示例#9
0
def show_product(request, product_slug, template_name='catalog/product.html'):
    p = get_object_or_404(Product, slug=product_slug)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    # need to evaluate the HTTP method
    if request.method == 'POST':
        # add to cart...create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            # add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound form. Note request as a kwarg
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    stats.log_product_view(request, p)
    product_reviews = ProductReview.approved.filter(
        product=p).order_by('-date')
    review_form = ProductReviewForm()
    return render(request, template_name, locals())
示例#10
0
文件: views.py 项目: c-j-j/ecomstore
def show_product(request, product_slug, template_name="catalog/product.html"):
    product = get_object_or_404(Product, slug=product_slug)

    from stats import stats
    stats.log_product_view(request,product)

    categories = product.categories.filter(is_active=True)
    page_title = product.name
    meta_keywords = product.meta_keywords
    meta_description = product.meta_description

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)

        if form.is_valid():
            cart.add_to_cart(request)
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(url)
    else:
        form = ProductAddToCartForm(request=request, label_suffix=':')

    form.fields['product_slug'].widget.attrs['value'] = product_slug
    request.session.set_test_cookie()

    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
示例#11
0
def show_product(request, product_slug):
    """
    new product view, with POST vs GET detection
    """
    p = get_object_or_404(Product, slug=product_slug)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    if request.method == 'POST':
        # add to cart... create the bound form
        post_data = request.POST.copy()
        product_add_to_cart_form = ProductAddToCartForm(request, post_data)
        # check if posted data is valid
        if product_add_to_cart_form.is_valid():
            # add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
                # url = urlresolvers.reverse('show_cart')
                # return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound form. Note request as a kwarg
        product_add_to_cart_form = ProductAddToCartForm(request=request,
                                                        label_suffix=':')
        # assign the hidden input the product slug
        product_add_to_cart_form.fields['product_slug'].widget.attrs[
            'value'] = product_slug
        # set the test cookie on our first GET request
        request.session.set_test_cookie()
    stats.log_product_view(request, p)

    customers_who_bought_this_p_also_bought = utils.products_bought_together(p)

    product_reviews = ProductReview.approved.filter(
        product=p).order_by('-date')
    review_form = ProductReviewForm()
    review_rating = ProductRatingForm()
    # rating promedio
    avg_rating = p.avg_rating()
    cant_rating = p.productrating_set.count()
    desired_by_user = False
    user_already_voted = 0
    if request.user.is_authenticated():
        # el usuario loguead ya voto por este prod?
        try:
            user_product_rating = ProductRating.objects.get(user=request.user,
                                                            product=p)
            user_already_voted = user_product_rating.rating
        except ProductRating.DoesNotExist:
            user_already_voted = 0
        # deseado por el usuario logueado?
        user_profile = profile.get_profile(request)
        if p in user_profile.wish_list.all():
            desired_by_user = True
    return render_to_response("catalog/product.html",
                              locals(),
                              context_instance=RequestContext(request))
示例#12
0
def show_product(request, product_slug):
    """ view for each product page """
    product_cache_key = request.path
    # try to get product from cache
    p = cache.get(product_cache_key)
    # if a cache miss, fall back on db query
    if not p:
        p = get_object_or_404(Product.active, slug=product_slug)
        # store item in cache for next time
        cache.set(product_cache_key, p, CACHE_TIMEOUT)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    # evaluate the HTTP method, change as needed
    if request.method == 'POST':
        # create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            # add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(reverse('show_cart'))
    else:
        # create the unbound form. Notice the request as a keyword argument
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set test cookie to make sure cookies are enabled
    request.session.set_test_cookie()
    # Logs a user who just viewed this product
    stats.log_product_view(request, p)
    # product review additions, CH 10
    product_reviews = ProductReview.approved.filter(
        product=p).order_by('-date')
    review_form = ProductReviewForm()
    context = {
        'categories': categories,
        'p': p,
        'page_title': page_title,
        'meta_keywords': meta_keywords,
        'meta_description': meta_description,
        'form': form,
        'product_reviews': product_reviews,
        'review_form': review_form
    }
    template = 'catalog/product.html'
    return render(request, template, context)
示例#13
0
def show_product(request, product_slug, template_name="catalog/product.html"):
    """ view for each product page """
    product_cache_key = request.path
    # try to get product from cache
    p = cache.get(product_cache_key)
    # if a cache miss, fall back on db query
    if not p:
        p = get_object_or_404(Product, slug=product_slug)
        cache.set(product_cache_key, p, CACHE_TIMEOUT)

    categories = p.categories.all()
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description

    if request.method == 'POST':

        # create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid

        if form.is_valid():
            # add to cart and redirect to cart page

            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return redirect('show-cart')
    else:
        # create the unbound form. Notice the request as a keyword argument
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set test cookie to make sure cookies are enabled
    request.session.set_test_cookie()

    stats.log_product_view(request, p)
    # product review additions, CH 10
    product_reviews = ProductReview.approved.filter(
        product=p).order_by('-date')
    review_form = ProductReviewForm()
    return render(request, template_name, locals())
示例#14
0
def show_product(request, product_slug, template_name = "catalog/product.html"):
    product_cache_key = request.path
    # get product from cache
    p = cache.get(product_cache_key)
    # if a cache miss, fall back on database query
    if not p:
        p = get_object_or_404(Product, slug = product_slug)
        # store in cache for next time
        cache.set(product_cache_key, p, CACHE_TIMEOUT)

    #p = get_object_or_404(Product, slug = product_slug)
    from stats import stats
    stats.log_product_view(request, p) # add to product view
    categories = p.categories.all()
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    # need to evaluate the HTTP method
    if request.method == 'POST':
        # add to cart ... create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            # add to cart and redirect to cart page
            shoppingcart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = urlresolvers.reverse('show_cart')
            return HttpResponseRedirect(url)
    else:
        # it's a GET, create the unbound form. Note request as a kwarg
        form = ProductAddToCartForm(request = request, label_suffix = ':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()

    product_reviews = ProductReview.approved.filter(product = p).order_by('-date')
    review_form = ProductReviewForm()
    return render_to_response("catalog/product.html", locals(), context_instance = RequestContext(request))
示例#15
0
def show_product(request, product_slug):
    p = get_object_or_404(Product, slug=product_slug)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    
    # need to evaluate the HTTP method
    if request.method == 'POST':
        # add to cart...create the bound form
        postdata = request.POST.copy()
        form =ProductAddToCartForm(request.POST,instance=ProductAddToCartForm.cart_item)
        #check if posted data is valid
        if form.is_valid():
            cart_item =form.save(commit=False)
            #cart_item.cart_id = get_cart_id_function()
            cart_item.product = Product.objects.get(slug=product_slug)
            cart_item.save()
            message="added to cart"
            #add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = reverse('show_cart')
            return HttpResponseRedirect(url)
    else:
        form=FProductAddToCartForm()
    # assign the hidden input the product slug as the value
    #
    form.fields['product_slug'].widget.attrs['value']=product_slug
    # set the test cookie on our first GET request
    request.session.set_test_cookie()
    
    from stats import stats
    stats.log_product_view(request, p) # add to product view
    product_reviews = ProductReview.approved.filter(product=p).order_by('-date')
    review_form = ProductReviewForm()
    return render_to_response("catalog/product.html", locals(),context_instance=RequestContext(request))
示例#16
0
def show_product(request, product_slug, template_name="catalog/product.html"):
    p = get_object_or_404(Product, slug=product_slug)
    stats.log_product_view(request, p)
    product_reviews = ProductReview.approved.filter(product=p).order_by('-date')
    page = request.GET.get('page', 1)
    js = request.GET.get('js', '')
    paginator = Paginator(product_reviews, 1)
    reviews_count = product_reviews.count()
    try:
        product_reviews1 = paginator.page(page)
    except PageNotAnInteger:
        product_reviews1 = paginator.page(1)
    except EmptyPage:
        product_reviews1 = paginator.page(paginator.num_pages)
    if js == 'true':
        template = "catalog/product_review_paginated.html"
        html = render_to_string(template, {'product_reviews1': product_reviews1})
        response = simplejson.dumps({'success': 'True', 'html': html})
        return HttpResponse(response, content_type='application/javascript; charset=utf-8')

    if not product_reviews:
        review_form = ProductReviewForm()
    for r in product_reviews:
        print(request.user.username)
        print(r.user.username)
        if r.user.username == request.user.username:
            review_form = 'exists'
            print(review_form)
            break
        else:
            review_form = ProductReviewForm()
    print(review_form)
    categories = p.categories.filter(is_active=True)
    page_title = p.name
    meta_keywords = p.meta_keywords
    meta_description = p.meta_description
    # add to product view
    context = {
        'categories': categories,
        'page_title': page_title,
        'meta_keywords': meta_keywords,
        'meta_description': meta_description,
    }
    # need to evaluate the HTTP method
    if request.method == 'POST':
        if pending_checker(request) == 0:
            url = reverse('show_checkout', args=['PendingLipa'])
            return HttpResponseRedirect(url)
        # add to cart....create the bound form
        postdata = request.POST.copy()
        form = ProductAddToCartForm(request, postdata)
        # check if posted data is valid
        if form.is_valid():
            # add to cart and redirect to cart page
            cart.add_to_cart(request)
            # if test cookie worked, get rid of it
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            url = reverse('show_cart')
            return HttpResponseRedirect(url)
    else:
        # it's a get, create the unbound form. Note a request as a kwarg
        form = ProductAddToCartForm(request=request, label_suffix=':')
    # assign the hidden input the product slug
    form.fields['product_slug'].widget.attrs['value'] = product_slug
    # set the test cookie on our first get request
    request.session.set_test_cookie()
    return render(request, template_name, locals(), RequestContext(request))