Skip to content

Commit c552771

Browse files
committed
taxonomy namespace & typings enhancements
1 parent b9d91e0 commit c552771

File tree

45 files changed

+211
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+211
-158
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
Get term set by name
2+
Get term sets in Group
33
"""
44

55
from office365.graph_client import GraphClient
66
from tests.graph_case import acquire_token_by_username_password
77

88
client = GraphClient(acquire_token_by_username_password)
99
term_store = client.sites.root.term_store
10-
group = term_store.groups.get_by_name("Geography").get().execute_query()
11-
term_set = group.sets.get_by_name("Locations").get().execute_query()
12-
print(term_set.id)
10+
sets = term_store.groups.get_by_name("Geography").sets.get().execute_query()
11+
# term_set = group.sets.get_by_name("Locations").get().execute_query()
12+
for ts in sets:
13+
print(ts)

examples/sharepoint/features/ensure_activated.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tests import test_client_credentials, test_site_url
55

66
ctx = ClientContext(test_site_url).with_credentials(test_client_credentials)
7-
f = ctx.site.features.add(
7+
feature = ctx.site.features.add(
88
KnownFeaturesList.ContentTypeHub, False, FeatureDefinitionScope.Farm, True
99
).execute_query()
10-
print("Feature {0} has been activated.", f.display_name)
10+
print("Feature {0} has been activated.", feature.display_name)

examples/sharepoint/folders/get_system_metadata.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,44 @@
77

88
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
99
list_title = "Docs"
10+
11+
folder_items = (
12+
ctx.web.lists.get_by_title(list_title)
13+
.items.filter("FSObjType eq 1")
14+
.select(
15+
[
16+
"FSObjType",
17+
"Author/Id",
18+
"Author/Title",
19+
"Author/Name",
20+
"Editor/Id",
21+
"Editor/Title",
22+
"Editor/Name",
23+
]
24+
)
25+
.expand(["Author", "Editor"])
26+
.get()
27+
.execute_query()
28+
)
29+
1030
folder_path = "Archive" # folder relative path
1131
folder_item = (
1232
ctx.web.lists.get_by_title(list_title)
1333
.get_item_by_url(folder_path)
14-
.select(["Author/Title"])
15-
.expand(["Author"])
34+
.select(
35+
[
36+
"Author/Id",
37+
"Author/Title",
38+
"Author/Name",
39+
"Editor/Id",
40+
"Editor/Title",
41+
"Editor/Name",
42+
]
43+
)
44+
.expand(["Author", "Editor"])
1645
.get()
1746
.execute_query()
1847
)
1948

2049
print(folder_item.properties.get("Author"))
50+
print(folder_item.properties.get("Editor"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Search for document files within a specific site
3+
Path managed property is provided to limit search scope
4+
5+
https://learn.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview
6+
"""
7+
8+
from office365.sharepoint.client_context import ClientContext
9+
from tests import (
10+
test_site_url,
11+
test_team_site_url,
12+
test_user_credentials,
13+
)
14+
15+
ctx = ClientContext(test_site_url).with_credentials(test_user_credentials)
16+
17+
result = ctx.search.post_query(
18+
"Path={0}/*".format(test_team_site_url), row_limit=10
19+
).execute_query()
20+
for row in result.value.PrimaryQueryResult.RelevantResults.Table.Rows:
21+
print("{0}".format(row.Cells["Path"]))

examples/sharepoint/tenant/__init__.py

Whitespace-only changes.

examples/sharepoint/users/__init__.py

Whitespace-only changes.

examples/sharepoint/users/export_site_users.py examples/sharepoint/users/list_site_users.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""
22
Retrieves site users
3-
4-
53
"""
64

75
from office365.sharepoint.client_context import ClientContext

office365/base_item.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def created_by(self):
2525

2626
@property
2727
def created_by_user(self):
28-
"""
29-
Identity of the user who created the item
30-
"""
28+
"""Identity of the user who created the item"""
3129
from office365.directory.users.user import User
3230

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

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

4342
@property
4443
def last_modified_by_user(self):
45-
"""
46-
Identity of the user who last modified the item.
47-
"""
44+
"""Identity of the user who last modified the item."""
4845
from office365.directory.users.user import User
4946

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

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

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

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

7170
@name.setter
7271
def name(self, value):
73-
"""
74-
Sets the name of the item.
75-
"""
72+
# type: (str) -> None
73+
"""Sets the name of the item."""
7674
self.set_property("name", value)
7775

7876
@property
7977
def description(self):
8078
# type: () -> Optional[str]
81-
"""
82-
Provides a user-visible description of the item.
83-
"""
79+
"""Provides a user-visible description of the item."""
8480
return self.properties.get("description", None)
8581

8682
@description.setter
8783
def description(self, value):
84+
# type: (str) -> None
8885
self.set_property("description", value)
8986

9087
@property
9188
def web_url(self):
9289
# type: () -> Optional[str]
93-
"""
94-
URL that displays the resource in the browser
95-
"""
90+
"""URL that displays the resource in the browser"""
9691
return self.properties.get("webUrl", None)
9792

9893
@property
9994
def parent_reference(self):
95+
# type: () -> ItemReference
10096
"""Parent information, if the item has a parent."""
101-
return self.properties.get("parentReference", ItemReference())
102-
103-
@parent_reference.setter
104-
def parent_reference(self, value):
105-
self.set_property("parentReference", value, False)
97+
return self.properties.setdefault("parentReference", ItemReference())
10698

10799
def get_property(self, name, default_value=None):
108100
if default_value is None:

office365/communications/presences/presence.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from office365.communications.presences.status_message import PresenceStatusMessage
44
from office365.entity import Entity
5+
from office365.outlook.calendar.dateTimeTimeZone import DateTimeTimeZone
56
from office365.outlook.mail.item_body import ItemBody
67
from office365.runtime.queries.service_operation import ServiceOperationQuery
78

@@ -52,12 +53,22 @@ def set_presence(
5253
self.context.add_query(qry)
5354
return self
5455

55-
def set_status_message(self, message):
56+
def set_status_message(self, message, expiry=None):
5657
"""
5758
Set a presence status message for a user. An optional expiration date and time can be supplied.
58-
:param str message: Status message item.
59+
:param str or ItemBody message: Status message item.
60+
:param datetime.datetime expiry: Time in which the status message expires. If not provided, the status message
61+
doesn't expire.
5962
"""
60-
payload = {"statusMessage": PresenceStatusMessage(message=ItemBody(message))}
63+
if not isinstance(message, ItemBody):
64+
message = ItemBody(message)
65+
if expiry:
66+
expiry = DateTimeTimeZone.parse(expiry)
67+
payload = {
68+
"statusMessage": PresenceStatusMessage(
69+
message=message, expiry_datetime=expiry
70+
)
71+
}
6172
qry = ServiceOperationQuery(self, "setStatusMessage", None, payload)
6273
self.context.add_query(qry)
6374
return self

office365/entity_collection.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def __getitem__(self, key):
4141

4242
def add(self, **kwargs):
4343
# type: (Any) -> T
44-
"""
45-
Creates an entity and prepares the query
46-
"""
44+
"""Creates an entity and prepares the query"""
4745
return_type = self.create_typed_object(kwargs, ItemPath(self.resource_path))
4846
self.add_child(return_type)
4947
qry = CreateEntityQuery(self, return_type, return_type)

office365/onedrive/analytics/item_activity_stat.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from typing import Optional
23

34
from office365.entity import Entity
45
from office365.entity_collection import EntityCollection
@@ -38,9 +39,8 @@ def end_datetime(self):
3839

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

4646
@property
@@ -55,6 +55,7 @@ def start_datetime(self):
5555

5656
@property
5757
def activities(self):
58+
# type: () -> EntityCollection[ItemActivity]
5859
"""Exposes the itemActivities represented in this itemActivityStat resource."""
5960
return self.properties.get(
6061
"activities",

office365/onedrive/documentsets/version.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def created_by(self):
2525
@property
2626
def created_datetime(self):
2727
# type: () -> datetime.datetime
28-
"""
29-
Date and time when this version was created.
30-
"""
28+
"""Date and time when this version was created."""
3129
return self.properties("createdDateTime", datetime.datetime.min)
3230

3331
@property

office365/onedrive/listitems/list_item.py

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def drive_item(self):
6060

6161
@property
6262
def content_type(self):
63+
# type: () -> ContentTypeInfo
6364
"""The content type of this list item"""
6465
return self.properties.get("contentType", ContentTypeInfo())
6566

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

7475
@property
7576
def document_set_versions(self):
77+
# type: () -> EntityCollection[DocumentSetVersion]
7678
"""Version information for a document set version created by a user."""
7779
return self.properties.get(
7880
"documentSetVersions",

office365/onedrive/sharepoint.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Sharepoint(Entity):
88

99
@property
1010
def settings(self):
11+
# type: () -> SharepointSettings
1112
"""Represents the tenant-level settings for SharePoint and OneDrive."""
1213
return self.properties.get(
1314
"settings",

office365/onedrive/shares/collection.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ def __init__(self, context, resource_path=None):
88
super(SharesCollection, self).__init__(context, SharedDriveItem, resource_path)
99

1010
def by_url(self, url):
11-
"""
12-
Address shared item by absolute url
13-
:type url: str
14-
"""
11+
# type: (str) -> SharedDriveItem
12+
"""Address shared item by absolute url"""
1513
return SharedDriveItem(self.context, SharedPath(url, self.resource_path))

office365/onedrive/termstore/groups/group.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.entity import Entity
24
from office365.onedrive.termstore.sets.collection import SetCollection
35
from office365.runtime.paths.resource_path import ResourcePath
@@ -6,18 +8,24 @@
68
class Group(Entity):
79
"""Term Group"""
810

11+
def __str__(self):
12+
return self.display_name
13+
914
@property
1015
def display_name(self):
16+
# type: () -> Optional[str]
1117
"""Name of the group."""
1218
return self.properties.get("displayName", None)
1319

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

1926
@property
2027
def sets(self):
28+
# type: () -> SetCollection
2129
"""Collection of all sets available in the term store."""
2230
return self.properties.get(
2331
"sets",

office365/onedrive/termstore/sets/collection.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, context, resource_path=None, parent_group=None):
1414
self._parent_group = parent_group
1515

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

office365/onedrive/termstore/sets/name.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from office365.runtime.client_value import ClientValue
24

35

@@ -15,3 +17,6 @@ def __init__(self, name=None, language_tag="en-US"):
1517
super(LocalizedName, self).__init__()
1618
self.name = name
1719
self.languageTag = language_tag
20+
21+
def __repr__(self):
22+
return json.dumps(self.to_json())

office365/onedrive/termstore/sets/set.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ class Set(Entity):
1414
terms. A group can contain multiple sets.
1515
"""
1616

17+
def __repr__(self):
18+
return repr(self.localized_names)
19+
1720
@property
1821
def children(self):
22+
# type: () -> TermCollection
1923
"""Children terms of set in term store."""
2024
return self.properties.get(
2125
"children",
@@ -28,6 +32,7 @@ def children(self):
2832

2933
@property
3034
def localized_names(self):
35+
# type: () -> ClientValueCollection[LocalizedName]
3136
""""""
3237
return self.properties.get(
3338
"localizedNames", ClientValueCollection(LocalizedName)
@@ -45,6 +50,7 @@ def parent_group(self):
4550

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

5662
@property
5763
def terms(self):
64+
# type: () -> TermCollection
5865
"""All the terms under the set."""
5966
return self.properties.get(
6067
"terms",

0 commit comments

Comments
 (0)