Skip to content

Commit 590377e

Browse files
committed
SharePoint API list namespace updates
1 parent f807a0d commit 590377e

17 files changed

+290
-48
lines changed

examples/sharepoint/files/get_file_properties.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
file_url = '/sites/team/Shared Documents/big_buck_bunny.mp4'
88
file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query()
99

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

1314
# or directly via object properties
1415
print("file size: ", file.length)
1516
print("file name: ", file.name)
17+
18+
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
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

45
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
5-
tasks_list = ctx.web.lists.get_by_title("Tasks")
6+
tasks_list = ctx.web.lists.get_by_title("Company Tasks")
67
items = tasks_list.items.get().select(["*", "Author/Id", "Author/Title", "Editor/Title"]).expand(["Author", "Editor"]).execute_query()
7-
for item in items:
8+
for item in items: # type:ListItem
89
print("{0}".format(item.properties.get('Author').get("Title")))
9-

examples/sharepoint/lists/read_list.py

-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55

66
target_list = ctx.web.lists.get_by_title("Site Pages").get().execute_query()
77
print("List title: {0}".format(target_list.title))
8-
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from office365.sharepoint.client_context import ClientContext
22
from office365.sharepoint.listitems.caml.query import CamlQuery
3+
from office365.sharepoint.listitems.listitem import ListItem
34
from tests import test_client_credentials, test_team_site_url
45

56

6-
def print_progress(items_read):
7-
print("Items read: {0}".format(items_read))
8-
9-
107
def create_paged_query(page_size):
118
qry = CamlQuery()
129
qry.ViewXml = f"""
@@ -19,10 +16,9 @@ def create_paged_query(page_size):
1916

2017

2118
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
22-
target_list = ctx.web.lists.get_by_title("Tasks")
19+
target_list = ctx.web.lists.get_by_title("Contacts_Large")
2320
list_qry = create_paged_query(50)
2421
items = target_list.get_items(list_qry).execute_query()
2522
print("Loaded items count: {0}".format(len(items)))
26-
for index, item in enumerate(items):
27-
pass
28-
#print("{0}: {1}".format(index, item.properties['Title']))
23+
for index, item in enumerate(items): # type: int, ListItem
24+
print("{0}: {1}".format(index, item.properties['Title']))

office365/sharepoint/contenttypes/content_type.py

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def group(self, value):
9595
@property
9696
def schema_xml(self):
9797
"""Specifies the XML schema that represents the content type.
98+
9899
:rtype: str or None
99100
"""
100101
return self.properties.get("SchemaXml", None)

office365/sharepoint/listitems/caml/query.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def __init__(self, dates_in_utc=True, view_xml=None, listitem_collection_positio
2727
@staticmethod
2828
def parse(query_expr, scope=ViewScope.DefaultValue):
2929
"""
30-
Construct CamlQuery object from expression
30+
Initiates a CamlQuery object from a query expression
31+
3132
:type query_expr: str
3233
:type scope: ViewScope
3334
"""
@@ -47,11 +48,13 @@ def create_all_items_query():
4748

4849
@staticmethod
4950
def create_all_folders_query():
51+
"""Constructs a query to return folder objects"""
5052
qry_text = "<Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">1</Value></Eq></Where>"
5153
return CamlQuery.parse(qry_text, ViewScope.RecursiveAll)
5254

5355
@staticmethod
5456
def create_all_files_query():
57+
"""Constructs a query to return file objects"""
5558
qry_text = "<Where><Eq><FieldRef Name=\"FSObjType\" /><Value Type=\"Integer\">0</Value></Eq></Where>"
5659
return CamlQuery.parse(qry_text, ViewScope.RecursiveAll)
5760

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ListItemComplianceInfo(ClientValue):
5+
6+
def __init__(self, compliance_tag=None, tag_policy_event_based=None, tag_policy_hold=None, tag_policy_record=None):
7+
"""
8+
:param str compliance_tag:
9+
:param bool tag_policy_event_based:
10+
:param bool tag_policy_hold:
11+
:param bool tag_policy_record:
12+
"""
13+
self.ComplianceTag = compliance_tag
14+
self.TagPolicyEventBased = tag_policy_event_based
15+
self.TagPolicyHold = tag_policy_hold
16+
self.TagPolicyRecord = tag_policy_record

office365/sharepoint/listitems/creation_information.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33

44
class ListItemCreationInformation(ClientValue):
55

6-
def __init__(self, leafName=None, folderUrl=None, underlyingObjectType=None):
6+
def __init__(self, leaf_name=None, folder_url=None, underlying_object_type=None):
77
"""
88
Specifies the properties of the new list item.
99
10-
:param int underlyingObjectType: Specifies whether the new list item is a file or a folder.
11-
:param str leafName: Specifies the name of the new list item. It MUST be the name of the file if the parent
10+
:param int underlying_object_type: Specifies whether the new list item is a file or a folder.
11+
:param str leaf_name: Specifies the name of the new list item. It MUST be the name of the file if the parent
1212
list of the list item is a document library.
13-
:param str folderUrl: Specifies the folder for the new list item. It MUST be NULL, empty, a server-relative
13+
:param str folder_url: Specifies the folder for the new list item. It MUST be NULL, empty, a server-relative
1414
URL, or an absolute URL. If the value is a server-relative URL or an absolute URL, it MUST be under the root
1515
folder of the list.
16-
17-
18-
1916
"""
2017
super(ListItemCreationInformation, self).__init__()
21-
self.FolderUrl = folderUrl
22-
self.LeafName = leafName
23-
self.UnderlyingObjectType = underlyingObjectType
18+
self.FolderUrl = folder_url
19+
self.LeafName = leaf_name
20+
self.UnderlyingObjectType = underlying_object_type

office365/sharepoint/listitems/listitem.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from office365.sharepoint.fields.lookup_value import FieldLookupValue
1111
from office365.sharepoint.fields.multi_lookup_value import FieldMultiLookupValue
1212
from office365.sharepoint.likes.liked_by_information import LikedByInformation
13+
from office365.sharepoint.listitems.compliance_info import ListItemComplianceInfo
1314
from office365.sharepoint.listitems.form_update_value import ListItemFormUpdateValue
1415
from office365.sharepoint.listitems.version import ListItemVersion
1516
from office365.sharepoint.permissions.securable_object import SecurableObject
@@ -350,6 +351,8 @@ def field_values(self):
350351
@property
351352
def comments_disabled(self):
352353
"""
354+
Indicates whether comments for this item are disabled or not.
355+
353356
:rtype: bool or None
354357
"""
355358
return self.properties.get("CommentsDisabled", None)
@@ -358,6 +361,7 @@ def comments_disabled(self):
358361
def file_system_object_type(self):
359362
"""
360363
Gets a value that specifies whether the list item is a file or a list folder.
364+
361365
:rtype: str or None
362366
"""
363367
return self.properties.get("FileSystemObjectType", None)
@@ -366,15 +370,19 @@ def file_system_object_type(self):
366370
def id(self):
367371
"""
368372
Gets a value that specifies the list item identifier.
373+
369374
:rtype: int
370375
"""
371376
return self.properties.get("Id", None)
372377

378+
@property
379+
def compliance_info(self):
380+
return self.properties.get("ComplianceInfo", ListItemComplianceInfo())
381+
373382
@property
374383
def liked_by_information(self):
375384
"""
376385
Gets a value that specifies the list item identifier.
377-
:rtype: LikedByInformation
378386
"""
379387
return self.properties.get("LikedByInformation",
380388
LikedByInformation(self.context,
@@ -392,6 +400,7 @@ def get_property(self, name, default_value=None):
392400
property_mapping = {
393401
"AttachmentFiles": self.attachment_files,
394402
"ContentType": self.content_type,
403+
"ComplianceInfo": self.compliance_info,
395404
"EffectiveBasePermissions": self.effective_base_permissions,
396405
"LikedByInformation": self.liked_by_information,
397406
"ParentList": self.parent_list,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from office365.runtime.client_value import ClientValue
2+
from office365.runtime.client_value_collection import ClientValueCollection
3+
4+
5+
class CreatableItemInfo(ClientValue):
6+
"""
7+
Information on a creatable item: what the item is and where to go to create it. Alternatively, the information
8+
provided here can be used to call CreateDocument (section 3.2.5.79.2.2.9) or
9+
CreateDocumentAndGetEditLink (section 3.2.5.79.2.1.13).
10+
"""
11+
12+
13+
class CreatableItemInfoCollection(ClientValue):
14+
"""Represents a collection of CreatableItemInfo (section 3.2.5.283) objects."""
15+
16+
def __init__(self, items=None):
17+
"""
18+
:param list[CreatableItemInfo] items:
19+
"""
20+
super(CreatableItemInfoCollection, self).__init__()
21+
self.Items = ClientValueCollection(CreatableItemInfo, items)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
from office365.sharepoint.lists.creatable_item_info import CreatableItemInfoCollection
3+
4+
5+
class CreatablesInfo(BaseEntity):
6+
"""
7+
Returns an object that describes what this list can create, and a collection of links to visit in order to create
8+
those things. If it can't create certain things, it contains an error message describing why.
9+
10+
The consumer MUST append the encoded URL of the current page to the links returned here.
11+
(This page the link goes to needs it as a query parameter to function correctly.) The consumer SHOULD also consider
12+
appending &IsDlg=1 to the link, to remove the UI from the linked page, if desired.
13+
"""
14+
15+
@property
16+
def can_create_folders(self):
17+
"""
18+
Indicates if the user is able to create folders in the current list. The user MUST have the appropriate
19+
permissions and the list MUST allow folder creation.
20+
21+
:rtype: bool or None
22+
"""
23+
return self.properties.get("CanCreateFolders", None)
24+
25+
@property
26+
def can_create_items(self):
27+
"""
28+
Indicates whether this list can create items (such as documents (Word/Excel/PowerPoint))
29+
using Microsoft Office Online.
30+
31+
:rtype: bool or None
32+
"""
33+
return self.properties.get("CanCreateItems", None)
34+
35+
@property
36+
def can_upload_files(self):
37+
"""
38+
Indicates whether the user is able to upload files to this list.
39+
40+
:rtype: bool or None
41+
"""
42+
return self.properties.get("CanUploadFiles", None)
43+
44+
@property
45+
def creatables_collection(self):
46+
"""
47+
Represents a collection of CreatableItemInfo (section 3.2.5.283) objects describing what can be created,
48+
one CreatableItemInfo for each creatable type.
49+
"""
50+
return self.properties.get("CreatablesCollection", CreatableItemInfoCollection())
51+
52+
def get_property(self, name, default_value=None):
53+
if default_value is None:
54+
property_mapping = {
55+
"CreatablesCollection": self.creatables_collection
56+
}
57+
default_value = property_mapping.get(name, None)
58+
return super(CreatablesInfo, self).get_property(name, default_value)

office365/sharepoint/lists/creation_information.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def __init__(self, title=None, description=None, base_template=None, allow_conte
99
1010
:type base_template: int or None
1111
:type allow_content_types: bool
12-
:type description: str or None
13-
:type title: str
12+
:poram str or None description: Specifies the description of the new list.
13+
:param str title: Specifies the display name of the new list.
1414
"""
1515
super(ListCreationInformation, self).__init__()
1616
self.Title = title
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class DocumentTemplateType:
2+
"""Specifies the type for the document template (1) for the new list."""
3+
4+
Invalid = 0
5+
"""Invalid document template."""
6+
7+
Word = 1
8+
"""Word template."""
9+
10+
Excel = 2
11+
"""Excel template."""

0 commit comments

Comments
 (0)