xia_engine.fields.ExternalField
- class xia_engine.fields.ExternalField(document_type, field_map: dict, list_length: int = 0, dependent: bool = False, **kwargs)
Bases:
BaseExternalField
The field mapped to other documents
- document_type
member document class
- field_map
mapping current field name and external class field name as current: external
- list_length
0 means don’t show as list. list_length > 1 means show as listing with max length = list_length
- dependent
It will trigger two things: 1. The data validation will check if the external document exists or not. 2. The external data deletion will fail if it detects it still needs to support another document
- __init__(document_type, field_map: dict, list_length: int = 0, dependent: bool = False, **kwargs)
- Parameters
required (bool) – The field is required
default (Any) – Default value of the field
validation (callable) – A custom validation function
value_min (Any) – Minimum accepted value
value_max (Any) – Maximum accepted value
choices (list) – List of accepted value
description (str) – Description of the field
runtime (bool) – value has runtime form
stateful (bool) – value should be store in the database
hidden (bool) – value shouldn’t be shown to the display
sample (Any) – example value of this field (in internal / runtime form)
display (dict) – Define some display related settings (display format, readonly etc…)
Methods
__init__
(document_type, field_map[, ...])- param required
The field is required
from_db
(value, /[, decoder, engine])Value transformation from database form
from_display
(value[, runtime_display])Value transformation from display form to internal form
from_runtime
(runtime_value, /)Value transformation from runtime value to internal form
Get a sample value of a field
get_value
([value, runtime_value, acl])Get runtime value when it is necessary
guess_value
([value])No need to guess value
to_db
(value[, runtime_value, catalog, ...])Value transformation to database form
to_display
(value[, runtime_value, lazy, ...])Value transformation to display form
validate
(value[, runtime_value])No need to validate
Attributes
SAMPLE_DICT
db_form
detail_form
display_form
internal_form
runtime_form
- from_db(value: Any, /, decoder: callable = None, engine=None)
Value transformation from database form
- Parameters
decoder (callable) – Encode the value
value (any) – value to be transformed from database form to internal form
engine (BaseEngine) – Engine to be passed
- Returns
internal value and runtime value tuple
- from_display(value: Any, runtime_display: Any = None, /)
Value transformation from display form to internal form
- Parameters
value (any) – display value to be transformed
runtime_display (any) – display runtime value to be transformed
- from_runtime(runtime_value: Any, /)
Value transformation from runtime value to internal form
- Parameters
runtime_value – runtime value
- get_sample()
Get a sample value of a field
- Returns
sample value
- Return type
object
- get_value(value: Optional[Any] = None, runtime_value: Optional[Any] = None, /, acl=None, **kwargs)
Get runtime value when it is necessary
- Parameters
value (any) – value on internal form. could be None for no-stateful fields
runtime_value (any) – value of runtime value. could be None when the data is not loaded
- guess_value(value: Optional[Any] = None)
No need to guess value
- to_db(value: Any, runtime_value: Any = None, /, catalog: dict = None, encoder: callable = None, ignore_unknown: bool = False, engine=None)
Value transformation to database form
- Parameters
encoder (callable) – Encode the value
runtime_value (any) – runtime value to be transformed
value (any) – value to be transformed from internal form to database form
catalog (dict) – Data catalog to decide if the field will be shown or not
ignore_unknown (bool) – If the unknown field should be ignored
engine (BaseEngine) – Engine to be passed
- to_display(value: Any, runtime_value: Optional[Any] = None, /, lazy: bool = True, catalog: Optional[dict] = None, show_hidden: bool = False, **kwargs)
Value transformation to display form
- Parameters
value (any) – value to be transformed from internal form to database form
runtime_value (any) – value of runtime value. could be None when the data is not loaded
- validate(value: Any, runtime_value: Optional[Any] = None, /)
No need to validate