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.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:
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 RecursionError). 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]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)
shuup.core.fields.utils module
Module contents
- class shuup.core.fields.InternalIdentifierField(**kwargs)[source]
Bases:
CharField
- deconstruct()[source]
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- class shuup.core.fields.FormattedDecimalFormField(*, max_value=None, min_value=None, max_digits=None, decimal_places=None, **kwargs)[source]
Bases:
DecimalField
- MAX_DECIMAL_PLACES_FOR_STEP = 5
- class shuup.core.fields.FormattedDecimalField(verbose_name=None, name=None, max_digits=None, decimal_places=None, **kwargs)[source]
Bases:
DecimalField
DecimalField subclass to display decimal values in non-scientific format.
- class shuup.core.fields.MoneyValueField(**kwargs)[source]
Bases:
FormattedDecimalField
- class shuup.core.fields.QuantityField(**kwargs)[source]
Bases:
FormattedDecimalField
- class shuup.core.fields.MeasurementField(unit, **kwargs)[source]
Bases:
FormattedDecimalField
- deconstruct()[source]
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- class shuup.core.fields.LanguageFieldMixin[source]
Bases:
object
- LANGUAGE_CODES = {'aa', 'ab', 'af', 'agq', 'ak', 'am', 'an', 'ann', 'ar', 'arn', 'as', 'asa', 'ast', 'az', 'ba', 'bal', 'bas', 'be', 'bem', 'bew', 'bez', 'bg', 'bgc', 'bgn', 'bho', 'blo', 'blt', 'bm', 'bn', 'bo', 'br', 'brx', 'bs', 'bss', 'byn', 'ca', 'cad', 'cch', 'ccp', 'ce', 'ceb', 'cgg', 'cho', 'chr', 'cic', 'ckb', 'co', 'cs', 'csw', 'cu', 'cv', 'cy', 'da', 'dav', 'de', 'dje', 'doi', 'dsb', 'dua', 'dv', 'dyo', 'dz', 'ebu', 'ee', 'el', 'en', 'eo', 'es', 'et', 'eu', 'ewo', 'fa', 'fat', 'ff', 'fi', 'fil', 'fo', 'fr', 'frr', 'fur', 'fy', 'ga', 'gaa', 'gd', 'gez', 'gl', 'gn', 'gsw', 'gu', 'guz', 'gv', 'ha', 'haw', 'he', 'hi', 'hnj', 'hr', 'hsb', 'hu', 'hy', 'ia', 'id', 'ie', 'ig', 'ii', 'ike', 'io', 'is', 'it', 'iu', 'ja', 'jbo', 'jgo', 'jmc', 'jv', 'ka', 'kaa', 'kab', 'kaj', 'kam', 'kcg', 'kde', 'kea', 'ken', 'kgp', 'khq', 'ki', 'kk', 'kkj', 'kl', 'kln', 'km', 'kn', 'ko', 'kok', 'kpe', 'ks', 'ksb', 'ksf', 'ksh', 'ku', 'kw', 'kxv', 'ky', 'la', 'lag', 'lb', 'lg', 'lij', 'lkt', 'lmo', 'ln', 'lo', 'lrc', 'lt', 'ltg', 'lu', 'luo', 'luy', 'lv', 'mai', 'mas', 'mdf', 'mer', 'mfe', 'mg', 'mgh', 'mgo', 'mi', 'mic', 'mk', 'ml', 'mn', 'mni', 'moh', 'mr', 'ms', 'mt', 'mua', 'mus', 'my', 'myv', 'mzn', 'naq', 'nb', 'nd', 'nds', 'ne', 'nl', 'nmg', 'nn', 'nnh', 'no', 'nqo', 'nr', 'nso', 'nus', 'nv', 'ny', 'nyn', 'oc', 'om', 'or', 'os', 'osa', 'pa', 'pap', 'pcm', 'pis', 'pl', 'prg', 'ps', 'pt', 'qu', 'quc', 'raj', 'rhg', 'rif', 'rm', 'rn', 'ro', 'rof', 'ru', 'rw', 'rwk', 'sa', 'sah', 'saq', 'sat', 'sbp', 'sc', 'scn', 'sd', 'sdh', 'se', 'seh', 'ses', 'sg', 'shi', 'shn', 'si', 'sid', 'sk', 'sl', 'sma', 'smj', 'smn', 'sms', 'sn', 'so', 'sq', 'sr', 'ss', 'ssy', 'st', 'su', 'sv', 'sw', 'syr', 'szl', 'ta', 'te', 'teo', 'tg', 'th', 'ti', 'tig', 'tk', 'tl', 'tn', 'to', 'tok', 'tpi', 'tr', 'trv', 'trw', 'ts', 'tt', 'tw', 'twq', 'tyv', 'tzm', 'ug', 'uk', 'und', 'ur', 'uz', 'vai', 've', 'vec', 'vi', 'vmw', 'vo', 'vun', 'wa', 'wae', 'wal', 'wbp', 'wo', 'xh', 'xnr', 'xog', 'yav', 'yi', 'yo', 'yrl', 'yue', 'za', 'zgh', 'zh', 'zu'}
- class shuup.core.fields.LanguageField(*args, **kwargs)[source]
Bases:
LanguageFieldMixin
,CharField
- class shuup.core.fields.LanguageFormField(*args, **kwargs)[source]
Bases:
LanguageFieldMixin
,ChoiceField
- 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:
ForeignKey
- allow_unsaved_instance_assignment = True
- class shuup.core.fields.HexColorField(**kwargs)[source]
Bases:
CharField
Supports hexadecimal color values: #ABC, #AABBCC, #001122AA.
- class shuup.core.fields.SeparatedValuesField(*args, **kwargs)[source]
Bases:
TextField
- class shuup.core.fields.PolymorphicJSONField(*args, dump_kwargs=None, load_kwargs=None, **kwargs)[source]
Bases:
JSONField
Use this field when using JSONField inside a polumorphic model. https://github.com/dmkoch/django-jsonfield/pull/193