Skip to content

Commit d1650c8

Browse files
committed
#766 fix, SharePoint examples updates, typings enhancements
1 parent 4489512 commit d1650c8

File tree

38 files changed

+167
-162
lines changed

38 files changed

+167
-162
lines changed

examples/onedrive/files/search.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
client = GraphClient(acquire_token_by_username_password)
1111
result = client.search.query_drive_items("Guide.docx").execute_query()
1212
for item in result.value:
13-
print("Search terms: {0}".format(item.searchTerms))
13+
for hit_container in item.hitsContainers:
14+
for hit in hit_container.hits:
15+
print(hit.resource)

examples/onedrive/sites/__init__.py

Whitespace-only changes.

examples/planner/__init__.py

Whitespace-only changes.

examples/sharepoint/files/copy_file.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"Shared Documents/Financial Sample.xlsx"
1111
)
1212
folder_to = ctx.web.get_folder_by_server_relative_url("Shared Documents/archive")
13+
# folder_to = "Shared Documents/archive/2002/02"
1314
file_to = file_from.copyto(folder_to, True).execute_query()
14-
print("File has been copied into '{0}'".format(file_to))
15+
print("{0} copied into '{1}'".format(file_from, file_to))

examples/sharepoint/files/copy_using_path.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
)
1212

1313
folder_to = ctx.web.get_folder_by_server_relative_path("Shared Documents/archive")
14+
# folder_to = "Shared Documents/archive/2002/02"
1415
file_to = file_from.copyto_using_path(folder_to, True).execute_query()
15-
print("File has been copied into '{0}'".format(file_to.server_relative_path))
16+
print("{0} copied into {1}".format(file_from, file_to))

examples/sharepoint/files/move_file.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,18 @@
33
"""
44
from office365.sharepoint.client_context import ClientContext
55
from office365.sharepoint.files.move_operations import MoveOperations
6-
from tests import create_unique_name, test_team_site_url, test_user_credentials
6+
from tests import test_team_site_url, test_user_credentials
77

88
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
99

10-
print("Creating temporary folders and uploading a file...")
11-
path = "../../data/report #123.csv"
12-
folder_from = ctx.web.default_document_library().root_folder.add(
13-
create_unique_name("from")
14-
)
15-
folder_to = ctx.web.default_document_library().root_folder.add(create_unique_name("to"))
16-
file = folder_from.files.upload(path).execute_query()
1710

18-
# copies the file with a new name into folder
19-
print("Moving file to parent folder...")
20-
file_to = file.move_to_using_path(folder_to, MoveOperations.overwrite).execute_query()
21-
print(
22-
"File has been copied from '{0}' into '{1}'".format(
23-
file.server_relative_path, folder_to.serverRelativeUrl
24-
)
11+
file_from = ctx.web.get_file_by_server_relative_path(
12+
"Shared Documents/Financial Sample.xlsx"
2513
)
14+
# folder_to = ctx.web.get_folder_by_server_relative_url("Shared Documents")
15+
folder_to = "Shared Documents"
2616

27-
print("Cleaning up...")
28-
folder_from.delete_object().execute_query()
29-
folder_to.delete_object().execute_query()
17+
file_to = file_from.move_to_using_path(
18+
folder_to, MoveOperations.overwrite
19+
).execute_query()
20+
print("'{0}' moved into '{1}'".format(file_from, file_to))

examples/sharepoint/files/rename_page.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from office365.sharepoint.client_context import ClientContext
55
from tests import test_team_site_url, test_user_credentials
66

7-
from_url = "Home_Archive.aspx"
8-
to_url = "Home.aspx"
7+
file_url = "Site Pages/Home.aspx"
8+
new_name = "NewHome.aspx"
99
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
10-
file = ctx.web.lists.get_by_title("Site Pages").root_folder.files.get_by_url(from_url)
11-
file.rename(to_url).execute_query()
10+
file = ctx.web.get_file_by_server_relative_path(file_url)
11+
file.rename(new_name).execute_query()

examples/sharepoint/folders/create.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414
.execute_query()
1515
)
1616
print("Folder : {0} has been created".format(folder.serverRelativeUrl))
17-
folder.delete_object().execute_query()

examples/sharepoint/folders/create_doc_set.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
from tests import test_client_credentials, test_team_site_url
44

55
client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
6-
target_folder = client.web.default_document_library().root_folder.folders.get_by_url(
7-
"2017"
8-
)
9-
10-
doc_set = DocumentSet.create(client, target_folder, "07").execute_query()
6+
lib = client.web.default_document_library()
7+
doc_set = DocumentSet.create(client, lib.root_folder, "07").execute_query()
118
print("DocSet created: {0}".format(doc_set.name))

examples/sharepoint/folders/folder_exists.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests import test_client_credentials, test_team_site_url
66

77
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
8-
folder_path = "SitePages"
8+
folder_path = "Shared Documents"
99
folder = (
1010
ctx.web.get_folder_by_server_relative_url(folder_path)
1111
.select(["Exists"])
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"""
2+
Get folder at the specified path
3+
"""
14
from office365.sharepoint.client_context import ClientContext
25
from tests import test_client_credentials, test_team_site_url
36

47
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
5-
folder = ctx.web.folders.get_by_path("Shared Documents")
6-
ctx.load(folder, ["ServerRelativeUrl", "Folders"]).execute_query()
7-
print(folder.serverRelativeUrl)
8+
folder = ctx.web.folders.get_by_path("Shared Documents").get().execute_query()
9+
print(folder)

examples/sharepoint/folders/get_props.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Gets Folder properties
2+
Gets folder properties
33
"""
44
from office365.sharepoint.client_context import ClientContext
55
from tests import test_client_credentials, test_team_site_url

examples/sharepoint/folders/list_folders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
1010
folders = (
11-
ctx.web.default_document_library().root_folder.get_folders(True).execute_query()
11+
ctx.web.default_document_library().root_folder.get_folders(False).execute_query()
1212
)
1313
for folder in folders:
1414
print(
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
"""
2+
Demonstrates how to update folder properties
3+
"""
14
from office365.sharepoint.client_context import ClientContext
25
from tests import test_team_site_url, test_user_credentials
36

47
ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
58

6-
target_folder_url = "/Shared Documents/Archive/2022/09/01"
7-
target_folder = (
8-
ctx.web.default_document_library().root_folder.folders.ensure_folder_path(
9-
"Archive/2022/09"
10-
)
11-
)
12-
folder_item = target_folder.list_item_all_fields
13-
folder_item.set_property("DocScope", "Public").update().execute_query()
14-
print(target_folder.serverRelativeUrl)
9+
folder_url = "Shared Documents/Archive"
10+
folder = ctx.web.get_folder_by_server_relative_path(folder_url)
11+
folder_item = folder.list_item_all_fields
12+
prop_name = "DocScope"
13+
prop_value = "Public"
14+
folder_item.set_property(prop_name, prop_value).update().execute_query()

examples/sharepoint/listitems/read.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
This common way of retrieving List Items from a List, only the default properties are getting returned
3+
4+
Official documentation:
5+
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest#working-with-list-items-by-using-rest
6+
"""
7+
8+
from office365.sharepoint.client_context import ClientContext
9+
from tests import test_client_credentials, test_team_site_url
10+
11+
list_title = "Company Tasks"
12+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
13+
tasks_list = ctx.web.lists.get_by_title(list_title)
14+
items = tasks_list.items.get().execute_query()
15+
for item in items:
16+
print("{0}".format(item.properties.get("Title")))

examples/sharepoint/listitems/read_props.py

-8
This file was deleted.

examples/sharepoint/sharing/share_web.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Share a Web with user
3+
"""
4+
15
import sys
26

37
from office365.sharepoint.client_context import ClientContext

examples/teams/__init__.py

Whitespace-only changes.

examples/teams/does_user_have_access.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77

88
from office365.graph_client import GraphClient
9-
from office365.teams.team import Team
109
from tests import test_user_principal_name
1110
from tests.graph_case import acquire_token_by_client_credentials
1211

@@ -15,7 +14,7 @@
1514
if len(teams) < 1:
1615
sys.exit("No teams found")
1716

18-
team = teams[0] # type: Team
17+
team = teams[0]
1918
result = team.primary_channel.does_user_have_access(
2019
user_principal_name=test_user_principal_name
2120
).execute_query()

examples/teams/list_all.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
from office365.graph_client import GraphClient
8-
from office365.teams.team import Team
98
from tests.graph_case import acquire_token_by_client_credentials
109

1110
client = GraphClient(acquire_token_by_client_credentials)

office365/communications/onlinemeetings/online_meeting.py

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

34
from office365.communications.onlinemeetings.participants import MeetingParticipants
45
from office365.entity import Entity
@@ -14,49 +15,37 @@ class OnlineMeeting(Entity):
1415

1516
@property
1617
def allow_attendee_to_enable_camera(self):
17-
"""
18-
Indicates whether attendees can turn on their camera.
19-
:rtype: str
20-
"""
18+
# type: () -> Optional[bool]
19+
"""Indicates whether attendees can turn on their camera."""
2120
return self.properties.get("allowAttendeeToEnableCamera", None)
2221

2322
@property
2423
def allow_attendee_to_enable_mic(self):
25-
"""
26-
Indicates whether attendees can turn on their microphone.
27-
:rtype: str
28-
"""
24+
# type: () -> Optional[bool]
25+
"""Indicates whether attendees can turn on their microphone."""
2926
return self.properties.get("allowAttendeeToEnableMic", None)
3027

3128
@property
3229
def allowed_presenters(self):
33-
"""
34-
Specifies who can be a presenter in a meeting. Possible values are listed in the following table.
35-
"""
30+
"""Specifies who can be a presenter in a meeting. Possible values are listed in the following table."""
3631
return self.properties.get("allowedPresenters", StringCollection())
3732

3833
@property
3934
def allow_meeting_chat(self):
40-
"""
41-
Specifies the mode of meeting chat.
42-
:rtype: str or None
43-
"""
35+
# type: () -> Optional[bool]
36+
"""Specifies the mode of meeting chat."""
4437
return self.properties.get("allowMeetingChat", None)
4538

4639
@property
4740
def allow_participants_to_change_name(self):
48-
"""
49-
Specifies if participants are allowed to rename themselves in an instance of the meeting.
50-
:rtype: bool or None
51-
"""
41+
# type: () -> Optional[bool]
42+
"""Specifies if participants are allowed to rename themselves in an instance of the meeting."""
5243
return self.properties.get("allowParticipantsToChangeName", None)
5344

5445
@property
5546
def attendee_report(self):
56-
"""
57-
The content stream of the attendee report of a Microsoft Teams live event.
58-
:rtype: bytes or None
59-
"""
47+
# type: () -> Optional[AnyStr]
48+
"""The content stream of the attendee report of a Microsoft Teams live event."""
6049
return self.properties.get("attendeeReport", None)
6150

6251
@property
@@ -68,17 +57,13 @@ def participants(self):
6857

6958
@property
7059
def subject(self):
71-
"""
72-
The subject of the online meeting.
73-
:rtype: str or None
74-
"""
60+
# type: () -> Optional[str]
61+
"""The subject of the online meeting."""
7562
return self.properties.get("subject", None)
7663

7764
@subject.setter
7865
def subject(self, value):
79-
"""
80-
:type value: str
81-
"""
66+
# type: (str) -> None
8267
self.set_property("subject", value)
8368

8469
@property
@@ -88,9 +73,9 @@ def start_datetime(self):
8873

8974
@start_datetime.setter
9075
def start_datetime(self, value):
76+
# type: (datetime) -> None
9177
"""
9278
Sets the meeting start time in UTC.
93-
:type value: datetime.datetime
9479
"""
9580
self.set_property("startDateTime", value.isoformat())
9681

@@ -101,10 +86,8 @@ def end_datetime(self):
10186

10287
@end_datetime.setter
10388
def end_datetime(self, value):
104-
"""
105-
Sets the meeting end time in UTC.
106-
:type value: datetime.datetime
107-
"""
89+
# type: (datetime) -> None
90+
"""Sets the meeting end time in UTC."""
10891
self.set_property("endDateTime", value.isoformat())
10992

11093
@property
@@ -114,11 +97,13 @@ def join_information(self):
11497

11598
@property
11699
def join_web_url(self):
100+
# type: () -> Optional[str]
117101
"""The join URL of the online meeting. Read-only."""
118102
return self.properties.get("joinWebUrl", None)
119103

120104
@property
121105
def video_teleconference_id(self):
106+
# type: () -> Optional[str]
122107
"""The video teleconferencing ID."""
123108
return self.properties.get("videoTeleconferenceId", None)
124109

office365/directory/users/activities/activity.py

+5-4
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
@@ -15,39 +16,39 @@ class UserActivity(Entity):
1516

1617
@property
1718
def activation_url(self):
19+
# type: () -> Optional[str]
1820
"""URL used to launch the activity in the best native experience represented by the appId.
1921
Might launch a web-based app if no native app exists
20-
:rtype: str or None
2122
"""
2223
return self.properties.get("activationUrl", None)
2324

2425
@property
2526
def activity_source_host(self):
27+
# type: () -> Optional[str]
2628
"""Required. URL for the domain representing the cross-platform identity mapping for the app.
2729
Mapping is stored either as a JSON file hosted on the domain or configurable via Windows Dev Center.
2830
The JSON file is named cross-platform-app-identifiers and is hosted at root of your HTTPS domain,
2931
either at the top level domain or include a sub domain.
3032
For example: https://contoso.com or https://myapp.contoso.com but NOT https://myapp.contoso.com/somepath.
3133
You must have a unique file and domain (or sub domain) per cross-platform app identity.
3234
For example, a separate file and domain is needed for Word vs. PowerPoint.
33-
:rtype: str or None
3435
"""
3536
return self.properties.get("activitySourceHost", None)
3637

3738
@property
3839
def app_activity_id(self):
40+
# type: () -> Optional[str]
3941
"""
4042
The unique activity ID in the context of the app - supplied by caller and immutable thereafter.
41-
:rtype: str
4243
"""
4344
return self.properties.get("appActivityId", None)
4445

4546
@property
4647
def app_display_name(self):
48+
# type: () -> Optional[str]
4749
"""
4850
Short text description of the app used to generate the activity for use in cases when the app is
4951
not installed on the user’s local device.
50-
:rtype: str
5152
"""
5253
return self.properties.get("appDisplayName", None)
5354

0 commit comments

Comments
 (0)