shuup.core.fields package

Submodules

shuup.core.fields.tagged_json module

“Tagged JSON” encoder/decoder.

Objects that are normally not unambiguously representable via JSON are encoded into special objects of the form {tag: val}; the encoding and decoding process can be customized however necessary.

shuup.core.fields.tagged_json.isoformat(obj)[source]
shuup.core.fields.tagged_json.encode_enum(enum_val)[source]
shuup.core.fields.tagged_json.decode_enum(val)[source]
class shuup.core.fields.tagged_json.TagRegistry[source]

Bases: object

register(tag, classes, encoder=<class 'str'>, decoder=None)[source]
encode(obj, default)[source]
decode(obj)[source]
shuup.core.fields.tagged_json.tag_registry = <shuup.core.fields.tagged_json.TagRegistry object>

The default tag registry.

class shuup.core.fields.tagged_json.TaggedJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: jsonfield.encoder.JSONEncoder

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

registry = <shuup.core.fields.tagged_json.TagRegistry object>
default(obj)[source]

shuup.core.fields.utils module

shuup.core.fields.utils.ensure_decimal_places(value)[source]

Module contents

class shuup.core.fields.InternalIdentifierField(**kwargs)[source]

Bases: django.db.models.fields.CharField

get_prep_value(value)[source]
deconstruct()[source]
class shuup.core.fields.CurrencyField(**kwargs)[source]

Bases: django.db.models.fields.CharField

class shuup.core.fields.FormattedDecimalFormField(*, max_value=None, min_value=None, max_digits=None, decimal_places=None, **kwargs)[source]

Bases: django.forms.fields.DecimalField

MAX_DECIMAL_PLACES_FOR_STEP = 5
widget_attrs(widget)[source]
class shuup.core.fields.FormattedDecimalField(verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs)[source]

Bases: django.db.models.fields.DecimalField

DecimalField subclass to display decimal values in non-scientific format.

value_from_object(obj)[source]
format_decimal(value, max_digits=100, exponent_limit=100)[source]
formfield(**kwargs)[source]
class shuup.core.fields.MoneyValueField(**kwargs)[source]

Bases: shuup.core.fields.FormattedDecimalField

class shuup.core.fields.QuantityField(**kwargs)[source]

Bases: shuup.core.fields.FormattedDecimalField

class shuup.core.fields.MeasurementField(unit, **kwargs)[source]

Bases: shuup.core.fields.FormattedDecimalField

deconstruct()[source]
class shuup.core.fields.LanguageFieldMixin[source]

Bases: object

LANGUAGE_CODES = {'rwk', 'mzn', 'und', 'et', 'luo', 'nl', 'prg', 'ug', 'eu', 'dua', 'de', 'hr', 'ha', 'as', 'bs', 'el', 'te', 'ast', 'fi', 'ff', 'om', 'ii', 'sah', 'lv', 'tk', 'sbp', 'uk', 'hi', 'yi', 'ksh', 'twq', 'xog', 'nus', 'sk', 'hsb', 'mfe', 'tw', 'vai', 'mt', 'kn', 'jmc', 'rof', 'pl', 'kl', 'ne', 'ti', 'se', 'qu', 'he', 'eo', 'brx', 'gv', 'nyn', 'bn', 'ewo', 'saq', 'es', 'ce', 'lg', 'mr', 'pa', 'gd', 'root', 'it', 'cgg', 'zu', 'id', 'sr', 'nb', 'uz', 'ko', 'ln', 'agq', 'smn', 'bo', 'sw', 'sq', 'seh', 'dje', 'vun', 'hu', 'hy', 'sv', 'ky', 'guz', 'kw', 'nd', 'bm', 'ka', 'rw', 'ca', 'ar', 'da', 'af', 'kab', 'lo', 'os', 'my', 'fat', 'nn', 'yue', 'ur', 'wae', 'haw', 'kk', 'pt', 'fo', 'ga', 'km', 'th', 'kkj', 'tr', 'lrc', 'be', 'lag', 'bas', 'ak', 'gl', 'fil', 'ki', 'yav', 'dav', 'gsw', 'chr', 'ta', 'is', 'to', 'lu', 'khq', 'dz', 'ckb', 'az', 'kde', 'zgh', 'naq', 'ebu', 'jgo', 'tzm', 'br', 'kam', 'mer', 'asa', 'nmg', 'lkt', 'gu', 'cu', 'rn', 'cs', 'mgo', 'lt', 'mg', 'dyo', 'ro', 'kok', 'vi', 'bem', 'bg', 'ps', 'sn', 'shi', 'luy', 'ee', 'no', 'sg', 'ru', 'ms', 'mn', 'dsb', 'ksf', 'si', 'teo', 'mas', 'ja', 'mua', 'so', 'ig', 'zh', 'ks', 'kln', 'fa', 'vo', 'yo', 'tl', 'mk', 'ksb', 'sl', 'kea', 'fy', 'ml', 'bez', 'lb', 'en', 'am', 'or', 'fr', 'nnh', 'rm', 'cy', 'mgh', 'fur', 'ses'}
class shuup.core.fields.LanguageField(*args, **kwargs)[source]

Bases: shuup.core.fields.LanguageFieldMixin, django.db.models.fields.CharField

get_choices(include_blank=True, blank_choice=[('', '---------')])[source]
class shuup.core.fields.LanguageFormField(*args, **kwargs)[source]

Bases: shuup.core.fields.LanguageFieldMixin, django.forms.fields.ChoiceField

get_choices(include_blank=True, blank_choice=[('', '---------')])[source]
class shuup.core.fields.UnsavedForeignKey(to, on_delete, related_name=None, related_query_name=None, limit_choices_to=None, parent_link=False, to_field=None, db_constraint=True, **kwargs)[source]

Bases: django.db.models.fields.related.ForeignKey

allow_unsaved_instance_assignment = True
class shuup.core.fields.TaggedJSONField(*args, **kwargs)[source]

Bases: jsonfield.fields.JSONField

contribute_to_class(cls, name)
class shuup.core.fields.HexColorField(**kwargs)[source]

Bases: django.db.models.fields.CharField

Supports hexadecimal color values: #ABC, #AABBCC, #001122AA.

class shuup.core.fields.SeparatedValuesField(*args, **kwargs)[source]

Bases: django.db.models.fields.TextField

https://stackoverflow.com/questions/1110153/what-is-the-most-efficient-way-to-store-a-list-in-the-django-models

from_db_value(value, expression, connection)[source]
get_db_prep_value(value, connection, prepared=False)[source]
value_to_string(obj)[source]
shuup.core.fields.polymorphic_has_pk(obj)[source]
class shuup.core.fields.PolymorphicJSONField(*args, **kwargs)[source]

Bases: jsonfield.fields.JSONField

Use this field when using JSONField inside a polumorphic model. https://github.com/dmkoch/django-jsonfield/pull/193

pre_init(value, obj)[source]
contribute_to_class(cls, name)