コード例 #1
0
ファイル: general.py プロジェクト: tmskrtsz/shuup
def get_random_products(context, n_products=6, orderable_only=True, sale_items_only=False):
    request = context["request"]
    key, products = context_cache.get_cached_value(
        identifier="random_products",
        item=cache_utils.get_random_products_cache_item(request.shop),
        context=request,
        n_products=n_products, orderable_only=orderable_only,
        sale_items_only=sale_items_only
    )
    if products is not None:
        return products

    products = get_listed_products(
        context,
        n_products,
        ordering="?",
        filter_dict={
            "variation_parent": None
        },
        orderable_only=orderable_only,
        sale_items_only=sale_items_only
    )
    products = cache_product_things(request, products)
    context_cache.set_cached_value(key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
コード例 #2
0
ファイル: general.py プロジェクト: laxmikamat/shuup
def get_random_products(context,
                        n_products=6,
                        orderable_only=True,
                        sale_items_only=False):
    request = context["request"]
    key, product_ids = context_cache.get_cached_value(
        identifier="random_products",
        item=cache_utils.get_random_products_cache_item(request.shop),
        context=request,
        n_products=n_products,
        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_listed_products(context,
                                   n_products,
                                   ordering="?",
                                   filter_dict={"variation_parent": None},
                                   orderable_only=orderable_only,
                                   sale_items_only=sale_items_only)
    products = cache_product_things(request, products)
    product_ids = [product.id for product in products]
    context_cache.set_cached_value(
        key, product_ids, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products
コード例 #3
0
ファイル: signal_handlers.py プロジェクト: wayhome25/shuup
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))
コード例 #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))
コード例 #5
0
ファイル: signal_handlers.py プロジェクト: ruqaiya/shuup
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()
コード例 #6
0
ファイル: signal_handlers.py プロジェクト: zaster/shuup
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()
コード例 #7
0
ファイル: general.py プロジェクト: ruqaiya/shuup
def get_random_products(context, n_products=6, orderable_only=True):
    request = context["request"]
    key, products = context_cache.get_cached_value(
        identifier="random_products",
        item=cache_utils.get_random_products_cache_item(request.shop),
        context=request,
        n_products=n_products, orderable_only=orderable_only
    )
    if products is not None:
        return products

    products = _get_listed_products(
        context,
        n_products,
        ordering="?",
        filter_dict={
            "variation_parent": None
        },
        orderable_only=orderable_only
    )
    products = cache_product_things(request, products)
    context_cache.set_cached_value(key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return products