class OnenoteEntitySchemaObjectModel
A base class for OneNote entity objects that provides schema-based property access with a focus on creation datetime tracking.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/entity_schema_object_model.py
7 - 27
simple
Purpose
This class serves as a foundational model for OneNote entities, extending OnenoteEntityBaseModel to provide standardized access to common schema properties. It specifically implements the 'createdDateTime' property that tracks when a OneNote entity (like a page or section) was created, ensuring consistent datetime handling across all OneNote entity types. The class uses a property-based approach for accessing entity metadata and provides a customizable property getter mechanism.
Source Code
class OnenoteEntitySchemaObjectModel(OnenoteEntityBaseModel):
"""This is a base type for OneNote entities."""
@property
def created_datetime(self):
# type: () -> Optional[datetime]
"""
The date and time when the page was created. The timestamp represents date and time information using
ISO 8601 format and is always in UTC time. For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z.
"""
return self.properties.get("createdDateTime", datetime.min)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"createdDateTime": self.created_datetime,
}
default_value = property_mapping.get(name, None)
return super(OnenoteEntitySchemaObjectModel, self).get_property(
name, default_value
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
OnenoteEntityBaseModel | - |
Parameter Details
__init__: This class does not define its own __init__ method, so it inherits the constructor from its parent class OnenoteEntityBaseModel. The parent constructor likely accepts parameters for initializing the entity's properties dictionary and other base model attributes.
Return Value
Instantiation returns an OnenoteEntitySchemaObjectModel instance. The created_datetime property returns an Optional[datetime] object representing when the entity was created in UTC (ISO 8601 format), or datetime.min if not set. The get_property method returns the value of the requested property, with type depending on the property name, or the provided default_value if the property doesn't exist.
Class Interface
Methods
@property created_datetime() -> Optional[datetime]
property
Purpose: Returns the creation datetime of the OneNote entity in UTC format
Returns: An Optional[datetime] object representing when the entity was created (ISO 8601 format, UTC), or datetime.min if the property is not set
get_property(name: str, default_value: Any = None) -> Any
Purpose: Retrieves a property value by name, with support for mapped properties and default values
Parameters:
name: The name of the property to retrieve (e.g., 'createdDateTime')default_value: Optional default value to return if the property is not found. If None, the method checks a property_mapping dictionary for known properties before delegating to the parent class
Returns: The value of the requested property. For 'createdDateTime', returns a datetime object. For other properties, returns the value from the parent class's get_property method or the provided default_value
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
properties |
dict | Inherited from parent class. Dictionary storing the entity's properties including 'createdDateTime' and other schema-defined attributes | instance |
Dependencies
datetimetypingoffice365.onenote.entity_base_model
Required Imports
from datetime import datetime
from typing import Optional
from office365.onenote.entity_base_model import OnenoteEntityBaseModel
Usage Example
from datetime import datetime
from typing import Optional
from office365.onenote.entity_base_model import OnenoteEntityBaseModel
from office365.onenote.entity_schema_object_model import OnenoteEntitySchemaObjectModel
# Instantiate the class (assuming parent class accepts properties dict)
entity = OnenoteEntitySchemaObjectModel()
# Access the created datetime property
created_time = entity.created_datetime
if created_time and created_time != datetime.min:
print(f"Entity created at: {created_time.isoformat()}")
# Use the get_property method with default value
created = entity.get_property('createdDateTime')
print(f"Created: {created}")
# Get a property with custom default
custom_prop = entity.get_property('customProperty', 'default_value')
print(f"Custom property: {custom_prop}")
Best Practices
- This is a base class meant to be inherited by specific OneNote entity types (pages, sections, notebooks), not typically instantiated directly
- The created_datetime property returns datetime.min as a fallback when the property is not set, so always check for this sentinel value
- When extending this class, add additional properties following the same pattern: use @property decorator and register them in the get_property method's property_mapping dictionary
- The class assumes that entity properties are stored in a 'properties' dictionary inherited from the parent class
- All datetime values are expected to be in UTC and follow ISO 8601 format
- When calling get_property, the method first checks the property_mapping for known properties before falling back to the parent implementation
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class OnenoteEntityHierarchyModel 81.3% similar
-
class OnenoteEntityBaseModel 78.1% similar
-
class Notebook 67.0% similar
-
class Onenote 66.3% similar
-
class OnenoteResource 58.9% similar