Record Objects #
A dict-like object for storing record data.
def __init__(data, field_defs, identifier, timezone)
A bunch of side effects happen on initialization:
- timestamps are corrected
Fieldclasses are constructed for each key/value in the record
- the Record is set to
immutable, preventing further updates to record values via
datadict - A single Knack record, such as what is returned from the Knack API or via JSON download in the Knack builder.
field_defslist - A list of
identifierstr or None - The Knack field key which should be used in the instance’s repr. This property is available in the knack object metadata, and is referred to the “Display Field” in the Knack builder under object settings. For some reason, the identifier is not always available in the object’s metadata. If the identifier is
None, “id” will be used.
timezonepytz.timezone - A
pytz.timezoneobject representing the record’s timezone.
Return the field whose key or name matches the client-provided value.
client_keystr - A field key (e.g., “field_99”) or field name.
object- The field’s value (dict, list, str, int, whatever Knack has in store for you.)
def __setitem__(key, value)
Bad things will happen if you re-assign record values to anything other than a field class. This is not immediately obvious, because you can assign values to the record without issue, but some operations will fail after assignment of a non-Field value. e.g., .format() and dict().
All that to say, we set immutable = True after init, and further attempts to setitem will raise a TypeError.
TypeError- Record object does not support item assignment.
def format(keys: Union[list, bool] = True, values: Union[list, bool] = True)
Returns the record as a dict.
keysbool or list, optional - If the keys should be formatted, or a list of field keys specifying the keys to be formatted.
valuesbool or list, optional - If values should be formatted, or a list of field keys specifying the values to be formatted
dict- A dict of the record values with formatted (aka, humaized) keys and/or values.