class PersonalizationScope
An enumeration class that defines personalization scope constants for the LimitedWebPartManager object in SharePoint Web Parts.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/webparts/personalization_scope.py
1 - 18
simple
Purpose
This class serves as a constant enumeration to specify the personalization scope when working with SharePoint Web Parts. It defines two scopes: User (0) for user-specific personalization data, and Shared (1) for personalization data that applies to all users. This is used to control how Web Part personalization data is loaded and saved on Web Part Pages.
Source Code
class PersonalizationScope:
"""Specifies the personalization scope for the LimitedWebPartManager object"""
User = 0
"""Personalization data that is user-specific, as well as personalization data that applies to all users,
is loaded for all Web Parts on a Web Part Page that support personalization data. Only personalization data that
is user-specific is saved on the Web Part Page. When referring to the scope associated
with a Web Parts control property, User scope indicates that the property can only load and store data applicable
to all users when running on a page in Shared scope. However, when the property's control is running on a page
in User scope, the property's per-user and all-user data will be loaded and merged. In this case, though,
only per-user data will be saved when a page is running in User scope."""
Shared = 1
"""
Personalization data that applies to all users is loaded for all Web Parts on a Web Part Page and is available
to be saved on the Web Part Page. When referring to the scope associated with a Web Parts control property,
Shared scope indicates that the property normally only allows loading or saving of data associated with all users.
"""
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
bases: This parameter refers to the base classes from which PersonalizationScope inherits. In this implementation, no explicit base classes are defined, so it implicitly inherits from 'object'.
Return Value
Instantiating this class returns a PersonalizationScope object. However, this class is designed to be used as a namespace for constants rather than being instantiated. The class attributes User (int value 0) and Shared (int value 1) are the primary values used in practice.
Class Interface
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
User |
int | Constant value (0) representing user-specific personalization scope. When set, personalization data that is user-specific as well as data for all users is loaded, but only user-specific data is saved. Properties can load and store data for all users when on a Shared scope page, but only per-user data is saved in User scope. | class |
Shared |
int | Constant value (1) representing shared personalization scope for all users. When set, personalization data that applies to all users is loaded and can be saved. Properties in this scope only allow loading or saving of data associated with all users. | class |
Usage Example
# Using PersonalizationScope as an enumeration
from personalization_scope import PersonalizationScope
# Access the User scope constant
user_scope = PersonalizationScope.User
print(user_scope) # Output: 0
# Access the Shared scope constant
shared_scope = PersonalizationScope.Shared
print(shared_scope) # Output: 1
# Typical usage in a function that requires scope specification
def set_webpart_scope(scope):
if scope == PersonalizationScope.User:
print("Setting user-specific personalization")
elif scope == PersonalizationScope.Shared:
print("Setting shared personalization for all users")
set_webpart_scope(PersonalizationScope.User)
set_webpart_scope(PersonalizationScope.Shared)
Best Practices
- This class should not be instantiated; use it as a namespace for accessing the constant values User and Shared
- Always use PersonalizationScope.User or PersonalizationScope.Shared instead of hardcoding integer values 0 or 1 for better code readability and maintainability
- Consider using Python's enum.Enum or enum.IntEnum for a more robust enumeration implementation in modern Python code
- When comparing scope values, use identity comparison (==) with the class attributes rather than comparing raw integer values
- This class is immutable by design - do not attempt to modify the User or Shared class attributes at runtime
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class FeatureDefinitionScope 69.1% similar
-
class ViewScope 68.2% similar
-
class LimitedWebPartManager 66.5% similar
-
class PersonalSiteCreationPriority 59.8% similar
-
class PersonalWeb 59.2% similar