Exemplo n.º 1
0
def get_best_selling_products(context,
                              n_products=12,
                              cutoff_days=30,
                              orderable_only=True,
                              sale_items_only=False):
    request = context["request"]

    key, product_ids = context_cache.get_cached_value(
        identifier="best_selling_products",
        item=cache_utils.get_best_selling_products_cache_item(request.shop),
        context=request,
        n_products=n_products,
        cutoff_days=cutoff_days,
        orderable_only=orderable_only,
        sale_items_only=sale_items_only)

    if product_ids is not None and _can_use_cache(product_ids, request.shop,
                                                  request.customer):
        return Product.objects.filter(id__in=product_ids)

    products = _get_best_selling_products(cutoff_days, n_products,
                                          orderable_only, request,
                                          sale_items_only)
    product_ids = [product.id for product in products]
    context_cache.set_cached_value(
        key, product_ids, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
Exemplo n.º 2
0
def get_best_selling_products(context,
                              n_products=12,
                              cutoff_days=30,
                              orderable_only=True,
                              supplier=None):
    request = context["request"]

    key, products = context_cache.get_cached_value(
        identifier="best_selling_products_%s" %
        (supplier.pk if supplier else ""),
        item=cache_utils.get_best_selling_products_cache_item(request.shop),
        context=request,
        n_products=n_products,
        cutoff_days=cutoff_days,
        orderable_only=orderable_only)

    if products is not None:
        return products

    products = _get_best_selling_products(cutoff_days,
                                          n_products,
                                          orderable_only,
                                          request,
                                          supplier=supplier)
    context_cache.set_cached_value(
        key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
Exemplo n.º 3
0
def handle_context_cache_item_bumped(sender, item, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if isinstance(item, ShopProduct):
        shop = item.shop
        context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
Exemplo n.º 4
0
 def bump_cache_for_shop_id(shop_id):
     context_cache.bump_cache_for_item(
         cache_utils.get_listed_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_best_selling_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_newest_products_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_products_for_category_cache_item(shop_id))
     context_cache.bump_cache_for_item(
         cache_utils.get_random_products_cache_item(shop_id))
Exemplo n.º 5
0
def handle_context_cache_item_bumped(sender, item, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if isinstance(item, ShopProduct):
        shop = item.shop
        context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
        bump_product_queryset_cache()

    elif isinstance(item, Product):
        bump_product_queryset_cache()
Exemplo n.º 6
0
def get_best_selling_products(context, n_products=12, cutoff_days=30, orderable_only=True):
    request = context["request"]

    key, products = context_cache.get_cached_value(
        identifier="best_selling_products",
        item=cache_utils.get_best_selling_products_cache_item(request.shop),
        context=request,
        n_products=n_products, cutoff_days=cutoff_days,
        orderable_only=orderable_only
    )

    if products is not None:
        return products

    products = _get_best_selling_products(cutoff_days, n_products, orderable_only, request)
    context_cache.set_cached_value(key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
Exemplo n.º 7
0
def handle_context_cache_item_bumped(sender, item, shop=None, **kwargs):
    """
    Every time the context cache is bumped for a ShopProduct
    we bump the context cache for template helpers for the item's shop
    """
    if issubclass(sender, ShopProduct):
        if not shop and isinstance(item, int):
            shop = ShopProduct.objects.get(id=item).shop
        elif not shop:
            shop = item.shop
        context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop))
        context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
        bump_product_queryset_cache()

    elif issubclass(sender, Product):
        bump_product_queryset_cache()