Skip to content

Commit

Permalink
taxonomy namespace & typings enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Nov 25, 2023
1 parent b9d91e0 commit c552771
Show file tree
Hide file tree
Showing 45 changed files with 211 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Get term set by name
Get term sets in Group
"""

from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password

client = GraphClient(acquire_token_by_username_password)
term_store = client.sites.root.term_store
group = term_store.groups.get_by_name("Geography").get().execute_query()
term_set = group.sets.get_by_name("Locations").get().execute_query()
print(term_set.id)
sets = term_store.groups.get_by_name("Geography").sets.get().execute_query()
# term_set = group.sets.get_by_name("Locations").get().execute_query()
for ts in sets:
print(ts)
4 changes: 2 additions & 2 deletions examples/sharepoint/features/ensure_activated.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests import test_client_credentials, test_site_url

ctx = ClientContext(test_site_url).with_credentials(test_client_credentials)
f = ctx.site.features.add(
feature = ctx.site.features.add(
KnownFeaturesList.ContentTypeHub, False, FeatureDefinitionScope.Farm, True
).execute_query()
print("Feature {0} has been activated.", f.display_name)
print("Feature {0} has been activated.", feature.display_name)
34 changes: 32 additions & 2 deletions examples/sharepoint/folders/get_system_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,44 @@

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
list_title = "Docs"

folder_items = (
ctx.web.lists.get_by_title(list_title)
.items.filter("FSObjType eq 1")
.select(
[
"FSObjType",
"Author/Id",
"Author/Title",
"Author/Name",
"Editor/Id",
"Editor/Title",
"Editor/Name",
]
)
.expand(["Author", "Editor"])
.get()
.execute_query()
)

folder_path = "Archive" # folder relative path
folder_item = (
ctx.web.lists.get_by_title(list_title)
.get_item_by_url(folder_path)
.select(["Author/Title"])
.expand(["Author"])
.select(
[
"Author/Id",
"Author/Title",
"Author/Name",
"Editor/Id",
"Editor/Title",
"Editor/Name",
]
)
.expand(["Author", "Editor"])
.get()
.execute_query()
)

print(folder_item.properties.get("Author"))
print(folder_item.properties.get("Editor"))
21 changes: 21 additions & 0 deletions examples/sharepoint/search/search_site_only.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Search for document files within a specific site
Path managed property is provided to limit search scope
https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview
"""

from office365.sharepoint.client_context import ClientContext
from tests import (
test_site_url,
test_team_site_url,
test_user_credentials,
)

ctx = ClientContext(test_site_url).with_credentials(test_user_credentials)

result = ctx.search.post_query(
"Path={0}/*".format(test_team_site_url), row_limit=10
).execute_query()
for row in result.value.PrimaryQueryResult.RelevantResults.Table.Rows:
print("{0}".format(row.Cells["Path"]))
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Retrieves site users
"""

from office365.sharepoint.client_context import ClientContext
Expand Down
32 changes: 12 additions & 20 deletions office365/base_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def created_by(self):

@property
def created_by_user(self):
"""
Identity of the user who created the item
"""
"""Identity of the user who created the item"""
from office365.directory.users.user import User

return self.properties.get(
Expand All @@ -37,14 +35,13 @@ def created_by_user(self):

@property
def last_modified_by(self):
# type: () -> IdentitySet
"""Identity of the user, device, and application which last modified the item."""
return self.properties.get("lastModifiedBy", IdentitySet())

@property
def last_modified_by_user(self):
"""
Identity of the user who last modified the item.
"""
"""Identity of the user who last modified the item."""
from office365.directory.users.user import User

return self.properties.get(
Expand All @@ -54,11 +51,13 @@ def last_modified_by_user(self):

@property
def created_datetime(self):
# type: () -> Optional[datetime]
"""Gets date and time of item creation."""
return self.properties.get("createdDateTime", datetime.min)

@property
def last_modified_datetime(self):
# type: () -> Optional[datetime]
"""Gets date and time the item was last modified."""
return self.properties.get("lastModifiedDateTime", datetime.min)

Expand All @@ -70,39 +69,32 @@ def name(self):

@name.setter
def name(self, value):
"""
Sets the name of the item.
"""
# type: (str) -> None
"""Sets the name of the item."""
self.set_property("name", value)

@property
def description(self):
# type: () -> Optional[str]
"""
Provides a user-visible description of the item.
"""
"""Provides a user-visible description of the item."""
return self.properties.get("description", None)

@description.setter
def description(self, value):
# type: (str) -> None
self.set_property("description", value)

@property
def web_url(self):
# type: () -> Optional[str]
"""
URL that displays the resource in the browser
"""
"""URL that displays the resource in the browser"""
return self.properties.get("webUrl", None)

@property
def parent_reference(self):
# type: () -> ItemReference
"""Parent information, if the item has a parent."""
return self.properties.get("parentReference", ItemReference())

@parent_reference.setter
def parent_reference(self, value):
self.set_property("parentReference", value, False)
return self.properties.setdefault("parentReference", ItemReference())

def get_property(self, name, default_value=None):
if default_value is None:
Expand Down
17 changes: 14 additions & 3 deletions office365/communications/presences/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from office365.communications.presences.status_message import PresenceStatusMessage
from office365.entity import Entity
from office365.outlook.calendar.dateTimeTimeZone import DateTimeTimeZone
from office365.outlook.mail.item_body import ItemBody
from office365.runtime.queries.service_operation import ServiceOperationQuery

Expand Down Expand Up @@ -52,12 +53,22 @@ def set_presence(
self.context.add_query(qry)
return self

def set_status_message(self, message):
def set_status_message(self, message, expiry=None):
"""
Set a presence status message for a user. An optional expiration date and time can be supplied.
:param str message: Status message item.
:param str or ItemBody message: Status message item.
:param datetime.datetime expiry: Time in which the status message expires. If not provided, the status message
doesn't expire.
"""
payload = {"statusMessage": PresenceStatusMessage(message=ItemBody(message))}
if not isinstance(message, ItemBody):
message = ItemBody(message)
if expiry:
expiry = DateTimeTimeZone.parse(expiry)
payload = {
"statusMessage": PresenceStatusMessage(
message=message, expiry_datetime=expiry
)
}
qry = ServiceOperationQuery(self, "setStatusMessage", None, payload)
self.context.add_query(qry)
return self
Expand Down
4 changes: 1 addition & 3 deletions office365/entity_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def __getitem__(self, key):

def add(self, **kwargs):
# type: (Any) -> T
"""
Creates an entity and prepares the query
"""
"""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)
Expand Down
7 changes: 4 additions & 3 deletions office365/onedrive/analytics/item_activity_stat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from typing import Optional

from office365.entity import Entity
from office365.entity_collection import EntityCollection
Expand Down Expand Up @@ -38,9 +39,8 @@ def end_datetime(self):

@property
def is_trending(self):
"""Indicates whether the item is trending.
:rtype: bool or None
"""
# type: () -> Optional[bool]
"""Indicates whether the item is trending."""
return self.properties.get("isTrending", None)

@property
Expand All @@ -55,6 +55,7 @@ def start_datetime(self):

@property
def activities(self):
# type: () -> EntityCollection[ItemActivity]
"""Exposes the itemActivities represented in this itemActivityStat resource."""
return self.properties.get(
"activities",
Expand Down
4 changes: 1 addition & 3 deletions office365/onedrive/documentsets/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def created_by(self):
@property
def created_datetime(self):
# type: () -> datetime.datetime
"""
Date and time when this version was created.
"""
"""Date and time when this version was created."""
return self.properties("createdDateTime", datetime.datetime.min)

@property
Expand Down
2 changes: 2 additions & 0 deletions office365/onedrive/listitems/list_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def drive_item(self):

@property
def content_type(self):
# type: () -> ContentTypeInfo
"""The content type of this list item"""
return self.properties.get("contentType", ContentTypeInfo())

Expand All @@ -73,6 +74,7 @@ def analytics(self):

@property
def document_set_versions(self):
# type: () -> EntityCollection[DocumentSetVersion]
"""Version information for a document set version created by a user."""
return self.properties.get(
"documentSetVersions",
Expand Down
1 change: 1 addition & 0 deletions office365/onedrive/sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Sharepoint(Entity):

@property
def settings(self):
# type: () -> SharepointSettings
"""Represents the tenant-level settings for SharePoint and OneDrive."""
return self.properties.get(
"settings",
Expand Down
6 changes: 2 additions & 4 deletions office365/onedrive/shares/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ def __init__(self, context, resource_path=None):
super(SharesCollection, self).__init__(context, SharedDriveItem, resource_path)

def by_url(self, url):
"""
Address shared item by absolute url
:type url: str
"""
# type: (str) -> SharedDriveItem
"""Address shared item by absolute url"""
return SharedDriveItem(self.context, SharedPath(url, self.resource_path))
8 changes: 8 additions & 0 deletions office365/onedrive/termstore/groups/group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.entity import Entity
from office365.onedrive.termstore.sets.collection import SetCollection
from office365.runtime.paths.resource_path import ResourcePath
Expand All @@ -6,18 +8,24 @@
class Group(Entity):
"""Term Group"""

def __str__(self):
return self.display_name

@property
def display_name(self):
# type: () -> Optional[str]
"""Name of the group."""
return self.properties.get("displayName", None)

@property
def parent_site_id(self):
# type: () -> Optional[str]
"""ID of the parent site of this group."""
return self.properties.get("parentSiteId", None)

@property
def sets(self):
# type: () -> SetCollection
"""Collection of all sets available in the term store."""
return self.properties.get(
"sets",
Expand Down
1 change: 1 addition & 0 deletions office365/onedrive/termstore/sets/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, context, resource_path=None, parent_group=None):
self._parent_group = parent_group

def get_by_name(self, name):
# type: (str) -> Set
"""Returns the TermSet specified by its name."""
return self.single("displayName eq '{0}'".format(name))

Expand Down
5 changes: 5 additions & 0 deletions office365/onedrive/termstore/sets/name.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from office365.runtime.client_value import ClientValue


Expand All @@ -15,3 +17,6 @@ def __init__(self, name=None, language_tag="en-US"):
super(LocalizedName, self).__init__()
self.name = name
self.languageTag = language_tag

def __repr__(self):
return json.dumps(self.to_json())
7 changes: 7 additions & 0 deletions office365/onedrive/termstore/sets/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class Set(Entity):
terms. A group can contain multiple sets.
"""

def __repr__(self):
return repr(self.localized_names)

@property
def children(self):
# type: () -> TermCollection
"""Children terms of set in term store."""
return self.properties.get(
"children",
Expand All @@ -28,6 +32,7 @@ def children(self):

@property
def localized_names(self):
# type: () -> ClientValueCollection[LocalizedName]
""""""
return self.properties.get(
"localizedNames", ClientValueCollection(LocalizedName)
Expand All @@ -45,6 +50,7 @@ def parent_group(self):

@property
def relations(self):
# type: () -> EntityCollection[Relation]
"""Indicates which terms have been pinned or reused directly under the set."""
return self.properties.get(
"relations",
Expand All @@ -55,6 +61,7 @@ def relations(self):

@property
def terms(self):
# type: () -> TermCollection
"""All the terms under the set."""
return self.properties.get(
"terms",
Expand Down
Loading

0 comments on commit c552771

Please sign in to comment.