Skip to content

Commit 0b67bbb

Browse files
committed
OneDrive: workspace namespace enhancements: new types & methods
1 parent a3dd31f commit 0b67bbb

File tree

12 files changed

+158
-19
lines changed

12 files changed

+158
-19
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
from office365.entity import Entity
2+
from office365.entity_collection import EntityCollection
3+
from office365.onedrive.workbooks.comments.reply import WorkbookCommentReply
4+
from office365.runtime.paths.resource_path import ResourcePath
25

36

47
class WorkbookComment(Entity):
58
"""Represents a comment in workbook."""
9+
10+
@property
11+
def replies(self):
12+
""""""
13+
return self.properties.get('replies',
14+
EntityCollection(self.context, WorkbookCommentReply,
15+
ResourcePath("replies", self.resource_path)))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class WorkbookCommentReply(Entity):
5+
"""Represents a reply to an Excel comment."""
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.entity import Entity
2+
3+
4+
class WorkbookFilter(Entity):
5+
"""Manages the filtering of a table's column."""

office365/onedrive/workbooks/functions/functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
class WorkbookFunctions(Entity):
77
"""Used as a container for Microsoft Excel worksheet function"""
88

9+
def abs(self, number):
10+
""""""
11+
return_type = WorkbookFunctionResult(self.context)
12+
payload = {
13+
"number": number,
14+
}
15+
qry = ServiceOperationQuery(self, "abs", None, payload, None, return_type)
16+
self.context.add_query(qry)
17+
return return_type
18+
919
def days(self, start_date, end_date):
1020
"""Returns the number of days between two dates.
1121

office365/onedrive/workbooks/ranges/range.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
from office365.entity import Entity
2+
from office365.onedrive.workbooks.ranges.view import WorkbookRangeView
23
from office365.runtime.paths.resource_path import ResourcePath
4+
from office365.runtime.queries.function import FunctionQuery
35

46

57
class WorkbookRange(Entity):
68
"""Range represents a set of one or more contiguous cells such as a cell, a row, a column, block of cells, etc."""
79

10+
def visible_view(self):
11+
""""""
12+
return_type = WorkbookRangeView(self.context)
13+
qry = FunctionQuery(self, "visibleView", return_type=return_type)
14+
self.context.add_query(qry)
15+
return return_type
16+
817
@property
918
def address(self):
1019
"""
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from office365.entity import Entity
2+
from office365.entity_collection import EntityCollection
3+
from office365.runtime.paths.resource_path import ResourcePath
4+
5+
6+
class WorkbookRangeView(Entity):
7+
"""Represents a set of visible cells of the parent range."""
8+
9+
@property
10+
def rows(self):
11+
"""Represents a collection of range views associated with the range."""
12+
return self.properties.get('rows',
13+
EntityCollection(self.context, WorkbookRangeView,
14+
ResourcePath("rows", self.resource_path)))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
from office365.entity_collection import EntityCollection
22
from office365.onedrive.workbooks.tables.columns.column import WorkbookTableColumn
3+
from office365.runtime.client_result import ClientResult
4+
from office365.runtime.queries.function import FunctionQuery
35

46

57
class WorkbookTableColumnCollection(EntityCollection):
68

79
def __init__(self, context, resource_path=None):
810
super(WorkbookTableColumnCollection, self).__init__(context, WorkbookTableColumn, resource_path)
911

12+
def add(self, index, name, values=None):
13+
"""
14+
Adds a new column to the table.
1015
16+
:param int index: Specifies the relative position of the new column. The previous column at this position
17+
is shifted to the right. The index value should be equal to or less than the last column's index value,
18+
so it cannot be used to append a column at the end of the table. Zero-indexed.
19+
:param list values: A 2-dimensional array of unformatted values of the table column.
20+
:param str name: Name
21+
"""
22+
return super(WorkbookTableColumnCollection, self).add(index=index, values=values, name=name)
23+
24+
def count(self):
25+
""""""
26+
return_type = ClientResult(self.context, int())
27+
qry = FunctionQuery(self, "count", None, return_type)
28+
self.context.add_query(qry)
29+
return return_type
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
from office365.entity import Entity
2+
from office365.onedrive.workbooks.filter import WorkbookFilter
3+
from office365.onedrive.workbooks.ranges.range import WorkbookRange
4+
from office365.runtime.paths.resource_path import ResourcePath
5+
from office365.runtime.queries.function import FunctionQuery
26

37

48
class WorkbookTableColumn(Entity):
59
"""Represents a column in a table."""
6-
pass
10+
11+
def header_row_range(self):
12+
"""
13+
Gets the range object associated with the header row of the column.
14+
"""
15+
return_type = WorkbookRange(self.context)
16+
qry = FunctionQuery(self, "headerRowRange", return_type=return_type)
17+
self.context.add_query(qry)
18+
return return_type
19+
20+
def range(self):
21+
"""
22+
Gets the range object associated with the entire column.
23+
"""
24+
return_type = WorkbookRange(self.context)
25+
qry = FunctionQuery(self, "range", return_type=return_type)
26+
self.context.add_query(qry)
27+
return return_type
28+
29+
@property
30+
def values(self):
31+
"""
32+
Represents the raw values of the specified range. The data returned could be of type string, number,
33+
or a boolean. Cell that contain an error will return the error string.
34+
"""
35+
return self.properties.get("values", None)
36+
37+
@property
38+
def filter(self):
39+
"""Retrieve the filter applied to the column."""
40+
return self.properties.get('filter',
41+
WorkbookFilter(self.context, ResourcePath("filter", self.resource_path)))

office365/onedrive/workbooks/tables/table.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from office365.onedrive.workbooks.ranges.range import WorkbookRange
33
from office365.onedrive.workbooks.tables.columns.collection import WorkbookTableColumnCollection
44
from office365.onedrive.workbooks.tables.rows.collection import WorkbookTableRowCollection
5-
from office365.runtime.http.http_method import HttpMethod
65
from office365.runtime.paths.resource_path import ResourcePath
6+
from office365.runtime.queries.function import FunctionQuery
77
from office365.runtime.queries.service_operation import ServiceOperationQuery
88

99

@@ -13,24 +13,22 @@ class WorkbookTable(Entity):
1313
def data_body_range(self):
1414
"""Gets the range object associated with the data body of the table."""
1515
return_type = WorkbookRange(self.context)
16-
qry = ServiceOperationQuery(self, "dataBodyRange", return_type=return_type)
16+
qry = FunctionQuery(self, "dataBodyRange", return_type=return_type)
1717
self.context.add_query(qry)
18+
return return_type
1819

19-
def _construct_request(request):
20-
request.method = HttpMethod.Get
21-
self.context.before_execute(_construct_request)
20+
def range(self):
21+
"""Get the range object associated with the entire table."""
22+
return_type = WorkbookRange(self.context)
23+
qry = FunctionQuery(self, "range", return_type=return_type)
24+
self.context.add_query(qry)
2225
return return_type
2326

2427
def total_row_range(self):
2528
"""Gets the range object associated with totals row of the table."""
2629
return_type = WorkbookRange(self.context)
27-
qry = ServiceOperationQuery(self, "totalRowRange", return_type=return_type)
30+
qry = FunctionQuery(self, "totalRowRange", return_type=return_type)
2831
self.context.add_query(qry)
29-
30-
def _construct_request(request):
31-
request.method = HttpMethod.Get
32-
33-
self.context.before_execute(_construct_request)
3432
return return_type
3533

3634
def clear_filters(self):

office365/outlook/calendar/group.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ class CalendarGroup(Entity):
1212
@property
1313
def name(self):
1414
"""
15+
The group name.
16+
1517
:rtype: str
1618
"""
1719
return self.properties.get("name", None)
1820

1921
@property
2022
def class_id(self):
2123
"""
24+
The class identifier
25+
2226
:rtype: str
2327
"""
2428
return self.properties.get("classId", None)

office365/outlook/contacts/folder.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from office365.directory.extensions.extended_property import MultiValueLegacyExtendedProperty, \
2+
SingleValueLegacyExtendedProperty
13
from office365.entity import Entity
24
from office365.entity_collection import EntityCollection
35
from office365.runtime.paths.resource_path import ResourcePath
@@ -21,10 +23,26 @@ def child_folders(self):
2123
EntityCollection(self.context, ContactFolder,
2224
ResourcePath("childFolders", self.resource_path)))
2325

26+
@property
27+
def multi_value_extended_properties(self):
28+
"""The collection of multi-value extended properties defined for the Contact folder."""
29+
return self.properties.get('multiValueExtendedProperties',
30+
EntityCollection(self.context, MultiValueLegacyExtendedProperty,
31+
ResourcePath("multiValueExtendedProperties", self.resource_path)))
32+
33+
@property
34+
def single_value_extended_properties(self):
35+
"""The collection of single-value extended properties defined for the Contact folder."""
36+
return self.properties.get('singleValueExtendedProperties',
37+
EntityCollection(self.context, SingleValueLegacyExtendedProperty,
38+
ResourcePath("singleValueExtendedProperties", self.resource_path)))
39+
2440
def get_property(self, name, default_value=None):
2541
if default_value is None:
2642
property_mapping = {
27-
"childFolders": self.child_folders
43+
"childFolders": self.child_folders,
44+
"multiValueExtendedProperties": self.multi_value_extended_properties,
45+
"singleValueExtendedProperties": self.single_value_extended_properties
2846
}
2947
default_value = property_mapping.get(name, None)
3048
return super(ContactFolder, self).get_property(name, default_value)

tests/onedrive/test_excel.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,34 @@ def test4_data_body_range(self):
5050
result = self.__class__.table.data_body_range().execute_query()
5151
self.assertIsNotNone(result.address)
5252

53-
def test5_get_table_rows(self):
53+
def test5_create_table_column(self):
54+
column = self.__class__.table.columns.add(3, "Column4").execute_query()
55+
self.assertIsNotNone(column.resource_path)
56+
57+
def test6_list_table_columns(self):
58+
columns = self.__class__.table.columns.get().execute_query()
59+
self.assertIsNotNone(columns.resource_path)
60+
61+
def test7_list_table_rows(self):
5462
rows = self.__class__.table.rows.get().execute_query()
5563
self.assertIsNotNone(rows.resource_path)
5664

57-
def test6_create_table_rows(self):
58-
rows = self.__class__.table.rows.add([["a", "b", "c"]]).execute_query()
65+
def test8_create_table_rows(self):
66+
rows = self.__class__.table.rows.add([["Val11", "Val12", "Val13", "Val14"]]).execute_query()
5967
self.assertIsNotNone(rows.resource_path)
6068

61-
def test7_delete_workbook_table(self):
69+
def test9_table_range(self):
70+
result = self.__class__.table.range().execute_query()
71+
self.assertIsNotNone(result.address)
72+
73+
def test_10_delete_workbook_table(self):
6274
self.__class__.table.delete_object().execute_query()
6375

64-
#def test8_workbook_create_session(self):
76+
#def test_11_workbook_create_session(self):
6577
# result = self.__class__.target_item.workbook.create_session().execute_query()
6678
# self.assertIsNotNone(result.value)
6779

68-
#def test9_workbook_close_session(self):
80+
#def test_12_workbook_close_session(self):
6981
# self.__class__.target_item.workbook.close_session().execute_query()
7082

7183

0 commit comments

Comments
 (0)