Skip to content

Commit af9d90d

Browse files
vvgrem@gmail.comvvgrem@gmail.com
authored andcommitted
SharePoint API: new types and methods
1 parent d559b3c commit af9d90d

File tree

81 files changed

+542
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+542
-134
lines changed

examples/sharepoint/files/upload_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
file_content = content_file.read()
1515

1616
list_title = "Documents"
17-
target_folder = ctx.web.lists.get_by_title(list_title).rootFolder
17+
target_folder = ctx.web.lists.get_by_title(list_title).root_folder
1818
name = os.path.basename(path)
1919
target_file = target_folder.upload_file(name, file_content)
2020
ctx.execute_query()

examples/sharepoint/folders/download_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
settings['client_credentials']['client_secret']))
1212

1313
# retrieve files from library
14-
files = ctx.web.lists.get_by_title("Documents").rootFolder.files
14+
files = ctx.web.lists.get_by_title("Documents").root_folder.files
1515
ctx.load(files)
1616
ctx.execute_query()
1717
download_path = tempfile.mkdtemp()

examples/sharepoint/lists_and_items/data_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def generate_documents(context):
3333
for idx in range(0, total_amount):
3434
# 1. Create a folder
3535
folder_name = fake.date()
36-
target_folder = lib.rootFolder.add(folder_name)
36+
target_folder = lib.root_folder.add(folder_name)
3737
context.execute_query()
3838
print("({0} of {1}) Folder '{2}' has been created".format(idx, total_amount, target_folder.serverRelativeUrl))
3939

examples/sharepoint/lists_and_items/read_attachments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
for item in items:
2323
if item.properties['Attachments']: # 1. determine whether ListItem contains attachments
2424
# 2. Explicitly load attachments for ListItem
25-
attachment_files = item.attachmentFiles
25+
attachment_files = item.attachment_files
2626
ctx.load(attachment_files)
2727
ctx.execute_query()
2828
# 3. Enumerate and save attachments
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import time
2+
from settings import settings
3+
from office365.runtime.auth.client_credential import ClientCredential
4+
from office365.sharepoint.client_context import ClientContext
5+
6+
7+
def process_site(context):
8+
target_web = context.web
9+
target_web.set_property("Description", "DEV site").update().get().execute_query()
10+
print(target_web.url)
11+
12+
13+
credentials = ClientCredential(settings.get('client_credentials').get('client_id'),
14+
settings.get('client_credentials').get('client_secret'))
15+
ctx = ClientContext(settings['url']).with_credentials(credentials)
16+
17+
if __name__ == '__main__':
18+
while 1:
19+
print(f"{time.ctime()}: Processing site")
20+
process_site(ctx)
21+
time.sleep(10)

office365/sharepoint/alerts/__init__.py

Whitespace-only changes.

office365/sharepoint/alerts/alert.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.sharepoint.base_entity import BaseEntity
2+
3+
4+
class Alert(BaseEntity):
5+
pass
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from office365.runtime.client_object_collection import ClientObjectCollection
2+
from office365.runtime.queries.service_operation_query import ServiceOperationQuery
3+
from office365.sharepoint.alerts.alert import Alert
4+
5+
6+
class AlertCollection(ClientObjectCollection):
7+
"""Content Type resource collection"""
8+
9+
def __init__(self, context, resource_path=None):
10+
super(AlertCollection, self).__init__(context, Alert, resource_path)
11+
12+
def add(self, parameters):
13+
"""
14+
15+
:type parameters: office365.sharepoint.alerts.alert_creation_information.AlertCreationInformation
16+
"""
17+
alert = Alert(self.context, None)
18+
self.add_child(alert)
19+
qry = ServiceOperationQuery(self, "Add", None, parameters, "alertCreationInformation", alert)
20+
self.context.add_query(qry)
21+
return alert
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class AlertCreationInformation(ClientValue):
5+
6+
def __init__(self, alert_frequency, template_name, alert_type):
7+
super().__init__()
8+
self.AlertFrequency = alert_frequency
9+
self.AlertTemplateName = template_name
10+
self.AlertType = alert_type
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class ChangeLogItemQuery(ClientValue):
5+
6+
def __init__(self, change_token=None, contains=None, row_limit=None):
7+
"""
8+
9+
:type change_token: str
10+
:type contains: str
11+
:type row_limit: str
12+
"""
13+
super().__init__()
14+
self.ChangeToken = change_token
15+
self.Contains = contains
16+
self.RowLimit = row_limit
17+
18+
@property
19+
def entity_type_name(self):
20+
return 'SP.ChangeLogItemQuery'

0 commit comments

Comments
 (0)