🔍 Code Extractor

class OnenoteEntityHierarchyModel

Maturity: 36

A model class representing OneNote entities with hierarchical properties such as notebooks, sections, and pages, providing access to display name, creation/modification metadata, and identity information.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/entity_hierarchy_model.py
Lines:
7 - 39
Complexity:
simple

Purpose

This class extends OnenoteEntitySchemaObjectModel to provide a common interface for OneNote hierarchical entities (notebooks, sections, pages). It encapsulates metadata about entity creation, modification, and display properties. The class provides read-only access to identity information (who created/modified the entity) and timestamps, making it suitable for tracking entity lifecycle and ownership in OneNote operations.

Source Code

class OnenoteEntityHierarchyModel(OnenoteEntitySchemaObjectModel):
    @property
    def display_name(self):
        # type: () -> Optional[str]
        """The name of the section."""
        return self.properties.get("displayName", None)

    @property
    def created_by(self):
        # type: () -> IdentitySet
        """Identity of the user, device, and application which created the item. Read-only."""
        return self.properties.get("createdBy", IdentitySet())

    @property
    def last_modified_by(self):
        """Identity of the user, device, and application which created the item. Read-only."""
        return self.properties.get("lastModifiedBy", IdentitySet())

    @property
    def last_modified_datetime(self):
        """Gets date and time the item was last modified."""
        return self.properties.get("lastModifiedDateTime", None)

    def get_property(self, name, default_value=None):
        if default_value is None:
            property_mapping = {
                "createdBy": self.created_by,
                "lastModifiedBy": self.last_modified_by,
            }
            default_value = property_mapping.get(name, None)
        return super(OnenoteEntityHierarchyModel, self).get_property(
            name, default_value
        )

Parameters

Name Type Default Kind
bases OnenoteEntitySchemaObjectModel -

Parameter Details

bases: Inherits from OnenoteEntitySchemaObjectModel, which provides the base properties dictionary and schema object functionality for OneNote entities

Return Value

Instantiation returns an OnenoteEntityHierarchyModel object that provides property-based access to OneNote entity metadata. Properties return specific types: display_name returns Optional[str], created_by and last_modified_by return IdentitySet objects, last_modified_datetime returns a datetime value or None, and get_property returns the requested property value with optional default.

Class Interface

Methods

@property display_name() -> Optional[str] property

Purpose: Returns the display name of the OneNote entity (section, notebook, or page)

Returns: Optional string containing the display name, or None if not set

@property created_by() -> IdentitySet property

Purpose: Returns identity information about who created the entity

Returns: IdentitySet object containing user, device, and application identity information of the creator. Returns empty IdentitySet if not available.

@property last_modified_by() -> IdentitySet property

Purpose: Returns identity information about who last modified the entity

Returns: IdentitySet object containing user, device, and application identity information of the last modifier. Returns empty IdentitySet if not available.

@property last_modified_datetime() -> Any property

Purpose: Returns the date and time when the entity was last modified

Returns: Datetime value representing when the entity was last modified, or None if not available

get_property(name: str, default_value: Any = None) -> Any

Purpose: Retrieves a property value by name with special handling for identity properties and custom default values

Parameters:

  • name: The name of the property to retrieve (e.g., 'displayName', 'createdBy', 'lastModifiedBy')
  • default_value: Optional default value to return if property is not found. If None, special defaults are used for 'createdBy' and 'lastModifiedBy' (returns IdentitySet objects)

Returns: The property value if found, or the default_value. For 'createdBy' and 'lastModifiedBy' without explicit defaults, returns the corresponding IdentitySet property value

Attributes

Name Type Description Scope
properties dict Inherited dictionary from parent class that stores all entity properties including displayName, createdBy, lastModifiedBy, and lastModifiedDateTime instance

Dependencies

  • typing
  • office365.directory.permissions.identity_set
  • office365.onenote.entity_schema_object_model

Required Imports

from typing import Optional
from office365.directory.permissions.identity_set import IdentitySet
from office365.onenote.entity_schema_object_model import OnenoteEntitySchemaObjectModel

Usage Example

# Assuming you have a OneNote entity data dictionary
from office365.onenote.entity_hierarchy_model import OnenoteEntityHierarchyModel
from office365.directory.permissions.identity_set import IdentitySet

# Create an instance (typically done internally by the SDK)
entity = OnenoteEntityHierarchyModel()

# Access properties
name = entity.display_name  # Get the display name
creator = entity.created_by  # Get IdentitySet of creator
modifier = entity.last_modified_by  # Get IdentitySet of last modifier
last_modified = entity.last_modified_datetime  # Get last modification timestamp

# Use get_property method for flexible property access
created_by_info = entity.get_property('createdBy')  # Returns IdentitySet
custom_prop = entity.get_property('customProperty', 'default_value')  # With default

Best Practices

  • This class is designed for read-only access to OneNote entity metadata; properties should not be modified directly
  • The class relies on a properties dictionary inherited from the parent class; ensure this is properly initialized before accessing properties
  • When using get_property, be aware that 'createdBy' and 'lastModifiedBy' have special handling that returns IdentitySet objects by default
  • All identity-related properties (created_by, last_modified_by) return IdentitySet objects, which may be empty if not populated
  • The display_name property may return None if not set in the underlying properties dictionary
  • This class is typically instantiated by the Office365 SDK when fetching OneNote entities, not manually by end users
  • Always check for None values when accessing optional properties like display_name and last_modified_datetime

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class OnenoteEntityBaseModel 82.8% similar

    OnenoteEntityBaseModel is a base class for OneNote entities that inherits from Entity. It serves as a foundational type for all OneNote-related entity models in the Office365 SDK.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/entity_base_model.py
  • class OnenoteEntitySchemaObjectModel 81.3% similar

    A base class for OneNote entity objects that provides schema-based property access with a focus on creation datetime tracking.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/entity_schema_object_model.py
  • class Notebook 80.0% similar

    Represents a OneNote notebook entity with access to its sections and section groups, providing a hierarchical structure for organizing OneNote content.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/notebooks/notebook.py
  • class Onenote 71.4% similar

    The Onenote class serves as the entry point for accessing Microsoft OneNote resources through the Microsoft Graph API, providing access to notebooks, pages, sections, and other OneNote entities.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/onenote.py
  • class SectionGroup 70.0% similar

    Represents a section group in a OneNote notebook that can contain both sections and nested section groups, providing hierarchical organization of OneNote content.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/onenote/sectiongroups/section_group.py
← Back to Browse