shuup.core.utils package

Submodules

shuup.core.utils.context_cache module

shuup.core.utils.context_cache.get_cached_value(identifier, item, context, **kwargs)[source]

Get item from context cache by identifier

Accepts optional kwargs parameter allow_cache which will skip fetching the actual cached object. When allow_cache is set to False only cache key for identifier, item, context combination is returned.

Parameters:
  • identifier (string) – Any
  • item – Any
  • context (dict) – Any
Returns:

Cache key and cached value if allowed

Return type:

tuple(str, object)

shuup.core.utils.context_cache.set_cached_value(key, value, timeout=None)[source]

Set value to context cache

Parameters:
  • key – Unique key formed to the context
  • value – Value to cache
  • timeout (int) – Timeout as seconds
shuup.core.utils.context_cache.bump_cache_for_shop_product(instance, shop=None)[source]

Bump cache for given shop product

Clear cache for shop product, product linked to it and all the children.

Parameters:shop_product (shuup.core.models.ShopProduct) – shop product object or shop product object id
shuup.core.utils.context_cache.bump_cache_for_product(product, shop=None)[source]

Bump cache for product

In case shop is not given all the shop products for the product is bumped.

Parameters:
  • product (shuup.core.models.Product) – product object or product object id or a list of product object id’s
  • shop (shuup.core.models.Shop|None) – shop object
shuup.core.utils.context_cache.bump_cache_for_item_ids(item_ids, namespace, object_class, shop=None)[source]

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.

shop parameter is deprecated and not used

Parameters:ids – list of cached object id’s
shuup.core.utils.context_cache.bump_cache_for_item(item)[source]

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.

Parameters:item – Cached object
shuup.core.utils.context_cache.bump_cache_for_pk(cls, pk)[source]

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.

Parameters:
  • cls – Class for cached object
  • pk – pk for cached object
shuup.core.utils.context_cache.bump_product_signal_handler(sender, instance, **kwargs)[source]

Signal handler for clearing product cache

Parameters:instance (shuup.core.models.Product) – Shuup product
shuup.core.utils.context_cache.bump_shop_product_signal_handler(sender, instance, **kwargs)[source]

Signal handler for clearing shop product cache

Parameters:instance (shuup.core.models.ShopProduct) – Shuup shop product
shuup.core.utils.context_cache.get_cache_key_for_context(identifier, item, context, **kwargs)[source]
shuup.core.utils.context_cache.bump_internal_cache()[source]

shuup.core.utils.db module

shuup.core.utils.db.float_wrap(value, func)[source]
shuup.core.utils.db.extend_sqlite_functions(connection=None, **kwargs)[source]

Extends SQLite with trigonometry functions

shuup.core.utils.form_mixins module

class shuup.core.utils.form_mixins.ProtectedFieldsMixin(**kwargs)[source]

Bases: object

change_protect_field_text = 'This field cannot be changed since it is protected.'
disable_protected_fields()[source]
clean_protected_fields(cleaned_data)[source]

Ignore protected fields (they are set to disabled, so they will not be in the form data).

As a side effect, this removes the fields from changed_data too.

Parameters:cleaned_data (dict) – Cleaned data
Returns:Cleaned data without protected field data
Return type:dict
clean()[source]

shuup.core.utils.formatters module

class shuup.core.utils.formatters.BaseAddressFormatter[source]

Bases: object

address_as_string_list(address, locale=None)[source]
class shuup.core.utils.formatters.DefaultAddressFormatter[source]

Bases: shuup.core.utils.formatters.BaseAddressFormatter

address_as_string_list(address, locale=None)[source]

shuup.core.utils.forms module

class shuup.core.utils.forms.MutableAddressForm(**kwargs)[source]

Bases: django.forms.models.ModelForm

class Meta[source]

Bases: object

model

alias of MutableAddress

fields = ('name', 'name_ext', 'phone', 'email', 'street', 'street2', 'postal_code', 'city', 'region', 'region_code', 'country')
labels = {'region_code': 'Region'}
save(commit=True)[source]
base_fields = OrderedDict([('name', <django.forms.fields.CharField object>), ('name_ext', <django.forms.fields.CharField object>), ('phone', <django.forms.fields.CharField object>), ('email', <django.forms.fields.EmailField object>), ('street', <django.forms.fields.CharField object>), ('street2', <django.forms.fields.CharField object>), ('postal_code', <django.forms.fields.CharField object>), ('city', <django.forms.fields.CharField object>), ('region', <django.forms.fields.CharField object>), ('region_code', <django.forms.fields.CharField object>), ('country', <django_countries.fields.LazyTypedChoiceField object>)])
declared_fields = OrderedDict()
media
class shuup.core.utils.forms.FormInfoMap(form_classes)[source]

Bases: collections.OrderedDict

get_by_object(obj)[source]
get_by_choice_value(choice_value)[source]
get_type_choices()[source]
class shuup.core.utils.forms.FormInfo(form_class)[source]

Bases: object

class shuup.core.utils.forms.RecoverPasswordForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]

Bases: django.forms.forms.Form

token_generator = <django.contrib.auth.tokens.PasswordResetTokenGenerator object>
subject_template_name = 'shuup/user/recover_password_mail_subject.jinja'
email_template_name = 'shuup/user/recover_password_mail_content.jinja'
from_email = None
recover_password_confirm_view_url_name = 'shuup:recover_password_confirm'
clean()[source]
save(request)[source]
process_user(user_to_recover, request)[source]
base_fields = OrderedDict([('username', <django.forms.fields.CharField object>), ('email', <django.forms.fields.EmailField object>)])
declared_fields = OrderedDict([('username', <django.forms.fields.CharField object>), ('email', <django.forms.fields.EmailField object>)])
media

shuup.core.utils.line_unit_mixin module

class shuup.core.utils.line_unit_mixin.LineWithUnit[source]

Bases: object

unit

Unit of this line.

Return type:UnitInterface

shuup.core.utils.maintenance module

shuup.core.utils.maintenance.maintenance_mode_exempt(view_func)[source]

Make view ignore shop maintenance mode

Parameters:view_func – view attached to this decorator
Returns:view added with maintenance_mode_exempt attribute

shuup.core.utils.menu module

class shuup.core.utils.menu.MainMenuUpdater(menu)[source]

Bases: object

To update items add for example updates = {

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/menu.py:docstring of shuup.core.utils.menu.MainMenuUpdater, line 3)

Unexpected indentation.
PRODUCTS_MENU_CATEGORY: [{“identifier”: “subscriptions”, “title”: _(“Subscriptions”)}], ORDERS_MENU_CATEGORY: [{“identifier”: “subscriptions”, “title”: _(“Subscriptions”)}]

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/menu.py:docstring of shuup.core.utils.menu.MainMenuUpdater, line 5)

Block quote ends without a blank line; unexpected unindent.

}

updates = {}
update()[source]

Update the shuup.admin.menu.MAIN_MENU :return:

shuup.core.utils.model_caching_descriptor module

class shuup.core.utils.model_caching_descriptor.ModelCachingDescriptor(name, queryset)[source]

Bases: object

set_id(instance, value)[source]
get_id(instance)[source]
set_object(instance, value)[source]
get_object(instance)[source]

shuup.core.utils.name_mixin module

class shuup.core.utils.name_mixin.NameMixin[source]

Bases: object

split_name
first_name
last_name
full_name

shuup.core.utils.price_cache module

Utilities for caching price info

shuup.core.utils.price_cache.cache_many_price_info(context, item, quantity, prices_infos, **context_args)[source]

Cache a list of PriceInfo

Parameters:context (object|WSGIRequest) – the context should contain at least a shop and a customer property

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/price_cache.py:docstring of shuup.core.utils.price_cache.cache_many_price_info, line 4)

Field list ends without a blank line; unexpected unindent.

:param object item :param float|Decimal quantity :param iterable[PriceInfo] prices_infos

shuup.core.utils.price_cache.cache_price_info(context, item, quantity, price_info, **context_args)[source]

Cache a PriceInfo

Parameters:object|WSGIRequest (context) – the context should contain at least a shop and a customer property

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/price_cache.py:docstring of shuup.core.utils.price_cache.cache_price_info, line 4)

Field list ends without a blank line; unexpected unindent.

:param item any :param quantity float|Decimal :param price_info PriceInfo

shuup.core.utils.price_cache.get_many_cached_price_info(context, item, quantity=1, **context_args)[source]

Get cached prices info list

Parameters:context (object|WSGIRequest) – the context should contain at least a shop and a customer property

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/price_cache.py:docstring of shuup.core.utils.price_cache.get_many_cached_price_info, line 4)

Field list ends without a blank line; unexpected unindent.

:param object item :param float|Decimal quantity

shuup.core.utils.price_cache.get_cached_price_info(context, item, quantity=1, **context_args)[source]

Get a cached price info

Parameters:context (object|WSGIRequest) – the context should contain at least a shop and a customer property

System Message: WARNING/2 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/price_cache.py:docstring of shuup.core.utils.price_cache.get_cached_price_info, line 4)

Field list ends without a blank line; unexpected unindent.

:param object item :param float|Decimal quantity

shuup.core.utils.price_cache.bump_price_info_cache(shop)[source]

Bump the price info cache for the entire shop

Parameters:shop (int|Shop) – the shop to be bump caches
shuup.core.utils.price_cache.bump_all_price_caches(shops=[])[source]

Bump all price info caches for the given shops or all shops

Parameters:shops (list[int|Shop]|None) – the shops list to be bump caches or None to bump all
shuup.core.utils.price_cache.bump_prices_for_product(product_id)[source]
shuup.core.utils.price_cache.bump_prices_for_shop_product(shop_id)[source]

shuup.core.utils.price_display module

Utilities for displaying prices correctly.

Contents:

  • Class PriceDisplayOptions for storing the display options.
  • Helper function render_price_property for rendering prices correctly from Python code.
  • Various filter classes for implementing Jinja2 filters.
shuup.core.utils.price_display.render_price_property(request, item, priceful, property_name='price')[source]

Render price property of a Priceful object.

Return type:str
class shuup.core.utils.price_display.PriceDisplayFilter(name, property_name=None)[source]

Bases: shuup.core.utils.price_display._ContextFilter

class shuup.core.utils.price_display.PricePropertyFilter(name, property_name=None)[source]

Bases: shuup.core.utils.price_display._ContextFilter

class shuup.core.utils.price_display.PricePercentPropertyFilter(name, property_name=None)[source]

Bases: shuup.core.utils.price_display._ContextFilter

class shuup.core.utils.price_display.TotalPriceDisplayFilter(name, property_name=None)[source]

Bases: shuup.core.utils.price_display._ContextFilter

shuup.core.utils.price_display.get_priced_children_for_price_range(request, product, quantity, supplier)[source]
class shuup.core.utils.price_display.PriceRangeDisplayFilter(name, property_name=None)[source]

Bases: shuup.core.utils.price_display._ContextFilter

shuup.core.utils.prices module

shuup.core.utils.prices.convert_taxness(request, item, priceful, with_taxes)[source]

Convert taxness of a priceful object.

Return a Priceful object result satisfying result.price.includes_tax == with_taxes if possible.

When given priceful does not have tax amount and taxes cannot be calculated automatically (should_calculate_taxes_automatically returns false), return the given priceful as is.

Given request is used for constructing a TaxingContext.

Return type:shuup.core.pricing.Priceful
class shuup.core.utils.prices.TaxedPriceInfo(price, base_price, quantity, tax_amount, **kwargs)[source]

Bases: shuup.core.pricing.PriceInfo

shuup.core.utils.product_bought_with_relations module

shuup.core.utils.product_bought_with_relations.add_bought_with_relations_for_product(product_id, max_quantity=10)[source]

Add ProductCrossSell objects with type ProductCrossSellType.BOUGHT_WITH based on other products ordered with product_id. Ordered amount is used as relation weight.

Parameters:
  • product_id (int) – product_id to add relations to
  • max_quantity (int) – maximum amount of relations created

shuup.core.utils.product_caching_object module

class shuup.core.utils.product_caching_object.ProductCachingObject[source]

Bases: object

product
product_id

shuup.core.utils.product_statistics module

shuup.core.utils.product_statistics.get_best_selling_product_info(shop_ids, cutoff_days=30, supplier=None)[source]
shuup.core.utils.product_statistics.get_products_ordered_with(prod, count=20, request=None, language=None)[source]
shuup.core.utils.product_statistics.get_products_by_brand(prod, count=6, request=None, language=None)[source]
shuup.core.utils.product_statistics.get_products_by_same_categories(prod, count=6, request=None, language=None)[source]

shuup.core.utils.product_subscription module

class shuup.core.utils.product_subscription.ProductSubscriptionOption(label: str, value: str, price: typing.Union[shuup.core.pricing.TaxfulPrice, shuup.core.pricing.TaxlessPrice], description: str = None)[source]

Bases: object

label = None
value = None
price = None
description = None
class shuup.core.utils.product_subscription.ProductSubscriptionContext(shop: shuup.core.models.Shop, product: shuup.core.models.Product, supplier: shuup.core.models.Supplier = None, user: django.contrib.auth.models.User = None, **kwargs)[source]

Bases: object

shop = None
product = None
supplier = None
user = None
class shuup.core.utils.product_subscription.BaseProductSubscriptionOptionProvider[source]

Bases: object

classmethod get_subscription_options(context: shuup.core.utils.product_subscription.ProductSubscriptionContext) → typing.Iterable[shuup.core.utils.product_subscription.ProductSubscriptionOption][source]
shuup.core.utils.product_subscription.get_product_subscription_options(context: shuup.core.utils.product_subscription.ProductSubscriptionContext, **kwargs) → typing.Iterable[shuup.core.utils.product_subscription.ProductSubscriptionOption][source]

shuup.core.utils.query module

shuup.core.utils.query.group_by_period(queryset, column, period, **annotate)[source]

Group and annotate given queryset by a given date period.

Parameters:
  • queryset (django.db.QuerySet) – Original queryset
  • column (str) – Column for grouping
  • period (str) – Period for grouping (‘year’, ‘month’, ‘day’)
  • annotate (dict[str,str]) – Dict for annotate()
Returns:

OrderedDict of period -> annotate columns

Return type:

collections.OrderedDict

shuup.core.utils.shops module

shuup.core.utils.shops.get_shop_from_host(host)[source]

Try to find a shop that matches a host e.g: shop.domain.com, domain.com, localhost:8000

:type host str

shuup.core.utils.slugs module

shuup.core.utils.slugs.generate_multilanguage_slugs(object, name_getter, slug_length=128)[source]

shuup.core.utils.static module

shuup.core.utils.static.get_shuup_static_url[source]

path is the static source path, e.g. myapp/styles.css package is the package name to get the version from.

System Message: ERROR/3 (/home/docs/checkouts/readthedocs.org/user_builds/shuup/checkouts/latest/shuup/core/utils/static.py:docstring of shuup.core.utils.static.get_shuup_static_url, line 3)

Unexpected indentation.
If not set, Shuup version is used. You can pass the name if any installed pacakge and use that version as a base.

shuup.core.utils.tax_numbers module

shuup.core.utils.tax_numbers.validate(tax_number)[source]

Validate a tax number.

Parameters:tax_number (str) – Tax number to validate.
Returns:Type identifier of the tax number, if detected. Possible values for now are either “vat” or “unknown”.
Return type:str
Raise:ValidationError if tax number type was detected, but it is somehow malformed.

shuup.core.utils.units module

shuup.core.utils.units.get_shuup_volume_unit()[source]

Return the volume unit that Shuup should use.

Return type:str

shuup.core.utils.users module

shuup.core.utils.users.real_user_or_none(user)[source]

Convert anonymous user to None.

If user is anonymous, return None, otherwise return the user as is.

shuup.core.utils.users.toggle_all_seeing_for_user(user)[source]
shuup.core.utils.users.is_user_all_seeing(user)[source]
shuup.core.utils.users.should_force_anonymous_contact(user)[source]
shuup.core.utils.users.should_force_person_contact(user)[source]
shuup.core.utils.users.force_anonymous_contact_for_user(user, value=True)[source]
shuup.core.utils.users.force_person_contact_for_user(user, value=True)[source]
shuup.core.utils.users.send_user_reset_password_email(user, shop, reset_domain_url, reset_url_name, token_generator=None, subject_template_name=None, email_template_name=None, from_email=None)[source]

shuup.core.utils.vat module

shuup.core.utils.vat.compile_pattern(prefix, pattern)[source]
exception shuup.core.utils.vat.VatValidationError(*args, **kwargs)[source]

Bases: django.core.exceptions.ValidationError

code = None
exception shuup.core.utils.vat.VatCannotIdentifyValidationError(*args, **kwargs)[source]

Bases: shuup.core.utils.vat.VatValidationError

code = 'vat_cannot_identify'
exception shuup.core.utils.vat.VatInvalidValidationError(*args, **kwargs)[source]

Bases: shuup.core.utils.vat.VatValidationError

code = 'vat_invalid'
shuup.core.utils.vat.verify_vat(vat_id, default_prefix='')[source]

Verify an EU VAT ID.

Returns a tuple (prefix, code_parts) – if both are truthy, the validation succeeded. If the prefix part is falsy, then the prefix was unknown and no validation was even attempted. If the prefix part is truthy, then it will contain the country prefix used for validation. The code_parts part can still be falsy, if the validation for the country’s VAT number pattern failed.

Parameters:
  • vat_id (str) – The VAT ID string to validate.
  • default_prefix (str) – The default prefix to assume if none can be parsed.
Returns:

Tuple of (prefix, code_parts)

shuup.core.utils.vat.get_vat_prefix_for_country(iso3166)[source]

Module contents