Skip to content

Commit ef216aa

Browse files
vvgrem@gmail.comvvgrem@gmail.com
vvgrem@gmail.com
authored and
vvgrem@gmail.com
committed
SharePoint API: support for documentset entity (create method)
1 parent 0676002 commit ef216aa

File tree

14 files changed

+104
-9
lines changed

14 files changed

+104
-9
lines changed

examples/sharepoint/lists_and_items/read_attachments.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
import tempfile
33

4+
45
from settings import settings
56

67
from office365.runtime.auth.client_credential import ClientCredential
78
from office365.sharepoint.client_context import ClientContext
8-
from office365.sharepoint.listitems.caml import CamlQuery
9+
from office365.sharepoint.listitems.caml.caml_query import CamlQuery
910

1011
download_path = tempfile.mkdtemp()
1112

@@ -14,7 +15,10 @@
1415
ctx = ClientContext(settings['url']).with_credentials(client_creds)
1516

1617
list_obj = ctx.web.lists.get_by_title("Tasks123")
17-
items = list_obj.get_items(CamlQuery.create_all_items_query())
18+
#items = list_obj.get_items(CamlQuery.create_all_items_query())
19+
#items = list_obj.get_items()
20+
items = list_obj.items
21+
ctx.load(items, ["ID", "UniqueId", "FileRef", "LinkFilename", "Title", "Attachments"])
1822
ctx.execute_query()
1923
for item in items:
2024
if item.properties['Attachments']: # 1. determine whether ListItem contains attachments
@@ -28,3 +32,4 @@
2832
with open(download_file_name, 'wb') as fh:
2933
content = attachment_file.read()
3034
fh.write(content)
35+
print(f"{attachment_file.server_relative_url} has been downloaded")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import ast
2+
3+
4+
class PropertyBuilder(ast.NodeTransformer):
5+
pass

generator/builders/type_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def generic_visit(self, node):
1919
def build(self, schema):
2020
result = dict(status=None, output_file=None, source_tree=None)
2121
if schema['state'] == 'attached':
22-
result.output_file = schema['file']
22+
result["output_file"] = schema['file']
2323
with open(schema['file']) as f:
2424
result["source_tree"] = ast.parse(f.read())
2525
result["status"] = "updated"

generator/templates/complex_type.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33

44
class ComplexType(ClientValue):
5-
pass
5+
6+
def __init__(self):
7+
super().__init__()

office365/onedrive/file_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22

3+
from office365.actions.upload_content_query import UploadContentQuery
34
from office365.onedrive.driveItemUploadableProperties import DriveItemUploadableProperties
45
from office365.runtime.http.http_method import HttpMethod
56
from office365.runtime.http.request_options import RequestOptions
6-
from office365.actions.upload_content_query import UploadContentQuery
77

88

99
def read_in_chunks(file_object, chunk_size=1024):

office365/sharepoint/documentmanagement/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from office365.runtime.http.http_method import HttpMethod
2+
from office365.runtime.http.request_options import RequestOptions
3+
from office365.sharepoint.base_entity import BaseEntity
4+
5+
6+
class DocumentSet(BaseEntity):
7+
8+
@staticmethod
9+
def create(context, parentFolder, name, ctid="0x0120D520"):
10+
"""Creates a new DocumentSet object.
11+
12+
:type context: office365.sharepoint.client_context.ClientContext
13+
:type parentFolder: office365.sharepoint.folders.folder.Folder
14+
:type name: str
15+
:type ctid: office365.sharepoint.contenttypes.content_type_id.ContentTypeId
16+
"""
17+
result = DocumentSet(context)
18+
19+
def _create_doc_set():
20+
21+
url = r"{0}/_vti_bin/listdata.svc/{1}".format(context.base_url,
22+
parentFolder.properties["Name"].replace(" ", ""))
23+
request = RequestOptions(url)
24+
request.method = HttpMethod.Post
25+
folder_url = parentFolder.serverRelativeUrl + '/' + name
26+
request.set_header('Slug', '{0}|{1}'.format(folder_url, ctid))
27+
response = context.execute_request_direct(request)
28+
json = response.json()
29+
context.pending_request().map_json(json, result)
30+
31+
parentFolder.ensure_properties(["ServerRelativeUrl", "Name"], _create_doc_set)
32+
return result

office365/sharepoint/social/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_object import ClientObject
2+
3+
4+
class SocialRestActor(ClientObject):
5+
pass
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
from office365.runtime.client_object import ClientObject
2+
from office365.runtime.queries.service_operation_query import ServiceOperationQuery
23

34

45
class UserProfile(ClientObject):
5-
pass
6+
7+
def create_personal_site_enque(self, isInteractive):
8+
"""
9+
Enqueues creating a personal site for this user, which can be used to share documents, web pages,
10+
and other files.
11+
12+
:type isInteractive: bool
13+
"""
14+
payload = {"isInteractive": isInteractive}
15+
qry = ServiceOperationQuery(self, "CreatePersonalSiteEnque", None, payload, None, None)
16+
self.context.add_query(qry)
17+
return self

tests/graph_case.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest import TestCase
22

33
import adal
4-
54
from settings import settings
65

76
from office365.graph_client import GraphClient

tests/sharepoint/test_document_set.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from tests import random_seed
2+
from tests.sharepoint.sharepoint_case import SPTestCase
3+
4+
from office365.sharepoint.documentmanagement.document_set import DocumentSet
5+
from office365.sharepoint.lists.list import List
6+
from office365.sharepoint.lists.list_creation_information import ListCreationInformation
7+
from office365.sharepoint.lists.list_template_type import ListTemplateType
8+
9+
10+
class TestSharePointDocumentSet(SPTestCase):
11+
target_lib = None # type: List
12+
13+
@classmethod
14+
def setUpClass(cls):
15+
super(TestSharePointDocumentSet, cls).setUpClass()
16+
cls.target_lib = cls.ensure_list(cls.client.web,
17+
ListCreationInformation(
18+
"Archive Documents N%s" % random_seed,
19+
None,
20+
ListTemplateType.DocumentLibrary))
21+
22+
@classmethod
23+
def tearDownClass(cls):
24+
cls.target_lib.delete_object().execute_query()
25+
26+
def test1_create_document_set(self):
27+
name = "DocSet"
28+
doc_set = DocumentSet.create(self.client, self.target_lib.rootFolder, name)
29+
self.client.execute_query()
30+
self.assertEqual(doc_set.properties["Name"], name)

tests/sharepoint/test_user_profile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from office365.sharepoint.userprofiles.profileLoader import ProfileLoader
21
from tests.sharepoint.sharepoint_case import SPTestCase
32

3+
from office365.sharepoint.userprofiles.profileLoader import ProfileLoader
4+
45

56
class TestUserProfile(SPTestCase):
67
profile_loader = None # type: ProfileLoader
@@ -12,3 +13,7 @@ def test1_get_profile_loader(self):
1213
def test2_get_profile_loader(self):
1314
user_profile = self.__class__.profile_loader.get_user_profile().execute_query()
1415
self.assertIsNotNone(user_profile.properties["AccountName"])
16+
17+
def test3_create_personal_site(self):
18+
user_profile = self.__class__.profile_loader.get_user_profile()
19+
user_profile.create_personal_site_enque(True).execute_query()

tests/teams/test_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test5_get_primary_channel(self):
5151
primary_channel = self.__class__.target_team.primaryChannel.get().execute_query()
5252
self.assertIsNotNone(primary_channel.resource_path)
5353

54-
#def test6_get_channel_files_location(self):
54+
# def test6_get_channel_files_location(self):
5555
# drive_item = self.__class__.target_channel.filesFolder.get().execute_query()
5656
# self.assertIsNotNone(drive_item.resource_path)
5757

0 commit comments

Comments
 (0)