class EntityCollection_v1
Maturity: 33
A collection container which represents a named collections of entities
File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/entity_collection.py
Lines:
17 - 63
17 - 63
Complexity:
moderate
moderate
Purpose
A collection container which represents a named collections of entities
Source Code
class EntityCollection(ClientObjectCollection[T]):
"""A collection container which represents a named collections of entities"""
def __init__(self, context, item_type, resource_path=None, parent=None):
# type: (GraphClient, Type[T], Optional[ResourcePath], Optional[Entity]) -> None
super(EntityCollection, self).__init__(
context, item_type, resource_path, parent
)
def __getitem__(self, key):
# type: (int | str) -> T
"""
:param key: key is used to address an entity by either an index or by identifier
:type key: int or str
"""
if isinstance(key, int):
return super(EntityCollection, self).__getitem__(key)
elif is_string_type(key):
return self.create_typed_object(
resource_path=EntityPath(key, self.resource_path)
)
else:
raise ValueError(
"Invalid key: expected either an entity index [int] or identifier [str]"
)
def add(self, **kwargs):
# type: (Any) -> T
"""Creates an entity and prepares the query"""
return_type = self.create_typed_object(kwargs, ItemPath(self.resource_path))
self.add_child(return_type)
qry = CreateEntityQuery(self, return_type, return_type)
self.context.add_query(qry)
return return_type
def create_typed_object(self, initial_properties=None, resource_path=None):
# type: (Optional[dict], Optional[ResourcePath]) -> T
if resource_path is None:
resource_path = EntityPath(None, self.resource_path)
return super(EntityCollection, self).create_typed_object(
initial_properties, resource_path
)
@property
def context(self):
# type: () -> GraphClient
return self._context
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientObjectCollection[T] | - |
Parameter Details
bases: Parameter of type ClientObjectCollection[T]
Return Value
Returns unspecified type
Class Interface
Methods
__init__(self, context, item_type, resource_path, parent)
Purpose: Internal method: init
Parameters:
context: Parameteritem_type: Parameterresource_path: Parameterparent: Parameter
Returns: None
__getitem__(self, key)
Purpose: :param key: key is used to address an entity by either an index or by identifier :type key: int or str
Parameters:
key: Parameter
Returns: None
add(self)
Purpose: Creates an entity and prepares the query
Returns: None
create_typed_object(self, initial_properties, resource_path)
Purpose: Creates typed
Parameters:
initial_properties: Parameterresource_path: Parameter
Returns: None
context(self)
property
Purpose: Performs context
Returns: None
Required Imports
from typing import TYPE_CHECKING
from typing import Any
from typing import Optional
from typing import Type
from typing import TypeVar
Usage Example
# Example usage:
# result = EntityCollection(bases)
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class EntityCollection 77.9% similar
-
class AppCollection 62.5% similar
-
class FormCollection 60.3% similar
-
class VideoItemCollection 60.1% similar
-
class AttachmentCollection_v1 59.8% similar