viktor.api
Warning
There is an improved API module, with easier methods and classes. Please use the viktor.api_v1
module instead.
API
Resource
- class
viktor.api.
Resource
(headers, host, resource_id=None)¶ -
-
resource_name
: Optional[str] = None¶
-
headers
= None¶
-
host
= None¶
-
id
= None¶
- abstract
list
()¶ - Return type
List
[dict
]
- abstract
get
()¶ - Return type
dict
-
create
(data)¶ Creates a Resource object.
- Parameters
data (
Any
) – parameter set.- Return type
dict
-
post
(data)¶ - Parameters
data (
Any
) – the content of the object- Return type
dict
-
update_properties
(new_properties)¶ Update the properties of an entity.
Example:
entity.update_properties({ "tab_1": { "section_1": { "numberfield_1": None, } } })
- Parameters
new_properties (
Union
[Munch
,dict
]) – a dictionary containing the properties that should be added to the already existing properties. Properties which were already present will be updated.- Return type
dict
- Returns
the server object with the updated properties
-
post_properties
(new_properties)¶ Post properties on an entity.
Example:
entity.post_properties({ "tab_1": { "section_1": { "numberfield_1": None, } } })
- Parameters
new_properties (
Union
[Munch
,dict
]) – a properties dictionary that must replace the already existing properties dictionary.- Return type
dict
- Returns
the server object with the new properties
-
delete
()¶ Delete the object
- Return type
None
-
Entity
- class
viktor.api.
Entity
(headers, host, resource_id=None)¶ Bases:
viktor.api.Resource
-
resource_name
: Optional[str] = 'entities'¶
-
list
()¶ - Return type
List
[dict
]- Returns
A list of the entities
-
get
()¶ - Return type
dict
- Returns
A dict with the entity content
-
children
(include_deleted=False)¶ - Return type
List
[dict
]- Returns
a list of the children of an entity, this is a list of dicts
-
root_entities
(include_deleted=False)¶ - Return type
List
[dict
]- Returns
the list of children of the root entity (the ones that appear in the side menu)
-
child_ids
(include_deleted=False)¶ - Return type
List
[int
]- Returns
a list of the ids of the children of an entity, this is a list of integers
-
create_child
(child_entity)¶ - Parameters
child_entity (
Union
[Munch
,dict
]) – an object containing the properties of the new child, this must at least include the entity_type and properties- Return type
Any
- Returns
the object we got back from the server, this contains for example the id of the new object
-
parents
()¶ - Return type
List
[dict
]- Returns
a list of the parents of an entity, a list of dicts
-
parent_ids
()¶ - Return type
List
[int
]- Returns
a list of integers of the parents
-
revisions
()¶ - Return type
List
[dict
]- Returns
a list of the revisions of an entity, a list of dicts
-
download
(encoding: str) → str¶ -
download
(encoding: None = None) → bytes Download file. If encoding is specified decoding bytes accordingly.
- Return type
Union
[bytes
,str
]- Returns
string if encoding is specified, e.g. entity.download(encoding=’utf-8’)
bytes otherwise, e.g. entity.download()
-
EntityType
- class
viktor.api.
EntityType
(headers, host, resource_id=None)¶ Bases:
viktor.api.Resource
-
resource_name
: Optional[str] = 'entity_types'¶
-
list
()¶ - Return type
List
[dict
]- Returns
A list of the entity types
-
get
()¶ - Return type
dict
- Returns
A dict with the entity type content
-
child_types
()¶ - Return type
List
[dict
]- Returns
a list of the child types of an entity type, this is a list of dicts
-
entities
(include_deleted=False)¶ - Return type
List
[dict
]- Returns
a list of all entities of an entity type, this is a list of dicts
-
find_by_name
(name)¶ - Return type
dict
-
get_database_value_from_entity_id
-
viktor.api.
get_database_value_from_entity_id
(entity)¶ Returns the database value of a given entity in the following format:
>>> entity = { ... 'id': 123, ... 'name': 'entity_name', ... } >>> get_database_value_from_entity_id(entity) 'entity_123'
If no ‘id’ key is found, None is returned.
- Return type
Optional
[str
]
get_entity_id_from_database_value
-
viktor.api.
get_entity_id_from_database_value
(value)¶ Returns the entity id from its database value as integer:
>>> db_val = 'entity_123' >>> get_entity_id_from_database_value(db_val) 123
- Return type
Optional
[int
]
get_entity_option_list_for_designer
-
viktor.api.
get_entity_option_list_for_designer
(entities)¶ Returns a list of option list elements from a list of entities (dictionaries). This option list can directly be used in the parametrization, and has the following format:
option_list = [ OptionListElement(value='entity_123', label='entity_name'), .. ]
- Return type
List
[OptionListElement
]