Exemple #1
0
def order_repeat(request, hash):

    # THE PREVIOUS ORDER ITEM
    old_order = get_object_or_404(Order, hashkey=hash)

    new_order = Order.objects.create(
        date_confirmed=datetime.now(),
        address=old_order.address,
        owner=old_order.owner,
        status=Order.STATUS_CREATED_NOT_PAID,
        invoice_id="TEMP",
    )

    new_order.invoice_id = "TEA-00%s" % (new_order.id)
    new_order.save()

    # we'll also create a basket for them.
    # because IF they want to add something else to the order,
    # they'll need a basket.
    basket = Basket.objects.create(
        date_modified=datetime.now(),
        owner=new_order.owner,
    )

    # now we'll check for replacements/substitutions
    currency = _get_currency(request)

    for item in old_order.items.all():
        if item.item.is_active == False:
            # if it's not available, replace it with the closest matching UniqueProduct
            product = UniqueProduct.objects.filter(
                parent_product=item.item.parent_product,
                sale_price__isnull=True,
                currency=currency,
                is_active=True,
            ).order_by('-price')[0]
            basket_item = BasketItem.objects.create(item=product,
                                                    quantity=item.quantity,
                                                    basket=basket)
            new_order.items.add(basket_item)
        else:
            new_order.items.add(item)

    # for each item attached to the new order, reassign the basket to this new basket
    for item in new_order.items.all():
        item.basket = basket
        item.save()

    request.session['BASKET_ID'] = basket.id
    request.session['ORDER_ID'] = new_order.id

    # FINALLY, GET THE VALUES ETC.
    basket = _get_basket_value(request, order=new_order)

    return _render(request, 'shop/forms/order_repeat.html', locals())
Exemple #2
0
def sale(request):
    category = get_object_or_404(Category, slug=_('sale'))
    ups = UniqueProduct.objects.filter(is_active=True,
                                       sale_price__isnull=False,
                                       currency=_get_currency(request))
    products = []
    for x in ups:
        p = x.parent_product
        p.price = x
        products.append(p)

    return _render(request, "shop/category.html", locals())
Exemple #3
0
def order_repeat(request, hash):

    # THE PREVIOUS ORDER ITEM
    old_order = get_object_or_404(Order, hashkey=hash)

    new_order = Order.objects.create(
        date_confirmed=datetime.now(),
        address=old_order.address,
        owner=old_order.owner,
        status=Order.STATUS_CREATED_NOT_PAID,
        invoice_id="TEMP",
    )

    new_order.invoice_id = "TEA-00%s" % (new_order.id)
    new_order.save()

    # we'll also create a basket for them.
    # because IF they want to add something else to the order,
    # they'll need a basket.
    basket = Basket.objects.create(date_modified=datetime.now(), owner=new_order.owner)

    # now we'll check for replacements/substitutions
    currency = _get_currency(request)

    for item in old_order.items.all():
        if item.item.is_active == False:
            # if it's not available, replace it with the closest matching UniqueProduct
            product = UniqueProduct.objects.filter(
                parent_product=item.item.parent_product, sale_price__isnull=True, currency=currency, is_active=True
            ).order_by("-price")[0]
            basket_item = BasketItem.objects.create(item=product, quantity=item.quantity, basket=basket)
            new_order.items.add(basket_item)
        else:
            new_order.items.add(item)

    # for each item attached to the new order, reassign the basket to this new basket
    for item in new_order.items.all():
        item.basket = basket
        item.save()

    request.session["BASKET_ID"] = basket.id
    request.session["ORDER_ID"] = new_order.id

    # FINALLY, GET THE VALUES ETC.
    basket = _get_basket_value(request, order=new_order)

    return _render(request, "shop/forms/order_repeat.html", locals())
Exemple #4
0
def tea_view(request, slug):

    try:
        added = request.session['ADDED']
    except:
        added = None

    if added:
        try:
            thing = get_object_or_404(BasketItem, id=request.session['ADDED'])
            from shop.templatetags.convert_weights import convert_weights
            weight = convert_weights(request, thing.item.weight)
            message = _("1 x %(weight)s%(unit)s added to your basket!") % {
                'weight': weight,
                'unit': RequestContext(request)['weight_unit']
            }
            request.session['ADDED'] = None
        except:
            pass

    tea = get_object_or_404(Product, slug=slug)

    try:
        review = Review.objects.filter(is_published=True,
                                       product=tea,
                                       lang=get_language()).order_by('?')[0]
    except:
        pass

    # IF IT'S A MONTHLY ITEM, LET'S REDIRECT HERE:
    if tea.slug == _('monthly-tea-box'):
        return monthly_tea_box(request)

    recommended = _get_products(request, random=True, exclude=tea.id)[:4]
    prices = UniqueProduct.objects.filter(
        is_active=True, parent_product=tea,
        currency=_get_currency(request)).order_by('weight')

    # IN CASE OF DEALS ON THE PAGE
    multiple_form = AddMultipleItemsToBasket()

    return _render(request, "shop/tea_view.html", locals())
Exemple #5
0
def monthly_tea_box(request):

    product = get_object_or_404(Product, slug=_('monthly-tea-box'))
    products = Product.objects.filter(
        category__parent_category__slug=_('teas'), is_active=True)

    basket_items = BasketItem.objects.filter(basket=_get_basket(request))

    try:
        months = int(request.session['MONTHS'])
    except:
        months = settings.TEABOX_DEFAULT_MONTHS

    if product.is_active:
        excluded = []
        total_quantity = 0
        for x in products:

            x.single_price = x.get_lowest_price(_get_currency(request),
                                                exclude_sales=True)

            if not x.single_price.stocks():
                excluded.append(x.id)
                continue
                # weird... the above thing doesn't work.

            try:
                x.price = _get_monthly_price(x.single_price, months)
            except:
                x.price = None

            x.quantity = 0
            for y in basket_items:
                if x.single_price == y.item:
                    x.quantity += y.quantity
                    total_quantity += 1

        products.exclude(id__in=excluded, name__icontains=_("taster"))

    return _render(request, 'shop/monthly_tea_box.html', locals())
Exemple #6
0
def category(request, slug):
    curr = _get_currency(request)
    if slug == _("teas") or slug == _("teaware"):
        products = None
        category = get_object_or_404(Category, slug=slug)
        categories = Category.objects.filter(parent_category__slug=slug)
        for c in categories:
            c.products = _get_products(request, c.slug)

    else:
        category = get_object_or_404(Category, slug=slug)
        products = _get_products(request, category.slug)

    basket = _get_basket(request)
    if basket and products:
        for x in products:
            basket_item = BasketItem.objects.filter(basket=basket, item=x.get_lowest_price(curr))
            x.price = x.get_lowest_price(curr)
            if basket_item.count() > 0:
                x.basket_quantity = basket_item[0].quantity

    return _render(request, "shop/category.html", locals())
Exemple #7
0
def not_you(request):

    # remember the user's basket, otherwise they 'logout' but lose their own basket.
    this_user = request.user
    basket = Basket.objects.get(id=request.session['BASKET_ID'])
    currency = _get_currency(request)

    # log the user out
    if request.user.is_authenticated():
        from django.contrib.auth import load_backend, logout
        for backend in settings.AUTHENTICATION_BACKENDS:
            if this_user == load_backend(backend).get_user(this_user.pk):
                this_user.backend = backend
        if hasattr(this_user, 'backend'):
            logout(request)
            # re-add the basket cookie so they don't lose their items

            request.session['BASKET_ID'] = basket.id
            request.session['CURRENCY'] = currency

    # now they can return to the usual Step 1 of the form
    return HttpResponseRedirect('/order/step-one/')
Exemple #8
0
def monthly_tea_box(request):

    product = get_object_or_404(Product, slug=_("monthly-tea-box"))
    products = Product.objects.filter(category__parent_category__slug=_("teas"), is_active=True)

    basket_items = BasketItem.objects.filter(basket=_get_basket(request))

    try:
        months = int(request.session["MONTHS"])
    except:
        months = settings.TEABOX_DEFAULT_MONTHS

    if product.is_active:
        excluded = []
        total_quantity = 0
        for x in products:

            x.single_price = x.get_lowest_price(_get_currency(request), exclude_sales=True)

            if not x.single_price.stocks():
                excluded.append(x.id)
                continue
                # weird... the above thing doesn't work.

            try:
                x.price = _get_monthly_price(x.single_price, months)
            except:
                x.price = None

            x.quantity = 0
            for y in basket_items:
                if x.single_price == y.item:
                    x.quantity += y.quantity
                    total_quantity += 1

        products.exclude(id__in=excluded, name__icontains=_("taster"))

    return _render(request, "shop/monthly_tea_box.html", locals())
Exemple #9
0
def not_you(request):

    # remember the user's basket, otherwise they 'logout' but lose their own basket.
    this_user = request.user
    basket = Basket.objects.get(id=request.session["BASKET_ID"])
    currency = _get_currency(request)

    # log the user out
    if request.user.is_authenticated():
        from django.contrib.auth import load_backend, logout

        for backend in settings.AUTHENTICATION_BACKENDS:
            if this_user == load_backend(backend).get_user(this_user.pk):
                this_user.backend = backend
        if hasattr(this_user, "backend"):
            logout(request)
            # re-add the basket cookie so they don't lose their items

            request.session["BASKET_ID"] = basket.id
            request.session["CURRENCY"] = currency

    # now they can return to the usual Step 1 of the form
    return HttpResponseRedirect("/order/step-one/")
Exemple #10
0
def category(request, slug):
    curr = _get_currency(request)
    if slug == _('teas') or slug == _('teaware'):
        products = None
        category = get_object_or_404(Category, slug=slug)
        categories = Category.objects.filter(parent_category__slug=slug)
        for c in categories:
            c.products = _get_products(request, c.slug)

    else:
        category = get_object_or_404(Category, slug=slug)
        products = _get_products(request, category.slug)

    basket = _get_basket(request)
    if basket and products:
        for x in products:
            basket_item = BasketItem.objects.filter(
                basket=basket, item=x.get_lowest_price(curr))
            x.price = x.get_lowest_price(curr)
            if basket_item.count() > 0:
                x.basket_quantity = basket_item[0].quantity

    return _render(request, "shop/category.html", locals())
Exemple #11
0
def tea_view(request, slug):

    try:
        added = request.session["ADDED"]
    except:
        added = None

    if added:
        try:
            thing = get_object_or_404(BasketItem, id=request.session["ADDED"])
            from shop.templatetags.convert_weights import convert_weights

            weight = convert_weights(request, thing.item.weight)
            message = _("1 x %(weight)s%(unit)s added to your basket!") % {
                "weight": weight,
                "unit": RequestContext(request)["weight_unit"],
            }
            request.session["ADDED"] = None
        except:
            pass

    tea = get_object_or_404(Product, slug=slug)

    try:
        review = Review.objects.filter(is_published=True, product=tea, lang=get_language()).order_by("?")[0]
    except:
        pass

    # IF IT'S A MONTHLY ITEM, LET'S REDIRECT HERE:
    if tea.slug == _("monthly-tea-box"):
        return monthly_tea_box(request)

    recommended = _get_products(request, random=True, exclude=tea.id)[:4]
    prices = UniqueProduct.objects.filter(is_active=True, parent_product=tea, currency=_get_currency(request)).order_by(
        "weight"
    )

    # IN CASE OF DEALS ON THE PAGE
    multiple_form = AddMultipleItemsToBasket()

    return _render(request, "shop/tea_view.html", locals())
Exemple #12
0
def sale(request):
    category = get_object_or_404(Category, slug=_("sale"))
    ups = UniqueProduct.objects.filter(is_active=True, sale_price__isnull=False, currency=_get_currency(request))
    products = []
    for x in ups:
        p = x.parent_product
        p.price = x
        products.append(p)

    return _render(request, "shop/category.html", locals())
def common(request):
    context = {}
    context['paypal_return_url'] = settings.PAYPAL_RETURN_URL
    context['paypal_notify_url'] = settings.PAYPAL_NOTIFY_URL
    context['paypal_business_name'] = settings.PAYPAL_BUSINESS_NAME
    context['paypal_receiver_email'] = settings.PAYPAL_RECEIVER_EMAIL
    context['paypal_submit_url'] = settings.PAYPAL_SUBMIT_URL
    context['stripe_public_key'] = settings.STRIPE_PUBLIC_KEY
    context['stripe_secret_key'] = settings.STRIPE_SECRET_KEY
    
    context['ga_is_on'] = settings.GA_IS_ON
    context['latestblogs'] = BlogEntry.objects.filter(is_draft=False, title__isnull=False).exclude(title__exact="None").order_by('-date_added')[:3]
    context['static_url'] = settings.STATIC_URL
    context['thumb_large'] = settings.THUMB_LARGE
    context['thumb_home_large'] = settings.THUMB_HOME_LARGE
    context['thumb_medium'] = settings.THUMB_MEDIUM
    context['thumb_small'] = settings.THUMB_SMALL
    
    context['date'] = datetime.now()
    
    
    # STUFF RELATED TO COUNTRY SPECIFIC SITES
    context['site_url'] = "http://www.minrivertea.com"
    context['analytics_id'] = settings.ANALYTICS_ID
    context['mailchimp_list_id'] = settings.MAILCHIMP_LIST_ID  
    
    # TEA OF THE MONTH
    try:
        totm = Product.objects.filter(totm__month=datetime.now().month, is_active=True)[0]
    except IndexError:
        totm = None
    context['totm'] = totm
    
    if get_language() == 'de':
        context['mailchimp_list_id'] = settings.GERMAN_MAILCHIMP_LIST_ID
        
    context['site_name'] = settings.SITE_NAME # the loose non-techy name


    # GET THE NAVIGATIONS
    context['main_nav'] = Category.objects.filter(is_navigation_item=True).order_by('list_order')
    context['top_nav'] = Page.objects.filter(is_top_nav=True).order_by('list_order')
     
             
        
    # REGIONAL STUFF
    context['region'] = _get_region(request)    
    if context['region'] == 'US':
        context['weight_unit'] = 'oz'
    else:
        context['weight_unit'] = 'g'
    
    
    # currency stuff
    context['currency'] = _get_currency(request) 
    

    # AFFILIATE STUFF
    if settings.AFFILIATE_SESSION_KEY in request.session:
        context['affiliate_session'] = True
    
    if request.GET.get(settings.AFFILIATE_URL_VARIABLE):
        context['landing_page'] = True # TODO we should change this to specify which landing page it shoudl show


    # CHANGE THE BASE TEMPLATE FOR ADMIN
    
    if '/admin-stuff/' in request.path:
        base_template = settings.BASE_TEMPLATE_ADMIN
    else:
        base_template = settings.BASE_TEMPLATE
    context['base_template'] = base_template


    # BASKET STUFF
    try:
        basket = Basket.objects.get(id=request.session['BASKET_ID'])
    except:
        basket = None
    
    
    try:
        context['basket_quantity'] = request.session['BASKET_QUANTITY']
        context['basket_amount'] = request.session['BASKET_AMOUNT']
    except:
        basket = _get_basket_value(request)
        context['basket_quantity'] = basket['basket_quantity']
        context['basket_amount'] = basket['total_price']  
    
            
    return context
def common(request):
    context = {}
    context['paypal_return_url'] = settings.PAYPAL_RETURN_URL
    context['paypal_notify_url'] = settings.PAYPAL_NOTIFY_URL
    context['paypal_business_name'] = settings.PAYPAL_BUSINESS_NAME
    context['paypal_receiver_email'] = settings.PAYPAL_RECEIVER_EMAIL
    context['paypal_submit_url'] = settings.PAYPAL_SUBMIT_URL
    context['stripe_public_key'] = settings.STRIPE_PUBLIC_KEY
    context['stripe_secret_key'] = settings.STRIPE_SECRET_KEY

    context['ga_is_on'] = settings.GA_IS_ON
    context['latestblogs'] = BlogEntry.objects.filter(
        is_draft=False, title__isnull=False).exclude(
            title__exact="None").order_by('-date_added')[:3]
    context['static_url'] = settings.STATIC_URL
    context['thumb_large'] = settings.THUMB_LARGE
    context['thumb_home_large'] = settings.THUMB_HOME_LARGE
    context['thumb_medium'] = settings.THUMB_MEDIUM
    context['thumb_small'] = settings.THUMB_SMALL

    context['date'] = datetime.now()

    # STUFF RELATED TO COUNTRY SPECIFIC SITES
    context['site_url'] = "http://www.minrivertea.com"
    context['analytics_id'] = settings.ANALYTICS_ID
    context['mailchimp_list_id'] = settings.MAILCHIMP_LIST_ID

    # TEA OF THE MONTH
    try:
        totm = Product.objects.filter(totm__month=datetime.now().month,
                                      is_active=True)[0]
    except IndexError:
        totm = None
    context['totm'] = totm

    if get_language() == 'de':
        context['mailchimp_list_id'] = settings.GERMAN_MAILCHIMP_LIST_ID

    context['site_name'] = settings.SITE_NAME  # the loose non-techy name

    # GET THE NAVIGATIONS
    context['main_nav'] = Category.objects.filter(
        is_navigation_item=True).order_by('list_order')
    context['top_nav'] = Page.objects.filter(
        is_top_nav=True).order_by('list_order')

    # REGIONAL STUFF
    context['region'] = _get_region(request)
    if context['region'] == 'US':
        context['weight_unit'] = 'oz'
    else:
        context['weight_unit'] = 'g'

    # currency stuff
    context['currency'] = _get_currency(request)

    # AFFILIATE STUFF
    if settings.AFFILIATE_SESSION_KEY in request.session:
        context['affiliate_session'] = True

    if request.GET.get(settings.AFFILIATE_URL_VARIABLE):
        context[
            'landing_page'] = True  # TODO we should change this to specify which landing page it shoudl show

    # CHANGE THE BASE TEMPLATE FOR ADMIN

    if '/admin-stuff/' in request.path:
        base_template = settings.BASE_TEMPLATE_ADMIN
    else:
        base_template = settings.BASE_TEMPLATE
    context['base_template'] = base_template

    # BASKET STUFF
    try:
        basket = Basket.objects.get(id=request.session['BASKET_ID'])
    except:
        basket = None

    try:
        context['basket_quantity'] = request.session['BASKET_QUANTITY']
        context['basket_amount'] = request.session['BASKET_AMOUNT']
    except:
        basket = _get_basket_value(request)
        context['basket_quantity'] = basket['basket_quantity']
        context['basket_amount'] = basket['total_price']

    return context