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