Core

Core app reference.

Utils

salesman.core.utils.format_price(value: Decimal, context: dict[str, Any] = {}) str[source]

Default price format function. Can be overriden by providing a dotted path to a function in SALESMAN_PRICE_FORMATTER setting.

Parameters:
  • value (Decimal) – Number value to be formatted

  • context (dict, optional) – Format context data. Defaults to {}.

Returns:

Formatted price as a string

Return type:

str

salesman.core.utils.get_salesman_model(name: str) Any[source]

Loads and returns a Salesman model by name. Should be used for accessing all models to allow for swappable models.

Parameters:

name (str) – A camel case Salesman model name

Returns:

Model class

Return type:

type

Serializers

class salesman.core.serializers.PriceField(*args, **kwargs)[source]

Price field used to display formated price whitin a serializer.

to_representation(value: str) str[source]

Transform the outgoing native value into primitive data.

Typing

class salesman.core.typing.Product(*args, **kwargs)[source]

Product protocol that all Salesman product models should implement.

get_price(request: HttpRequest) Decimal[source]

Method that returns product price for the given request.

Parameters:

request (HttpRequest) – Django request

Returns:

Product price

Return type:

Decimal

Utils

salesman.core.utils.format_price(value: Decimal, context: dict[str, Any] = {}) str[source]

Default price format function. Can be overriden by providing a dotted path to a function in SALESMAN_PRICE_FORMATTER setting.

Parameters:
  • value (Decimal) – Number value to be formatted

  • context (dict, optional) – Format context data. Defaults to {}.

Returns:

Formatted price as a string

Return type:

str

salesman.core.utils.get_salesman_model(name: str) Any[source]

Loads and returns a Salesman model by name. Should be used for accessing all models to allow for swappable models.

Parameters:

name (str) – A camel case Salesman model name

Returns:

Model class

Return type:

type