shoop.core.utils package

Submodules

shoop.core.utils.form_mixins module

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

Bases: object

change_protect_field_text = <django.utils.functional.lazy.<locals>.__proxy__ object>
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]

shoop.core.utils.maintenance module

shoop.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

shoop.core.utils.model_caching_descriptor module

class shoop.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]

shoop.core.utils.name_mixin module

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

Bases: object

split_name
first_name
last_name
full_name

shoop.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.
shoop.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 shoop.core.utils.price_display.PriceDisplayFilter(name, property_name=None)[source]

Bases: shoop.core.utils.price_display._ContextFilter

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

Bases: shoop.core.utils.price_display._ContextFilter

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

Bases: shoop.core.utils.price_display._ContextFilter

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

Bases: shoop.core.utils.price_display._ContextFilter

class shoop.core.utils.price_display.PriceRangeDisplayFilter(name, property_name=None)[source]

Bases: shoop.core.utils.price_display._ContextFilter

shoop.core.utils.prices module

shoop.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:shoop.core.pricing.Priceful
class shoop.core.utils.prices.TaxedPriceInfo(price, base_price, quantity, tax_amount, **kwargs)[source]

Bases: shoop.core.pricing.PriceInfo

shoop.core.utils.product_bought_with_relations module

shoop.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

shoop.core.utils.product_caching_object module

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

Bases: object

product
product_id

shoop.core.utils.query module

shoop.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

shoop.core.utils.slugs module

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

shoop.core.utils.tax_numbers module

shoop.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.

shoop.core.utils.users module

shoop.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.

shoop.core.utils.vat module

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

Bases: django.core.exceptions.ValidationError

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

Bases: shoop.core.utils.vat.VatValidationError

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

Bases: shoop.core.utils.vat.VatValidationError

code = 'vat_invalid'
shoop.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)

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

Module contents