Пример #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 handle_contact_group_m2m_changed(sender, instance, **kwargs):
    if isinstance(instance, Contact):
        bump_all_price_caches(set(instance.shops.values_list("pk", flat=True)))
    elif isinstance(instance, ContactGroup):
        if instance.shop_id:
            bump_all_price_caches([instance.shop_id])
        else:
            bump_all_price_caches()
Пример #6
0
def handle_contact_group_m2m_changed(sender, instance, **kwargs):
    if isinstance(instance, Contact):
        bump_all_price_caches(set(instance.shops.values_list("pk", flat=True)))
    elif isinstance(instance, ContactGroup):
        if instance.shop_id:
            bump_all_price_caches([instance.shop_id])
        else:
            bump_all_price_caches()
Пример #7
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)
Пример #8
0
def handle_post_save_bump_all_prices_caches(sender, instance, **kwargs):
    # bump all the prices for all the shops, as it is impossible to know
    # from which shop things have changed
    bump_all_price_caches()
Пример #9
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)
Пример #10
0
def handle_post_save_bump_all_prices_caches(sender, instance, **kwargs):
    # bump all the prices for all the shops, as it is impossible to know
    # from which shop things have changed
    bump_all_price_caches()
Пример #11
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)
Пример #12
0
def handle_cgp_price_post_save(sender, instance, **kwargs):
    bump_all_price_caches([instance.shop_id])
Пример #13
0
 def process(self, request, ids):
     shop = get_shop(request)
     Discount.objects.archived(shop).filter(_get_query(ids)).delete()
     bump_all_price_caches([shop.pk])
Пример #14
0
 def process(self, request, ids):
     shop = get_shop(request)
     Discount.objects.active(shop).filter(
         _get_query(ids)).update(active=False)
     bump_all_price_caches([shop.pk])
Пример #15
0
def handle_cgp_price_post_save(sender, instance, **kwargs):
    bump_all_price_caches([instance.shop_id])
Пример #16
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)