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. Whenallow_cache
is set to False only cache key for identifier, item, context combination is returned.
- 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
andbump_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
andbump_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
andbump_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.db module
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.'
shuup.core.utils.formatters module
- class shuup.core.utils.formatters.DefaultAddressFormatter[source]
Bases:
BaseAddressFormatter
shuup.core.utils.forms module
- class shuup.core.utils.forms.MutableAddressForm(**kwargs)[source]
Bases:
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]
Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
- base_fields = {'city': <django.forms.fields.CharField object>, 'country': <django_countries.fields.LazyTypedChoiceField object>, 'email': <django.forms.fields.EmailField object>, 'name': <django.forms.fields.CharField object>, 'name_ext': <django.forms.fields.CharField object>, 'phone': <django.forms.fields.CharField object>, 'postal_code': <django.forms.fields.CharField object>, 'region': <django.forms.fields.CharField object>, 'region_code': <django.forms.fields.CharField object>, 'street': <django.forms.fields.CharField object>, 'street2': <django.forms.fields.CharField object>}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- class shuup.core.utils.forms.FormInfoMap(form_classes)[source]
Bases:
OrderedDict
- 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:
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]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- base_fields = {'email': <django.forms.fields.EmailField object>, 'username': <django.forms.fields.CharField object>}
- declared_fields = {'email': <django.forms.fields.EmailField object>, 'username': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.
shuup.core.utils.line_unit_mixin module
shuup.core.utils.maintenance module
shuup.core.utils.model_caching_descriptor module
shuup.core.utils.name_mixin module
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
: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
: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
: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
: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
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:
- class shuup.core.utils.price_display.PriceDisplayFilter(name, property_name=None)[source]
Bases:
_ContextFilter
- class shuup.core.utils.price_display.PricePropertyFilter(name, property_name=None)[source]
Bases:
_ContextFilter
- class shuup.core.utils.price_display.PricePercentPropertyFilter(name, property_name=None)[source]
Bases:
_ContextFilter
- class shuup.core.utils.price_display.TotalPriceDisplayFilter(name, property_name=None)[source]
Bases:
_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
objectresult
satisfyingresult.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 givenpriceful
as is.Given
request
is used for constructing aTaxingContext
.- Return type:
- class shuup.core.utils.prices.TaxedPriceInfo(price, base_price, quantity, tax_amount, **kwargs)[source]
Bases:
PriceInfo
Initialize PriceInfo with prices and other parameters.
Prices can be taxful or taxless, but their types must match.
- Parameters:
price (Price) – Effective price for the specified quantity.
base_price (Price) – Base price for the specified quantity. Discounts are calculated based on this.
quantity (numbers.Number) – Quantity that the given price is for. Unit price is calculated by
discounted_unit_price = price / quantity
. Note: Quantity could be non-integral (i.e. decimal).expires_on (numbers.Number|None) – Unix timestamp, comparable to values returned by
time.time
, determining the point in time when the prices are no longer valid, or None if no expire time is set (which could mean indefinitely, but in reality, it just means undefined).
- __init__(price, base_price, quantity, tax_amount, **kwargs)[source]
Initialize PriceInfo with prices and other parameters.
Prices can be taxful or taxless, but their types must match.
- Parameters:
price (Price) – Effective price for the specified quantity.
base_price (Price) – Base price for the specified quantity. Discounts are calculated based on this.
quantity (numbers.Number) – Quantity that the given price is for. Unit price is calculated by
discounted_unit_price = price / quantity
. Note: Quantity could be non-integral (i.e. decimal).expires_on (numbers.Number|None) – Unix timestamp, comparable to values returned by
time.time
, determining the point in time when the prices are no longer valid, or None if no expire time is set (which could mean indefinitely, but in reality, it just means undefined).
shuup.core.utils.product_bought_with_relations module
shuup.core.utils.product_caching_object module
shuup.core.utils.product_statistics module
- shuup.core.utils.product_statistics.get_best_selling_product_info(shop_ids, cutoff_days=30, supplier=None, orderable_only=True, quantity=100)[source]
- shuup.core.utils.product_statistics.get_products_ordered_with(prod, count=20, request=None, language=None)[source]
shuup.core.utils.product_subscription module
- class shuup.core.utils.product_subscription.ProductSubscriptionOption(label: str, value: str, price: TaxfulPrice | TaxlessPrice, description: str = None)[source]
Bases:
object
- __init__(label: str, value: str, price: TaxfulPrice | TaxlessPrice, description: str = None)[source]
- label = None
- value = None
- price = None
- description = None
- class shuup.core.utils.product_subscription.ProductSubscriptionContext(shop: Shop, product: Product, supplier: Supplier = None, user: User = None, **kwargs)[source]
Bases:
object
- __init__(shop: Shop, product: Product, supplier: Supplier = None, user: User = None, **kwargs)[source]
- shop = None
- product = None
- supplier = None
- user = None
- class shuup.core.utils.product_subscription.BaseProductSubscriptionOptionProvider[source]
Bases:
object
- classmethod get_subscription_options(context: ProductSubscriptionContext) Iterable[ProductSubscriptionOption] [source]
- shuup.core.utils.product_subscription.get_product_subscription_options(context: ProductSubscriptionContext, **kwargs) Iterable[ProductSubscriptionOption] [source]
shuup.core.utils.query module
shuup.core.utils.shops module
shuup.core.utils.slugs module
shuup.core.utils.static module
shuup.core.utils.tax_numbers module
shuup.core.utils.units module
shuup.core.utils.users module
shuup.core.utils.vat module
- exception shuup.core.utils.vat.VatValidationError(*args, **kwargs)[source]
Bases:
ValidationError
The
message
argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. What we define as an “error” can be either a simple string or an instance of ValidationError with its message attribute set, and what we define as list or dictionary can be an actuallist
ordict
or an instance of ValidationError with itserror_list
orerror_dict
attribute set.- code = None
- __init__(*args, **kwargs)[source]
The
message
argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. What we define as an “error” can be either a simple string or an instance of ValidationError with its message attribute set, and what we define as list or dictionary can be an actuallist
ordict
or an instance of ValidationError with itserror_list
orerror_dict
attribute set.
- exception shuup.core.utils.vat.VatCannotIdentifyValidationError(*args, **kwargs)[source]
Bases:
VatValidationError
The
message
argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. What we define as an “error” can be either a simple string or an instance of ValidationError with its message attribute set, and what we define as list or dictionary can be an actuallist
ordict
or an instance of ValidationError with itserror_list
orerror_dict
attribute set.- code = 'vat_cannot_identify'
- exception shuup.core.utils.vat.VatInvalidValidationError(*args, **kwargs)[source]
Bases:
VatValidationError
The
message
argument can be a single error, a list of errors, or a dictionary that maps field names to lists of errors. What we define as an “error” can be either a simple string or an instance of ValidationError with its message attribute set, and what we define as list or dictionary can be an actuallist
ordict
or an instance of ValidationError with itserror_list
orerror_dict
attribute set.- 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.