Beispiel #1
0
def featuredxml(request):
    t = loader.get_template('featured.xml')

    # Lets select products based on the type of customer we're working with
    c = RequestContext(request,
                       common.commonDict({"openpath": ["home"]}, request))
    return HttpResponse(t.render(c), mimetype="application/xml")
Beispiel #2
0
def home(request):
    t = loader.get_template('index.html')
    coupon = request.session.get('coupon', '')
    coupons = Coupon.objects.all()
    if coupon:
        validate = [True if x.checkCode(coupon) else False for x in coupons]
        if validate.count(False) == len(coupons):
            request.session['coupon'] = ''
            order_id = request.session.get('order_id', None)
            if order_id:
                order = Order.objects.get(id=order_id)
                po = order.productorder_set.all()
                for x in po:
                    x.price = x.product.getTaxFreePrice(
                        x.size, request.user.is_active, '')
                    x.save()
        else:
            request.session['coupon'] = coupon
    #return HttpResponse(str(dir(getCategories()[0])))
    c = RequestContext(request,
                       common.commonDict({
                           "openpath": ["home"],
                       }, request))
    #return HttpResponse(common.commonDict({"openpath": ["home"],}, request)["products"])
    #raise Exception({'coupon':coupon,'coupon2':validate,'dict':common.commonDict({"openpath": ["home"], }, request)})
    return HttpResponse(t.render(c))
Beispiel #3
0
def stockists(request, region):
    t = loader.get_template('stockists.html')
    s = Stockist.objects.filter(region__iexact=region).order_by(
        "state", "suburb")
    openpath = ["stockists", region]
    c = RequestContext(
        request,
        common.commonDict({
            'stockists': s,
            'openpath': openpath,
        }, request))
    return HttpResponse(t.render(c))
Beispiel #4
0
def subscribe(request):
    data = {
        "openpath": ["home"],
    }
    if is_valid_email(request.POST.get("email")):
        try:
            o = User.objects.get(email=request.POST.get("email"))
            if Profile.objects.get(user=o.id).wholesale:

                s, created = Subscription.objects.get_or_create(
                    email=request.POST.get("email"),
                    defaults={
                        "is_wholesale": True,
                        "ip": request.META["REMOTE_ADDR"]
                    })
            else:
                s, created = Subscription.objects.get_or_create(
                    email=request.POST.get("email"),
                    defaults={
                        "is_wholesale": False,
                        "ip": request.META["REMOTE_ADDR"]
                    })
            t = loader.get_template('subscribe.html')
            if created:
                data["error"] = 0
                data["message"] = "Thanks for subscribing to our newsletter."
            else:
                data["error"] = 1
                data[
                    "message"] = "There was an error, perhaps you're already subscribed?"
        except:
            s, created = Subscription.objects.get_or_create(
                email=request.POST.get("email"),
                defaults={
                    "is_wholesale": False,
                    "ip": request.META["REMOTE_ADDR"]
                })
            t = loader.get_template('subscribe.html')
            if created:
                data["error"] = 0
                data["message"] = "Thanks for subscribing to our newsletter."
            else:
                data["error"] = 1
                data[
                    "message"] = "There was an error, perhaps you're already subscribed?"
    else:
        data["error"] = 1
        data["message"] = "Please use a valid email address"
    c = RequestContext(request, common.commonDict(data, request))
    return HttpResponse(str(data))
Beispiel #5
0
def catchall(request, path):
    try:
        document = MiscPage.objects.get(path=path,
                                        status__display_to_user=True)
        t = loader.get_template('catchall.html')
        c = RequestContext(
            request,
            common.commonDict({
                "openpath": ["home"],
                "document": document,
            }, request))
        return HttpResponse(t.render(c))
    except Exception, e:
        #TODO make 404
        return HttpResponse("Couldn't find the file you were looking for")
Beispiel #6
0
def product(request, code):
    t = loader.get_template('product.html')
    product = Product.objects.get(code=code)
    related = product.getRelatedProducts(request.user.is_active)

    if not request.user.is_active:
        quantities = range(product.minimum_quantity,
                           product.maximum_quantity + 1)
    else:
        quantities = range(product.minimum_quantity_wholesale,
                           product.maximum_quantity_wholesale + 1)
    c = RequestContext(
        request,
        common.commonDict(
            {
                'product': product,
                'quantities': quantities,
                'related': related,
            }, request))

    return HttpResponse(t.render(c))
Beispiel #7
0
def post(request, code):
    t = loader.get_template('blogpost.html')
    #return HttpResponse(str(dir(Product.objects.get(code=code))))
    blogpost = BlogPost.objects.get(slug=code)
    rp = request.POST.copy()
    messages = []
    if rp:
        form = CommentForm(rp)
    else:
        form = CommentForm()
    if form.is_valid(): # All validation rules pass
        c = Comment(post=blogpost, name=form.cleaned_data["name"], email=form.cleaned_data["email"], comment=form.cleaned_data["comment"], status=CommentStatus.objects.get(status="Published"))
        c.save()
        messages.append("Thanks for your comment")  
        return HttpResponseRedirect(blogpost.getURL())
    c = RequestContext(request,common.commonDict({
        'blogpost': blogpost,
        'form': form,
        'messages': messages,
        "openpath": ["blog"],
    }, request))
    return HttpResponse(t.render(c))
Beispiel #8
0
def home(request, offset=1):
    t = loader.get_template('blog_index.html')
    offset = int(offset)
    perpage = settings.BLOG_POSTS_PER_PAGE
    start = offset*perpage
    end = start+perpage
    
#    postcount = BlogPost.objects.select_related().filter(status__display_to_user=True, publishdate__lte=datetime.datetime.now()).order_by("-publishdate").count()
    
    blogposts = BlogPost.objects.select_related().filter(status__display_to_user=True, publishdate__lte=datetime.datetime.now()).order_by("-publishdate")
    
    p = Paginator(blogposts, perpage)
    
    page = p.page(offset)
    
    #return HttpResponse("")
    c = RequestContext(request,common.commonDict({
        'blogposts': page.object_list,
        "openpath": ["blog"],
        "page": page,
    }, request))
    return HttpResponse(t.render(c))
Beispiel #9
0
def success(request, orderid):
    msgg = ''
    if request.GET:

        order = Order.objects.filter(id=orderid)
        if order:
            order = order[0]
            profile = order.user.get_profile()
            shipping = profile.shipping_set.all()
            billing = profile.billing_set.all()
            token = request.GET.get('token')
            payerid = request.GET.get('PayerID')
            response = common.getResponse(order,
                                          action='do',
                                          token=token,
                                          payerid=payerid)
            msgg = response
            if response['ACK'] == 'Success':

                order.status = OrderStatus.objects.get(
                    status__iexact=settings.TXT_SHOP_ORDER_STATUS_ORDERED)
                order.save()
                payment = True
                t = loader.get_template('orderconfirmationemail.html')
                d = {
                    "profile": profile,
                    "shipping": shipping[0],
                    "billing": billing[0],
                    'payment': payment
                }
                c = RequestContext(request, common.commonDict(d, request))
                msg = t.render(c)
                email = EmailMultiAlternatives(
                    'EASTBOURNEART Order Received - Order ' +
                    order.getOrderNumber(), msg,
                    '*****@*****.**',
                    ['*****@*****.**', order.user.email])
                email.attach_alternative(msg, "text/html")
                # email.send()
                '''---------------------------------------inventory----------------------------------------------'''
                pos = order.productorder_set.all()
                for x in pos:
                    if x.product.inventory:
                        x.product.inventory -= x.quantity
                        x.product.save()
                        if x.product.inventory <= x.product.maximum_quantity_wholesale:
                            t = loader.get_template('productinshort.html')
                            c = RequestContext(request, {'product': x.product})
                            msg = t.render(c)
                            send_mail(
                                'EASTBOURNEART Product In Short - Product ' +
                                x.product.title,
                                msg,
                                '*****@*****.**', [
                                    '*****@*****.**',
                                    '*****@*****.**'
                                ],
                                fail_silently=False)
                    '''----------------------------------------------------------------------------------------------'''
                '''coupon =  request.session.get('coupon')
                coupons = Coupon.objects.all()
                for x in coupons:
                    r = x if x.checkCode(coupon) else None'''
                #if r:
                #r.addUsed(coupon)
                # send_mail('EASTBOURNEART Order Received - Order '+ order.getOrderNumber(), msg, '*****@*****.**', [order.user.email], fail_silently=False)
                request.session["order_id"] = None
                request.session['coupon'] = ''
                t = loader.get_template('success.html')
            else:
                t = loader.get_template('confirm.html')
                msgg = 'Sorry, we cannot checkout your order with paypal, please pay by another method.'
    else:

        t = loader.get_template('success.html')
    c = RequestContext(
        request,
        common.commonDict({
            'orderid': orderid.zfill(4),
            'msg': msgg
        }, request))
    return HttpResponse(t.render(c))
Beispiel #10
0
def payment(request):
    # TODO logging needs to be added into here
    msg = ''
    form = ''
    t = loader.get_template('payment.html')
    message = ''
    if request.session.get("order_id", None):
        order = Order.objects.get(pk=request.session.get("order_id", 0))
    else:
        raise ValueError("Order not found")
    '''-------------------------------paypal-------------------------------------------------'''
    if request.POST.get("paypalcheckout.x", None):
        if float(order.getShippingCharged()) != 0:
            msgg = common.getResponse(order)

            if msgg['ACK'] == 'Success':

                return HttpResponseRedirect(
                    "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%s&useraction=commit"
                    % msgg['TOKEN'])
            else:
                msg = msgg
                '''----------------------------------------------------------------------------------------'''

    elif request.POST:
        rp = request.POST.copy()
        if rp.get("editmyorder"):
            return HttpResponseRedirect("cart.html")
        form = CreditCardForm(rp)
        if form.is_valid():
            profile = order.user.get_profile()
            shipping = profile.shipping_set.all()
            billing = profile.billing_set.all()
            customer = Customer()
            names = form.cleaned_data.get("name")
            firstname = names[0]
            lastname = names[1]
            customer.first_name = firstname
            customer.last_name = lastname
            customer.email = billing[0].email
            customer.address = billing[0].address
            customer.postcode = billing[0].postcode
            customer.invoice_description = "Order from eastbourneart"
            customer.invoice_reference = order.getOrderNumber()
            customer.country = billing[0].country

            #op = CreditPayment()
            credit_card = CreditCard()
            #op.type = form.cleaned_data.get("type")
            credit_card.number = form.cleaned_data.get("number")
            credit_card.expiry_month = form.cleaned_data.get("expiryMonth")
            credit_card.expiry_year = form.cleaned_data.get("expiryYear")

            credit_card.holder_name = '%s %s' % (
                firstname,
                lastname,
            )
            credit_card.verification_number = form.cleaned_data.get("CVV")
            credit_card.ip_address = request.META["REMOTE_ADDR"]

            amount = float(order.total_charged)

            if customer.is_valid() and credit_card.is_valid():

                #17019375
                eway_client = EwayPaymentClient('17019375',
                                                config.REAL_TIME_CVN, True)
                response = eway_client.authorize(Decimal(str(amount)),
                                                 credit_card=credit_card,
                                                 customer=customer)
                if response.status.lower() == 'true':
                    order.status = OrderStatus.objects.get(
                        status__iexact=settings.TXT_SHOP_ORDER_STATUS_ORDERED)
                    order.save()
                    payment = True
                    t = loader.get_template('orderconfirmationemail.html')
                    d = {
                        "profile": profile,
                        "shipping": shipping[0],
                        "billing": billing[0],
                        'payment': payment
                    }
                    c = RequestContext(request, common.commonDict(d, request))
                    msg = t.render(c)
                    email = EmailMultiAlternatives(
                        'EASTBOURNEART Order Received - Order ' +
                        order.getOrderNumber(), msg,
                        '*****@*****.**',
                        ['*****@*****.**', order.user.email])
                    email.attach_alternative(msg, "text/html")
                    email.send()
                    '''---------------------------------------inventory----------------------------------------------'''
                    pos = order.productorder_set.all()
                    for x in pos:
                        if x.product.inventory:
                            x.product.inventory -= x.quantity
                            x.product.save()
                            if x.product.inventory <= x.product.maximum_quantity_wholesale:
                                t = loader.get_template('productinshort.html')
                                c = RequestContext(request,
                                                   {'product': x.product})
                                msg = t.render(c)
                                send_mail(
                                    'EASTBOURNEART Product In Short - Product '
                                    + x.product.title,
                                    msg,
                                    '*****@*****.**', [
                                        '*****@*****.**',
                                        '*****@*****.**'
                                    ],
                                    fail_silently=False)
                    '''----------------------------------------------------------------------------------------------'''
                    '''coupon =  request.session.get('coupon')
                    coupons = Coupon.objects.all()
                    for x in coupons:
                        r = x if x.checkCode(coupon) else None'''
                    #if r:
                    #r.addUsed(coupon)
                    # send_mail('EASTBOURNEART Order Received - Order '+ order.getOrderNumber(), msg, '*****@*****.**', [order.user.email], fail_silently=False)
                    request.session["order_id"] = None
                    request.session['coupon'] = ''
                    return HttpResponseRedirect("success%s.html" % order.id)
                else:
                    message = response.error

            else:
                return HttpResponse("ERROR: %s" %
                                    "Please supply all required infomation")
    else:
        form = CreditCardForm()
    country = request.session.get("shippingcountry", None)
    postcode = request.session.get("shippingpostcode", None)
    weight = order.getTotalWeight()
    try:
        if country.strip().lower() == "australia":
            price = postAustralia(getBoxes(order), getBoxWeight(order),
                                  postcode, order.getTotal())
        else:
            price = postInternational(getBoxes(order), getBoxWeight(order),
                                      postcode, country, order.getTotal())
        if not price:
            price = "?"
        price = 0.00 if price == 'free' else price
    except Exception, e:
        price = "?"
Beispiel #11
0
def confirmdetails(request):
    rp = request.POST.copy()
    order = Order.objects.get(pk=request.session.get("order_id", 0))
    u = order.user
    if rp.get("editmydetails",
              None) and request.user and request.user.is_active:
        return HttpResponseRedirect("/wholesale/shipping.html")
    if rp.get("editmydetails", None):
        return HttpResponseRedirect("details.html")
    if rp.get("editmyorder", None):
        return HttpResponseRedirect("cart.html")
    if rp.get("submitthisorder", None):
        order.status = OrderStatus.objects.get(status__iexact='pending')
        order.save()
        profile = u.get_profile()
        shipping = profile.shipping_set.all()
        if shipping:
            shipping = shipping[0]
        billing = profile.billing_set.all()
        if billing:
            billing = billing[0]

        payment = False
        t = loader.get_template('orderconfirmationemail.html')
        d = {
            "profile": profile,
            "shipping": shipping,
            "billing": billing,
            'payment': payment
        }
        c = RequestContext(request, common.commonDict(d, request))
        msg = t.render(c)
        email = EmailMultiAlternatives(
            'EASTBOURNEART Order Received - Order ' + order.getOrderNumber(),
            msg, '*****@*****.**',
            ['*****@*****.**', order.user.email])
        email.attach_alternative(msg, "text/html")
        email.send()
        '''---------------------------------------inventory----------------------------------------------'''
        pos = order.productorder_set.all()
        for x in pos:
            if x.product.inventory:
                x.product.inventory -= x.quantity
                x.product.save()
                if x.product.inventory <= x.product.maximum_quantity_wholesale:
                    t = loader.get_template('productinshort.html')
                    c = RequestContext(request, {'product': x.product})
                    msg = t.render(c)
                    send_mail('EASTBOURNEART Product In Short - Product ' +
                              x.product.title,
                              msg,
                              '*****@*****.**', [
                                  '*****@*****.**',
                                  '*****@*****.**'
                              ],
                              fail_silently=False)
        '''----------------------------------------------------------------------------------------------'''

        #send_mail('EASTBOURNEART Order Received - Order '+ order.getOrderNumber(), msg, '*****@*****.**', [order.user.email], fail_silently=False)
        '''coupon =  request.session.get('coupon')
        coupons = Coupon.objects.all()
        for x in coupons:
            r = x if x.checkCode(coupon) else None'''
        #if r:
        #r.addUsed(coupon)

        request.session["order_id"] = None
        request.session['coupon'] = ''
        return HttpResponseRedirect("success%s.html" % order.id)
    if request.POST:
        return HttpResponseRedirect("payment.html")
    if request.user.is_active:
        t = loader.get_template('wholesalecheckoutconfirmdetails.html')
    else:
        t = loader.get_template('checkoutconfirmdetails.html')
    profile = u.get_profile()
    country = request.session.get("shippingcountry", None)
    postcode = request.session.get("shippingpostcode", None)
    order = Order.objects.get(
        pk=request.session.get("order_id", 0),
        status=OrderStatus.objects.get(
            status=settings.TXT_SHOP_ORDER_STATUS_IN_PROGRESS))
    weight = order.getTotalWeight()
    if not request.user.is_active:
        try:
            if country.strip().lower() == "australia":
                price = postAustralia(getBoxes(order), getBoxWeight(order),
                                      postcode, order.getTotal())
            else:
                price = postInternational(getBoxes(order), getBoxWeight(order),
                                          postcode, country, order.getTotal())
            if not price:
                price = "?"
            price = 0.00 if price == 'free' else price
        except Exception, e:
            price = "?"
Beispiel #12
0
    p = Paginator(list(products), settings.PRODUCTS_PER_PAGE)
    try:
        pagination = {"paginator": p, "page": p.page(page), "pagenumber": page}
        products = p.page(page).object_list
    except EmptyPage, e:
        return HttpResponseRedirect(cat.getUrl())
    openpath = ["shop"]
    if cat.parent:
        openpath.append(cat.parent.slug)
    openpath.append(code)
    c = RequestContext(
        request,
        common.commonDict(
            {
                'category': cat,
                'products': common.split_list(products, 3),
                'page': pagination,
                "openpath": openpath,
            }, request))
    return HttpResponse(t.render(c))


def featuredxml(request):
    t = loader.get_template('featured.xml')

    # Lets select products based on the type of customer we're working with
    c = RequestContext(request,
                       common.commonDict({"openpath": ["home"]}, request))
    return HttpResponse(t.render(c), mimetype="application/xml")