コード例 #1
0
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
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
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
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
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
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
ファイル: signal_handers.py プロジェクト: yashodhank/shuup
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
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
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
ファイル: mass_actions.py プロジェクト: yashodhank/shuup
 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
ファイル: mass_actions.py プロジェクト: yashodhank/shuup
 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
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
def handle_cgp_price_post_save(sender, instance, **kwargs):
    bump_all_price_caches([instance.shop_id])
コード例 #16
0
ファイル: signal_handers.py プロジェクト: ruqaiya/shuup
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)