Exemplo n.º 1
0
 def delete(self, request, *args, **kwargs):
     response = super(SnippetDeleteView,
                      self).delete(request, *args, **kwargs)
     shop = get_shop(self.request)
     cache_key = GLOBAL_SNIPPETS_CACHE_KEY.format(shop_id=shop.pk)
     cache.bump_version(cache_key)
     return response
Exemplo n.º 2
0
    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)

        # bump children cache
        from shuup.core import cache
        cache.bump_version("category_cached_children")

        return rv
Exemplo n.º 3
0
    def save(self, *args, **kwargs):
        rv = super(Category, self).save(*args, **kwargs)
        generate_multilanguage_slugs(self, self._get_slug_name)

        # bump children cache
        from shuup.core import cache
        cache.bump_version("category_cached_children")

        return rv
Exemplo n.º 4
0
def test_cache_api():
    key = "test_prefix:123"
    value = "456"
    cache.set(key, value)
    assert cache.get(key) == value
    cache.bump_version(key)
    assert cache.get(key, default="derp") == "derp"  # version was bumped, so no way this is there
    cache.set(key, value)
    assert cache.get(key) == value
Exemplo n.º 5
0
def on_user_groups_change(instance, action, model, **kwargs):
    from shuup.admin.utils.permissions import USER_PERMISSIONS_CACHE_NAMESPACE
    # a group has changed it's users relation through group.users.set()
    # then we need to bump the entire cache
    if isinstance(instance, Group):
        cache.bump_version(USER_PERMISSIONS_CACHE_NAMESPACE)

    # bump only the user's permission cache
    elif isinstance(instance, get_user_model()):
        cache.bump_version("{}:{}".format(USER_PERMISSIONS_CACHE_NAMESPACE, instance.pk))
Exemplo n.º 6
0
def bump_cache_for_item(item):
    """
    Bump cache for given item

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param item: Cached object
    """
    cache.bump_version(_get_namespace_for_item(item))
Exemplo n.º 7
0
def bump_cache_for_item(item):
    """
    Bump cache for given item

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param item: Cached object
    """
    cache.bump_version(_get_namespace_for_item(item))
Exemplo n.º 8
0
def bump_cache_for_item(item):
    """
    Bump cache for given item

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param item: Cached object
    """
    cache.bump_version(_get_namespace_for_item(item))
    context_cache_item_bumped.send(getattr(item, "__class__", item), item=item)
Exemplo n.º 9
0
def bump_cache_for_item(item):
    """
    Bump cache for given item

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param item: Cached object
    """
    cache.bump_version(_get_namespace_for_item(item))
    context_cache_item_bumped.send(getattr(item, "__class__", item), item=item)
Exemplo n.º 10
0
def bump_cache_for_item_ids(item_ids, namespace, object_class, shop=None):
    """
    Bump cache for given item ids

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    :param ids: list of cached object id's
    """
    for item_id in item_ids:
        cache.bump_version("{}-{}".format(namespace, item_id))
Exemplo n.º 11
0
    def save(self, *args, **kwargs):
        if not self.key:
            self.key = uuid1().hex
        if not self.secret:
            self.secret = "{}{}".format(uuid4().hex, uuid4().hex)

        if self.pk:
            from shuup_api_permission.permissions import API_ACCESS_CACHE_KEY_FMT
            api_access_cache_key = API_ACCESS_CACHE_KEY_FMT.format(
                key=self.key)
            cache.bump_version(api_access_cache_key)

        super(APIAccess, self).save(*args, **kwargs)
Exemplo n.º 12
0
def set_configuration(shop=None, category=None, data=None):
    if category and category.pk:
        configuration.set(None, _get_category_configuration_key(category), data)
    elif shop:
        configuration.set(shop, FACETED_DEFAULT_CONF_KEY, data)
        cache.bump_version(get_theme_cache_key(shop))

    # clear active keys
    context_cache.bump_cache_for_item(category)
    if not category:
        from shuup.core.models import Category
        for cat_pk in Category.objects.all().values_list("pk", flat=True):
            context_cache.bump_cache_for_pk(Category, cat_pk)
Exemplo n.º 13
0
def set_configuration(shop=None, category=None, data=None):
    if category and category.pk:
        configuration.set(None, _get_category_configuration_key(category), data)
    elif shop:
        configuration.set(shop, FACETED_DEFAULT_CONF_KEY, data)
        cache.bump_version(get_theme_cache_key(shop))

    # clear active keys
    context_cache.bump_cache_for_item(category)
    if not category:
        from shuup.core.models import Category
        for cat_pk in Category.objects.all().values_list("pk", flat=True):
            context_cache.bump_cache_for_pk(Category, cat_pk)
Exemplo n.º 14
0
    def form_valid(self, form):
        identifier = form["theme"].cleaned_data["activate"]
        data = {"settings": {"stylesheet": form["theme"].cleaned_data["selected_style"]}}
        theme_settings, created = ThemeSettings.objects.get_or_create(
            theme_identifier=identifier, shop=get_shop(self.request)
        )
        if created:
            theme_settings.data = data
            theme_settings.save()
        else:
            theme_settings.update_settings(data["settings"])

        set_current_theme(identifier, self.object)
        cache.bump_version(get_theme_cache_key(get_shop(self.request)))
Exemplo n.º 15
0
 def form_valid(self, form):
     identifier = form["theme"].cleaned_data["activate"]
     theme = set_current_theme(identifier)
     data = {
         "settings": {
            "stylesheet": form["theme"].cleaned_data["selected_style"]
         }
     }
     theme_settings, created = ThemeSettings.objects.get_or_create(theme_identifier=theme.identifier)
     if created:
         theme_settings.data = data
     else:
         theme_settings.update_settings(data["settings"])
     theme_settings.activate()
     cache.bump_version(THEME_CACHE_KEY)
Exemplo n.º 16
0
def set_current_theme(identifier):
    """
    Activate a theme based on identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :return: Activated theme
    :rtype: Theme
    """
    cache.bump_version(THEME_CACHE_KEY)
    theme = get_theme_by_identifier(identifier)
    if not theme:
        raise ValueError("Invalid theme identifier")
    theme.set_current()
    cache.set(THEME_CACHE_KEY, theme)
    return theme
Exemplo n.º 17
0
 def form_valid(self, form):
     identifier = form["theme"].cleaned_data["activate"]
     theme = set_current_theme(identifier)
     data = {
         "settings": {
             "stylesheet": form["theme"].cleaned_data["selected_style"]
         }
     }
     theme_settings, created = ThemeSettings.objects.get_or_create(
         theme_identifier=theme.identifier)
     if created:
         theme_settings.data = data
     else:
         theme_settings.update_settings(data["settings"])
     theme_settings.activate()
     cache.bump_version(THEME_CACHE_KEY)
Exemplo n.º 18
0
def set_current_theme(identifier):
    """
    Activate a theme based on identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :return: Activated theme
    :rtype: Theme
    """
    cache.bump_version(THEME_CACHE_KEY)
    theme = get_theme_by_identifier(identifier)
    if not theme:
        raise ValueError("Invalid theme identifier")
    theme.set_current()
    cache.set(THEME_CACHE_KEY, theme)
    return theme
Exemplo n.º 19
0
def bump_cache_for_pk(cls, pk):
    """
    Bump cache for given class and pk combination

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    In case you need to use this to product or shop_product
    make sure you also bump related objects like in
    `bump_cache_for_shop_product`.

    :param cls: Class for cached object
    :param pk: pk for cached object
    """
    cache.bump_version("%s-%s" % (_get_namespace_prefix(cls), pk))
Exemplo n.º 20
0
def bump_cache_for_pk(cls, pk):
    """
    Bump cache for given class and pk combination

    Use this only for non product items. For products
    and shop_products use `bump_cache_for_product` and
    `bump_cache_for_shop_product` for those.

    In case you need to use this to product or shop_product
    make sure you also bump related objects like in
    `bump_cache_for_shop_product`.

    :param cls: Class for cached object
    :param pk: pk for cached object
    """
    cache.bump_version("%s-%s" % (_get_namespace_prefix(cls), pk))
Exemplo n.º 21
0
def test_cache_api():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_configuration_cache',
        }
    }):
        cache.init_cache()

        key = "test_prefix:123"
        value = "456"
        cache.set(key, value)
        assert cache.get(key) == value
        cache.bump_version(key)
        assert cache.get(key, default="derp") == "derp"  # version was bumped, so no way this is there
        cache.set(key, value)
        assert cache.get(key) == value
Exemplo n.º 22
0
def test_cache_api():
    with override_settings(CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
            'LOCATION': 'test_configuration_cache',
        }
    }):
        cache.init_cache()

        key = "test_prefix:123"
        value = "456"
        cache.set(key, value)
        assert cache.get(key) == value
        cache.bump_version(key)
        assert cache.get(key, default="derp") == "derp"  # version was bumped, so no way this is there
        cache.set(key, value)
        assert cache.get(key) == value
Exemplo n.º 23
0
def set_current_theme(identifier, shop):
    """
    Activate a theme based on identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :param shop: Shop to fetch the theme settings
    :type shop: shuup.core.models.Shop
    :return: Activated theme
    :rtype: Theme
    """
    cache.bump_version(get_theme_cache_key(shop))
    theme = get_theme_by_identifier(identifier, shop)
    if not theme:
        raise ValueError("Invalid theme identifier")
    theme.set_current()
    cache.set(get_theme_cache_key(shop), theme)
    set_middleware_current_theme(theme)
    return theme
Exemplo n.º 24
0
def set_current_theme(identifier, shop):
    """
    Activate a theme based on identifier.

    :param identifier: Theme identifier
    :type identifier: str
    :param shop: Shop to fetch the theme settings
    :type shop: shuup.core.models.Shop
    :return: Activated theme
    :rtype: Theme
    """
    cache.bump_version(get_theme_cache_key(shop))
    theme = get_theme_by_identifier(identifier, shop)
    if not theme:
        raise ValueError("Invalid theme identifier")
    theme.set_current()
    cache.set(get_theme_cache_key(shop), theme)
    set_middleware_current_theme(theme)
    return theme
Exemplo n.º 25
0
    def form_valid(self, form):
        identifier = form["theme"].cleaned_data["activate"]
        data = {
            "settings": {
               "stylesheet": form["theme"].cleaned_data["selected_style"]
            }
        }
        theme_settings, created = ThemeSettings.objects.get_or_create(
            theme_identifier=identifier,
            shop=get_shop(self.request)
        )
        if created:
            theme_settings.data = data
            theme_settings.save()
        else:
            theme_settings.update_settings(data["settings"])

        set_current_theme(identifier, self.object)
        cache.bump_version(get_theme_cache_key(get_shop(self.request)))
Exemplo n.º 26
0
def set(shop, key, value):
    """
    Set configuration item value for a shop or globally.

    If given `shop` is ``None``, the value of given `key` is set
    globally for all shops.  Otherwise sets a shop specific value which
    overrides the global value in configuration of the specified shop.

    :param shop: Shop to set value for, or None to set a global value
    :type shop: shuup.core.models.Shop|None
    :param key: Name of the key to set
    :type key: str
    :param value: Value to set.  Note: Must be JSON serializable.
    :type value: Any
    """
    ConfigurationItem.objects.update_or_create(
        shop=shop, key=key, defaults={"value": value})
    if shop:
        cache.set(_get_cache_key(shop), None)
    else:
        cache.bump_version(_SHOP_CONF_NAMESPACE)
Exemplo n.º 27
0
def invalidate_context_filter_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    # Let's try to preserve catalog filter cache as long as possible
    cache.bump_version("%s:%s" % (CATALOG_FILTER_CACHE_NAMESPACE, instance.pk))
Exemplo n.º 28
0
def bump_star_rating_cache(product_id):
    cache.bump_version("product_reviews_star_rating_{}".format(product_id))
Exemplo n.º 29
0
 def form_valid(self, form):
     response = super(SnippetEditView, self).form_valid(form)
     shop = get_shop(self.request)
     cache_key = GLOBAL_SNIPPETS_CACHE_KEY.format(shop_id=shop.pk)
     cache.bump_version(cache_key)
     return response
Exemplo n.º 30
0
def invalidate_context_condition_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)
Exemplo n.º 31
0
def invalidate_context_condition_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)
Exemplo n.º 32
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(THEME_CACHE_KEY)
Exemplo n.º 33
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(get_theme_cache_key(get_shop(self.request)))
Exemplo n.º 34
0
def bump_star_rating_cache(vendor_id):
    cache.bump_version("vendor_reviews_star_rating_{}".format(vendor_id))
Exemplo n.º 35
0
 def save(self, *args, **kwargs):
     super(Campaign, self).save(*args, **kwargs)
     cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
     cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)
     cache.bump_version(CATALOG_FILTER_CACHE_NAMESPACE)
Exemplo n.º 36
0
def bump_instance_thumbnail_cache(sender, instance, **kwargs):
    cache_namespace = "thumbnail_{}_{}".format(instance.pk, instance.__class__.__name__)
    cache.bump_version(cache_namespace)
Exemplo n.º 37
0
 def save(self, *args, **kwargs):
     super(Currency, self).save(*args, **kwargs)
     cache.bump_version('currency_precision')
Exemplo n.º 38
0
 def form_valid(self, form):
     response = super(SnippetEditView, self).form_valid(form)
     shop = get_shop(self.request)
     cache_key = GLOBAL_SNIPPETS_CACHE_KEY.format(shop_id=shop.pk)
     cache.bump_version(cache_key)
     return response
Exemplo n.º 39
0
def bump_internal_cache():
    cache.bump_version("_ctx_cache")
Exemplo n.º 40
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(get_theme_cache_key(get_shop(self.request)))
Exemplo n.º 41
0
def set_permissions_for_group(group, permissions):
    group_id = (group if isinstance(group, six.integer_types) else group.pk)
    configuration.set(None, _get_permission_key_for_group(group_id),
                      permissions)
    cache.bump_version(USER_PERMISSIONS_CACHE_NAMESPACE)
Exemplo n.º 42
0
 def save(self, *args, **kwargs):
     super(Campaign, self).save(*args, **kwargs)
     cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
     cache.bump_version(CONTEXT_CONDITION_CACHE_NAMESPACE)
     cache.bump_version(CATALOG_FILTER_CACHE_NAMESPACE)
Exemplo n.º 43
0
 def save(self, *args, **kwargs):
     super(Currency, self).save(*args, **kwargs)
     cache.bump_version('currency_precision')
Exemplo n.º 44
0
 def save_form(self, form):
     super(ThemeConfigDetailView, self).save_form(form)
     cache.bump_version(THEME_CACHE_KEY)
Exemplo n.º 45
0
def bump_sales_unit_cache_signal(*args, **kwargs):
    cache.bump_version("display_unit")
Exemplo n.º 46
0
def invalidate_context_filter_cache(sender, instance, **kwargs):
    cache.bump_version(CAMPAIGNS_CACHE_NAMESPACE)
    # Let's try to preserve catalog filter cache as long as possible
    cache.bump_version("%s:%s" % (CATALOG_FILTER_CACHE_NAMESPACE, instance.pk))
Exemplo n.º 47
0
def bump_internal_cache():
    cache.bump_version("_ctx_cache")
Exemplo n.º 48
0
def bump_sales_unit_cache_signal(*args, **kwargs):
    cache.bump_version("display_unit")
Exemplo n.º 49
0
def bump_star_rating_cache(vendor_id, option_id=None):
    cache.bump_version("vendor_reviews_star_rating_{}_{}".format(
        vendor_id, (option_id or "")))
Exemplo n.º 50
0
def bump_instance_thumbnail_cache(sender, instance, **kwargs):
    cache_namespace = "thumbnail_{}_{}".format(instance.pk,
                                               instance.__class__.__name__)
    cache.bump_version(cache_namespace)
Exemplo n.º 51
0
 def delete(self, request, *args, **kwargs):
     response = super(SnippetDeleteView, self).delete(request, *args, **kwargs)
     shop = get_shop(self.request)
     cache_key = GLOBAL_SNIPPETS_CACHE_KEY.format(shop_id=shop.pk)
     cache.bump_version(cache_key)
     return response