Skip to content

Commit 79cb42a

Browse files
committed
SharePoint API: view namespace updates
1 parent d6d8201 commit 79cb42a

File tree

13 files changed

+201
-21
lines changed

13 files changed

+201
-21
lines changed

examples/sharepoint/files/get_file_properties.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@
55

66
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
77
file_url = '/sites/team/Shared Documents/big_buck_bunny.mp4'
8-
#file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query()
9-
file = ctx.web.get_file_by_server_relative_url(file_url).expand(["ModifiedBy"]).get().execute_query()
8+
file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query()
9+
#file = ctx.web.get_file_by_server_relative_url(file_url).expand(["ModifiedBy"]).get().execute_query()
10+
#file = ctx.web.get_file_by_server_relative_url(file_url).expand(["ListItemAllFields"]).get().execute_query()
1011

1112
# print all file properties
1213
#print(json.dumps(file.properties, indent=4))
1314

1415
# or directly via object properties
1516
print("File size: ", file.length)
1617
print("File name: ", file.name)
17-
print("File modified by: {0}".format(file.modified_by.properties.get('UserPrincipalName')))
18+
#print("File modified by: {0}".format(file.modified_by.properties.get('UserPrincipalName')))
19+
#print("File modified by: {0}".format(file.listItemAllFields))
20+
if file.properties.get('CheckOutType') == 0:
21+
print("The file is checked out for editing on the server")
22+
elif file.properties.get('CheckOutType') == 1:
23+
print("The file is checked out for editing on the local computer.")
24+
else:
25+
print("The file is not checked out.")
26+
27+
1828

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
from office365.sharepoint.client_context import ClientContext
2+
from office365.sharepoint.listitems.listitem import ListItem
23
from tests import test_client_credentials, test_team_site_url
34

5+
6+
def retrieve_default_view_items(context):
7+
"""
8+
:type context: ClientContext
9+
"""
10+
lib = context.web.default_document_library()
11+
items = lib.default_view.get_items().execute_query()
12+
for item in items: # type: ListItem
13+
print(item.id)
14+
15+
16+
def retrieve_custom_view_items(context):
17+
"""
18+
:type context: ClientContext
19+
"""
20+
view = context.web.lists.get_by_title("Contacts_Large").views.get_by_title("All contacts")
21+
items = view.get_items().top(5).execute_query()
22+
for item in items: # type: ListItem
23+
print(item.id)
24+
25+
426
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
5-
lib = ctx.web.default_document_library()
6-
items = lib.default_view.get_items().execute_query()
7-
print(items)
27+
retrieve_default_view_items(ctx)
28+
#retrieve_custom_view_items(ctx)

office365/sharepoint/listitems/caml/query.py

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,77 @@
22
from office365.sharepoint.views.scope import ViewScope
33

44

5+
class WhereElement(object):
6+
"""Used within the context of a query to specify a filter."""
7+
8+
def __str__(self):
9+
return "<Where></Where>"
10+
11+
12+
class OrderByElement(object):
13+
"""Determines the sort order for a query"""
14+
15+
def __str__(self):
16+
return "<OrderBy></OrderBy>"
17+
18+
19+
class GroupByElement(object):
20+
"""Contains a Group By section for grouping the data returned through a query in a list view."""
21+
22+
def __str__(self):
23+
return "<GroupBy></GroupBy>"
24+
25+
26+
class QueryElement(object):
27+
"""Defines the query for a view."""
28+
29+
def __init__(self):
30+
self.Where = WhereElement()
31+
self.OrderBy = OrderByElement()
32+
self.GroupBy = GroupByElement()
33+
34+
@staticmethod
35+
def parse(expr):
36+
return QueryElement()
37+
38+
def __repr__(self):
39+
return "<Query>{0}</Query>".format(str(self.Where))
40+
41+
42+
class RowLimitElement(object):
43+
"""Sets the row limit for the number of items to display in a view."""
44+
45+
def __init__(self, top=None):
46+
"""
47+
:param int top:
48+
"""
49+
self.Top = top
50+
51+
def __str__(self):
52+
return "<RowLimit Paged=\"TRUE\">{0}</RowLimit>".format(self.Top)
53+
54+
55+
class ViewElement(object):
56+
""""""
57+
58+
def __init__(self, scope=ViewScope.DefaultValue, query=QueryElement(), row_limit=RowLimitElement()):
59+
self.Scope = scope
60+
self.Query = query
61+
self.RowLimit = row_limit
62+
63+
def __str__(self):
64+
return "<View Scope=\"{0}\"><Query>{1}</Query></View>".format(self.Scope, str(self.Query))
65+
66+
567
class CamlQuery(ClientValue):
668

7-
def __init__(self, dates_in_utc=True, view_xml=None, listitem_collection_position=None,
69+
def __init__(self, dates_in_utc=True, view_xml=None, list_item_collection_position=None,
870
folder_server_relative_url=None, allow_incremental_results=True):
971
"""
1072
Specifies a Collaborative Application Markup Language (CAML) query on a list or joined lists.
1173
1274
:type bool allowIncrementalResults: Specifies whether the incremental results can be returned.
13-
:param ListItemCollectionPosition listitem_collection_position: Specifies the information required to
75+
:param ListItemCollectionPosition list_item_collection_position: Specifies the information required to
1476
get the next page of data for the list view.
1577
:param str view_xml: Specifies the XML schema that defines the list view.
1678
:param str or None folder_server_relative_url: Specifies the server-relative URL of a list folder from which
@@ -22,26 +84,20 @@ def __init__(self, dates_in_utc=True, view_xml=None, listitem_collection_positio
2284
self.FolderServerRelativeUrl = folder_server_relative_url
2385
self.AllowIncrementalResults = allow_incremental_results
2486
self.ViewXml = view_xml
25-
self.ListItemCollectionPosition = listitem_collection_position
87+
self.ListItemCollectionPosition = list_item_collection_position
2688

2789
@staticmethod
2890
def parse(query_expr, scope=ViewScope.DefaultValue):
2991
"""
30-
Initiates a CamlQuery object from a query expression
92+
Creates a CamlQuery object from a query expression
3193
32-
:type query_expr: str
33-
:type scope: ViewScope
94+
:param str query_expr: Defines the query for a view.
95+
:param ViewScope scope: Specifies whether and how files and subfolders are included in a view.
3496
"""
3597
qry = CamlQuery()
3698
qry.ViewXml = "<View Scope=\"{0}\"><Query>{1}</Query></View>".format(scope, query_expr)
3799
return qry
38100

39-
@staticmethod
40-
def create_custom_query(query):
41-
qry = CamlQuery()
42-
qry.ViewXml = query
43-
return qry
44-
45101
@staticmethod
46102
def create_all_items_query():
47103
return CamlQuery.parse("", ViewScope.RecursiveAll)
@@ -58,6 +114,9 @@ def create_all_files_query():
58114
qry_text = "<Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">0</Value></Eq></Where>"
59115
return CamlQuery.parse(qry_text, ViewScope.RecursiveAll)
60116

117+
def __repr__(self):
118+
return self.ViewXml
119+
61120
@property
62121
def entity_type_name(self):
63122
return 'SP.CamlQuery'

office365/sharepoint/publishing/pages/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def is_file_picker_external_image_search_enabled(context):
112112
113113
:param office365.sharepoint.client_context.ClientContext context: Client context
114114
"""
115-
result = ClientResult(context)
115+
return_type = ClientResult(context)
116116
svc = SitePageService(context)
117-
qry = ServiceOperationQuery(svc, "IsFilePickerExternalImageSearchEnabled", None, None, None, result, True)
117+
qry = ServiceOperationQuery(svc, "IsFilePickerExternalImageSearchEnabled", None, None, None, return_type, True)
118118
context.add_query(qry)
119-
return result
119+
return return_type
120120

121121
@staticmethod
122122
def org_assets(context):

office365/sharepoint/publishing/portallaunch/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class PortalLaunchWave(ClientValue):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.Publishing.PortalLaunch.PortalLaunchWave"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class WavesManager(BaseEntity):
5+
6+
@property
7+
def entity_type_name(self):
8+
return "SP.Publishing.PortalLaunch.WavesManager"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ProvisionedTemporaryAzureContainerInfo(ClientValue):
5+
pass

office365/sharepoint/sites/site.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from office365.sharepoint.recyclebin.item_collection import RecycleBinItemCollection
1616
from office365.sharepoint.sitehealth.summary import SiteHealthSummary
1717
from office365.sharepoint.sites.sph_site import SPHSite
18+
from office365.sharepoint.sites.azure_container_Info import ProvisionedTemporaryAzureContainerInfo
1819
from office365.sharepoint.sites.upgrade_info import UpgradeInfo
1920
from office365.sharepoint.sites.usage_info import UsageInfo
2021
from office365.sharepoint.tenant.administration.site_administrators_info import SiteAdministratorsInfo
@@ -319,6 +320,13 @@ def open_web_by_id(self, web_id):
319320
self.context.add_query(qry)
320321
return return_type
321322

323+
def provision_temporary_azure_container(self):
324+
""""""
325+
return_type = ClientResult(self.context, ProvisionedTemporaryAzureContainerInfo())
326+
qry = ServiceOperationQuery(self, "ProvisionTemporaryAzureContainer", None, None, None, return_type)
327+
self.context.add_query(qry)
328+
return return_type
329+
322330
def register_hub_site(self, create_info=None):
323331
"""Registers an existing site as a hub site.
324332
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
from office365.runtime.client_value import ClientValue
2+
from office365.runtime.client_value_collection import ClientValueCollection
3+
4+
5+
class CollaborativeUsers(ClientValue):
6+
7+
@property
8+
def entity_type_name(self):
9+
return "Microsoft.SharePoint.Administration.TenantAdmin.CollaborativeUsers"
210

311

412
class CollaborationInsightsData(ClientValue):
513

14+
def __init__(self, last_report_date=None, collaborative_users=None):
15+
"""
16+
:param str last_report_date:
17+
:param list[CollaborativeUsers] collaborative_users:
18+
"""
19+
self.collaborativeUsers = ClientValueCollection(CollaborativeUsers, collaborative_users)
20+
self.lastReportDate = last_report_date
21+
622
@property
723
def entity_type_name(self):
824
return "Microsoft.SharePoint.Administration.TenantAdmin.CollaborationInsightsData"

0 commit comments

Comments
 (0)