Skip to content

Commit 5985120

Browse files
committed
typings & worksheet range (#745) enhancements
1 parent a7897ee commit 5985120

File tree

14 files changed

+262
-78
lines changed

14 files changed

+262
-78
lines changed

examples/onedrive/excel/read_range.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Gets the range object specified by the address or name.
3+
4+
https://learn.microsoft.com/en-us/graph/api/worksheet-range?view=graph-rest-1.0
5+
"""
6+
7+
import sys
8+
9+
from office365.graph_client import GraphClient
10+
from tests.graph_case import acquire_token_by_username_password
11+
12+
client = GraphClient(acquire_token_by_username_password)
13+
drive_item = client.me.drive.root.get_by_path("Financial Sample.xlsx")
14+
worksheets = drive_item.workbook.worksheets.get().execute_query()
15+
if len(worksheets) == 0:
16+
sys.exit("No worksheets found")
17+
18+
# worksheet_range = worksheets["Sheet1"].range().execute_query()
19+
worksheet_range = worksheets["Sheet1"].range(address="A2:P10").execute_query()
20+
print(worksheet_range)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Demonstrates how to apply filtering to list collection
3+
4+
In the provided example only the user defined lists are getting returned
5+
"""
6+
7+
from office365.sharepoint.client_context import ClientContext
8+
from tests import test_client_credentials, test_team_site_url
9+
10+
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
11+
result = (
12+
ctx.web.lists.get_by_title("Site Pages")
13+
.items.filter("ID eq 135 AND RequestType eq 'Standard'")
14+
.get()
15+
.execute_query()
16+
)
17+
for item in result:
18+
print(item.properties)

generator/import_metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def export_to_file(path, content):
2121
"--endpoint",
2222
dest="endpoint",
2323
help="Import metadata endpoint",
24-
default="sharepoint",
24+
default="microsoftgraph",
2525
)
2626
parser.add_argument(
2727
"-p",
2828
"--path",
2929
dest="path",
30-
default="./metadata/SharePoint.xml",
30+
default="./metadata/MicrosoftGraph.xml",
3131
help="Import metadata endpoint",
3232
)
3333

generator/metadata/MicrosoftGraph.xml

+157-9
Large diffs are not rendered by default.

office365/directory/identities/userflows/b2x/user_flow.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.directory.identities.userflows.language_configuration import (
24
UserFlowLanguageConfiguration,
35
)
@@ -20,6 +22,7 @@ class B2XIdentityUserFlow(IdentityUserFlow):
2022

2123
@property
2224
def languages(self):
25+
# type: () -> EntityCollection[UserFlowLanguageConfiguration]
2326
"""The languages supported for customization within the user flow. Language customization is enabled by default
2427
in self-service sign-up user flow. You cannot create custom languages in self-service sign-up user flows.
2528
"""
@@ -34,9 +37,8 @@ def languages(self):
3437

3538
@property
3639
def user_attribute_assignments(self):
37-
"""
38-
The user attribute assignments included in the user flow.
39-
"""
40+
# type: () -> IdentityUserFlowAttributeAssignmentCollection
41+
"""The user attribute assignments included in the user flow."""
4042
return self.properties.get(
4143
"userAttributeAssignments",
4244
IdentityUserFlowAttributeAssignmentCollection(
@@ -47,11 +49,10 @@ def user_attribute_assignments(self):
4749

4850
@property
4951
def user_flow_type(self):
52+
# type: () -> Optional[str]
5053
"""
5154
The type of user flow. For self-service sign-up user flows,
5255
the value can only be signUpOrSignIn and cannot be modified after creation.
53-
54-
:rtype: str or None
5556
"""
5657
return self.properties.get("userFlowType", None)
5758

office365/directory/identities/userflows/language_configuration.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.directory.identities.userflows.language_page import UserFlowLanguagePage
24
from office365.entity import Entity
35
from office365.entity_collection import EntityCollection
@@ -11,19 +13,19 @@ class UserFlowLanguageConfiguration(Entity):
1113
User flows for Azure Active Directory support defining the language and strings shown to users
1214
as they go through the journeys you configure with your user flows."""
1315

16+
def __str__(self):
17+
return self.display_name or self.entity_type_name
18+
1419
@property
1520
def display_name(self):
16-
"""
17-
The language name to display.
18-
:rtype: str or None
19-
"""
21+
# type: () -> Optional[str]
22+
"""The language name to display."""
2023
return self.properties.get("displayName", None)
2124

2225
@property
2326
def default_pages(self):
24-
"""
25-
Collection of pages with the default content to display in a user flow for a specified language.
26-
"""
27+
# type: () -> EntityCollection[UserFlowLanguagePage]
28+
"""Collection of pages with the default content to display in a user flow for a specified language."""
2729
return self.properties.get(
2830
"defaultPages",
2931
EntityCollection(
@@ -35,6 +37,7 @@ def default_pages(self):
3537

3638
@property
3739
def overrides_pages(self):
40+
# type: () -> EntityCollection[UserFlowLanguagePage]
3841
"""Collection of pages with the default content to display in a user flow for a specified language."""
3942
return self.properties.get(
4043
"overridesPages",

office365/directory/licenses/details.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.directory.licenses.service_plan_info import ServicePlanInfo
24
from office365.entity import Entity
35
from office365.runtime.client_value_collection import ClientValueCollection
@@ -17,18 +19,17 @@ def service_plans(self):
1719

1820
@property
1921
def sku_id(self):
22+
# type: () -> Optional[str]
2023
"""
2124
Unique identifier (GUID) for the service SKU. Equal to the skuId property on the related SubscribedSku object.
22-
Read-only
23-
:rtype: str or None
2425
"""
2526
return self.properties.get("skuId", None)
2627

2728
@property
2829
def sku_part_number(self):
30+
# type: () -> Optional[str]
2931
"""
3032
Unique SKU display name. Equal to the skuPartNumber on the related SubscribedSku object;
3133
for example: "AAD_Premium". Read-only
32-
:rtype: str or None
3334
"""
3435
return self.properties.get("skuPartNumber", None)

office365/onedrive/workbooks/worksheets/worksheet.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from office365.entity_collection import EntityCollection
55
from office365.onedrive.workbooks.charts.chart import WorkbookChart
66
from office365.onedrive.workbooks.names.named_item import WorkbookNamedItem
7+
from office365.onedrive.workbooks.ranges.range import WorkbookRange
78
from office365.onedrive.workbooks.tables.collection import WorkbookTableCollection
89
from office365.onedrive.workbooks.tables.pivot_table import WorkbookPivotTable
910
from office365.onedrive.workbooks.worksheets.protection import (
1011
WorkbookWorksheetProtection,
1112
)
1213
from office365.runtime.paths.resource_path import ResourcePath
14+
from office365.runtime.queries.function import FunctionQuery
1315

1416

1517
class WorkbookWorksheet(Entity):
@@ -18,10 +20,22 @@ class WorkbookWorksheet(Entity):
1820
"""
1921

2022
def __repr__(self):
21-
return self.name
23+
return self.name or self.entity_type_name
2224

2325
def __str__(self):
24-
return self.name
26+
return self.name or self.entity_type_name
27+
28+
def range(self, address=None):
29+
"""Gets the range object specified by the address or name."""
30+
return_type = WorkbookRange(
31+
self.context, ResourcePath("range", self.resource_path)
32+
)
33+
params = {"address": address}
34+
qry = FunctionQuery(
35+
self, "range", method_params=params, return_type=return_type
36+
)
37+
self.context.add_query(qry)
38+
return return_type
2539

2640
@property
2741
def charts(self):

office365/outlook/calendar/events/event.py

+12-28
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,22 @@ def ical_uid(self):
112112

113113
@property
114114
def importance(self):
115-
"""
116-
The importance of the event. The possible values are: low, normal, high.
117-
:rtype: str
118-
"""
115+
# type: () -> Optional[str]
116+
"""The importance of the event. The possible values are: low, normal, high."""
119117
return self.properties.get("importance", None)
120118

121119
@property
122120
def is_all_day(self):
121+
# type: () -> Optional[bool]
123122
"""
124123
Set to true if the event lasts all day. If true, regardless of whether it's a single-day or multi-day event,
125124
start and end time must be set to midnight and be in the same time zone.
126-
:rtype: bool or None
127125
"""
128126
return self.properties.get("isAllDay", None)
129127

130128
@property
131129
def start(self):
132-
"""
133-
The date, time, and time zone that the event starts. By default, the start time is in UTC.
134-
"""
130+
"""The date, time, and time zone that the event starts. By default, the start time is in UTC."""
135131
return self.properties.get("start", DateTimeTimeZone())
136132

137133
@start.setter
@@ -145,9 +141,7 @@ def start(self, value):
145141

146142
@property
147143
def end(self):
148-
"""
149-
The date, time, and time zone that the event starts. By default, the start time is in UTC.
150-
"""
144+
"""The date, time, and time zone that the event starts. By default, the start time is in UTC."""
151145
return self.properties.get("end", DateTimeTimeZone())
152146

153147
@end.setter
@@ -187,40 +181,30 @@ def multi_value_extended_properties(self):
187181

188182
@property
189183
def body(self):
190-
"""
191-
The body of the message associated with the event. It can be in HTML or text format.
192-
"""
184+
"""The body of the message associated with the event. It can be in HTML or text format."""
193185
return self.properties.get("body", ItemBody())
194186

195187
@body.setter
196188
def body(self, value):
197-
"""
198-
Sets The body of the message associated with the event. It can be in HTML or text format.
199-
"""
189+
"""Sets The body of the message associated with the event. It can be in HTML or text format."""
200190
self.set_property("body", ItemBody(value, "HTML"))
201191

202192
@property
203193
def body_preview(self):
204-
"""
205-
The preview of the message associated with the event. It is in text format.
206-
:rtype: str or None
207-
"""
194+
# type: () -> Optional[str]
195+
"""The preview of the message associated with the event. It is in text format."""
208196
return self.properties.get("bodyPreview", None)
209197

210198
@property
211199
def subject(self):
212200
# type: () -> Optional[str]
213-
"""
214-
The text of the event's subject line.
215-
"""
201+
"""The text of the event's subject line."""
216202
return self.properties.get("subject", None)
217203

218204
@subject.setter
219205
def subject(self, value):
220-
"""
221-
Sets The text of the event's subject line.
222-
:type: str or None
223-
"""
206+
# type: (str) -> None
207+
"""Sets The text of the event's subject line."""
224208
self.set_property("subject", value)
225209

226210
@property

office365/sharepoint/alerts/alert.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from office365.runtime.paths.resource_path import ResourcePath
24
from office365.sharepoint.entity import Entity
35

@@ -14,26 +16,20 @@ class Alert(Entity):
1416

1517
@property
1618
def alert_frequency(self):
17-
"""
18-
Gets the time interval for sending the alert.
19-
:rtype: int
20-
"""
19+
# type: () -> Optional[int]
20+
"""Gets the time interval for sending the alert."""
2121
return self.properties.get("AlertFrequency", None)
2222

2323
@property
2424
def alert_template_name(self):
25-
"""
26-
Gets the string representing the alert template name.
27-
:rtype: int
28-
"""
25+
# type: () -> Optional[int]
26+
"""Gets the string representing the alert template name."""
2927
return self.properties.get("AlertTemplateName", None)
3028

3129
@property
3230
def always_notify(self):
33-
"""
34-
Gets a Boolean value that causes daily and weekly alerts to trigger, even if there is no matching event.
35-
:rtype: bool
36-
"""
31+
# type: () -> Optional[bool]
32+
"""Gets a Boolean value that causes daily and weekly alerts to trigger, even if there is no matching event."""
3733
return self.properties.get("AlwaysNotify", None)
3834

3935
@property

office365/sharepoint/features/collection.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from office365.sharepoint.features.feature import Feature
55

66

7-
class FeatureCollection(EntityCollection):
7+
class FeatureCollection(EntityCollection[Feature]):
88
"""Represents a collection of Feature resources."""
99

1010
def __init__(self, context, resource_path=None, parent=None):
@@ -31,9 +31,7 @@ def _create_query():
3131
return ServiceOperationQuery(self, "Add", None, payload, None, return_type)
3232

3333
def _create_if_not_activated(f):
34-
"""
35-
:type f: Feature
36-
"""
34+
# type: (Feature) -> None
3735
if not f.properties:
3836
self.context.add_query(_create_query())
3937

office365/sharepoint/webs/template.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
class WebTemplate(Entity):
77
"""Specifies a site definition or a site template that is used to instantiate a site."""
88

9+
def __str__(self):
10+
return self.title or self.entity_type_name
11+
912
def __repr__(self):
1013
return self.name
1114

@@ -68,9 +71,8 @@ def lcid(self):
6871

6972
@property
7073
def name(self):
71-
"""Gets a value that specifies the display name of the list template.
72-
:rtype: str or None
73-
"""
74+
# type: () -> Optional[str]
75+
"""Gets a value that specifies the display name of the list template."""
7476
return self.properties.get("Name", None)
7577

7678
@property

office365/sharepoint/webs/web.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,8 @@ def url(self):
21852185

21862186
@property
21872187
def quick_launch_enabled(self):
2188-
"""Gets a value that specifies whether the Quick Launch area is enabled on the site.
2189-
:rtype: bool or None
2190-
"""
2188+
# type: () -> Optional[bool]
2189+
"""Gets a value that specifies whether the Quick Launch area is enabled on the site."""
21912190
return self.properties.get("QuickLaunchEnabled", None)
21922191

21932192
@property

0 commit comments

Comments
 (0)