Exemplo n.º 1
0
def handle_manufacturer_post_save(sender, instance, **kwargs):
    """
    Everytime a manufacturer gets saved, we bump our caches for manufacturer's shop or all shops
    """
    if instance.shops.exists():
        for shop in instance.shops.only("pk").all():
            context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
    else:
        # worst scenario ever
        for shop in Shop.objects.only("pk").all():
            context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
Exemplo n.º 2
0
def handle_manufacturer_post_save(sender, instance, **kwargs):
    """
    Everytime a manufacturer gets saved, we bump our caches for manufacturer's shop or all shops
    """
    if instance.shops.exists():
        for shop in instance.shops.only("pk").all():
            context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
    else:
        # worst scenario ever
        for shop in Shop.objects.only("pk").all():
            context_cache.bump_cache_for_item(cache_utils.get_all_manufacturers_cache_item(shop))
Exemplo n.º 3
0
def get_all_manufacturers(context):
    request = context["request"]
    key, manufacturers = context_cache.get_cached_value(
        identifier="all_manufacturers", item=cache_utils.get_all_manufacturers_cache_item(request.shop), context=request
    )
    if manufacturers is not None:
        return manufacturers

    products = Product.objects.listed(shop=request.shop, customer=request.customer)
    manufacturers_ids = products.values_list("manufacturer__id").distinct()
    manufacturers = Manufacturer.objects.filter(pk__in=manufacturers_ids)
    context_cache.set_cached_value(key, manufacturers, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return manufacturers
Exemplo n.º 4
0
def get_all_manufacturers(context):
    request = context["request"]
    key, manufacturers = context_cache.get_cached_value(
        identifier="all_manufacturers",
        item=cache_utils.get_all_manufacturers_cache_item(request.shop),
        context=request
    )
    if manufacturers is not None:
        return manufacturers

    products = Product.objects.listed(shop=request.shop, customer=request.customer)
    manufacturers_ids = products.values_list("manufacturer__id").distinct()
    manufacturers = Manufacturer.objects.filter(pk__in=manufacturers_ids)
    context_cache.set_cached_value(key, manufacturers, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION)
    return manufacturers