예제 #1
0
def handle_coupon_post_save(sender, instance, **kwargs):
    # Bump caches only if discount object exists
    # This prevents to bump caches when an instance is created and it is not attached yey
    if instance.coupon_code_discounts.exists():
        shops = set(instance.coupon_code_discounts.values_list("shops__pk", flat=True))
        bump_price_expiration(shops)
        bump_all_price_caches(shops)
예제 #2
0
def handle_coupon_post_save(sender, instance, **kwargs):
    # Bump caches only if discount object exists
    # This prevents to bump caches when an instance is created and it is not attached yey
    if instance.coupon_code_discounts.exists():
        shops = set(instance.coupon_code_discounts.values_list("shops__pk", flat=True))
        bump_price_expiration(shops)
        bump_all_price_caches(shops)
예제 #3
0
def handle_generic_m2m_changed(sender, instance, **kwargs):
    """
    As `instance` can be an instance of the sender or of the class the ManyToManyField is related to,
    we need to check the type of the instance and forward to the correct handler
    """
    if isinstance(instance, ShopProduct):
        bump_price_expiration([instance.shop_id])
        bump_all_price_caches([instance.shop_id])
    elif isinstance(instance, Category):
        for shop_id in set(instance.shop_products.all().values_list(
                "shop_id", flat=True)):
            bump_price_expiration([shop_id])
            bump_all_price_caches([shop_id])
    elif isinstance(instance, Discount):
        handle_discount_post_save(sender, instance, **kwargs)
    elif isinstance(instance, HappyHour):
        handle_happy_hour_post_save(sender, instance, **kwargs)
    else:
        raise DiscountM2MChangeError("Invalid instance type.")
예제 #4
0
def handle_generic_m2m_changed(sender, instance, **kwargs):
    """
    As `instance` can be an instance of the sender or of the class the ManyToManyField is related to,
    we need to check the type of the instance and forward to the correct handler
    """
    if isinstance(instance, ShopProduct):
        bump_price_expiration([instance.shop_id])
        bump_all_price_caches([instance.shop_id])
    elif isinstance(instance, Category):
        for shop_id in set(instance.shop_products.all().values_list("shop_id", flat=True)):
            bump_price_expiration([shop_id])
            bump_all_price_caches([shop_id])
    elif isinstance(instance, Discount):
        handle_discount_post_save(sender, instance, **kwargs)
    elif isinstance(instance, HappyHour):
        handle_happy_hour_post_save(sender, instance, **kwargs)
    elif isinstance(instance, AvailabilityException):
        handle_availability_exception_post_save(sender, instance, **kwargs)
    else:
        raise DiscountM2MChangeError("Invalid instance type.")
예제 #5
0
def hangle_generic_m2m_changed(sender, instance, **kwargs):
    """
    As `instance` can be an instance of the sender or of the class the ManyToManyField is related to,
    we need to check the type of the instance and forward to the correct handler
    """
    if isinstance(instance, Shop):
        bump_price_expiration([instance.pk])
        bump_all_price_caches([instance.pk])

    elif isinstance(instance, ShopProduct):
        bump_price_expiration([instance.shop_id])
        bump_all_price_caches([instance.shop_id])

    elif isinstance(instance, Discount):
        handle_discount_post_save(sender, instance, **kwargs)

    elif isinstance(instance, HappyHour):
        handle_happy_hour_post_save(sender, instance, **kwargs)

    elif isinstance(instance, TimeRange):
        handle_time_range_post_save(sender, instance, **kwargs)

    elif isinstance(instance, AvailabilityException):
        handle_availability_exception_post_save(sender, instance, **kwargs)
예제 #6
0
def handle_discount_post_save(sender, instance, **kwargs):
    shops = set(instance.shops.values_list("pk", flat=True))
    bump_price_expiration(shops)
    bump_all_price_caches(shops)
예제 #7
0
def handle_discount_post_save(sender, instance, **kwargs):
    shop_ids = set([instance.shop.pk])
    bump_price_expiration(shop_ids)
    bump_all_price_caches(shop_ids)
예제 #8
0
def handle_discount_post_save(sender, instance, **kwargs):
    shops = set(instance.shops.values_list("pk", flat=True))
    bump_price_expiration(shops)
    bump_all_price_caches(shops)