Skip to content

Commit

Permalink
SharePoint API: taxonomy namespace updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jul 16, 2023
1 parent 60a3bf9 commit ab02fa9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
3 changes: 2 additions & 1 deletion examples/sharepoint/folders/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# folder_to_url = "Shared Documents/archive"

print("Moving folder...")
folder_to = folder_from.move_to_using_path(folder_to_parent).execute_query()
#folder_to = folder_from.move_to_using_path(folder_to_parent).execute_query()
folder_to = folder_from.move_to(folder_to_parent).execute_query()
print("Folder has been moved into '{0}'".format(folder_to.serverRelativeUrl))

print("Cleaning up temporary folders ...")
Expand Down
26 changes: 26 additions & 0 deletions examples/sharepoint/folders/move_alt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Demonstrates how to move a folder within a site
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.utilities.move_copy_options import MoveCopyOptions
from office365.sharepoint.utilities.move_copy_util import MoveCopyUtil
from tests import test_client_credentials, test_team_site_url, create_unique_name

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)


print("Creating a temporary folders in a Documents library ...")
folder_from = ctx.web.default_document_library().root_folder.add(create_unique_name("in")).execute_query()
path = "../../data/report.csv"
folder_from.files.upload(path).execute_query()
folder_to_url = "Shared Documents/{0}".format(create_unique_name("out"))

print("Moving folder...")
opt = MoveCopyOptions()
MoveCopyUtil.move_folder(ctx, folder_from.serverRelativeUrl, folder_to_url, opt).execute_query()
print("Folder has been moved into '{0}'".format(folder_to_url))

print("Cleaning up temporary resources ...")
folder_to = ctx.web.get_folder_by_server_relative_url(folder_to_url)
folder_to.delete_object().execute_query()
print("Done")
7 changes: 4 additions & 3 deletions examples/sharepoint/taxonomy/update_field_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
custom_list = ctx.web.add_list(create_unique_name("Custom List")).execute_query()


print("Adding a taxonomy field into list '{0}'...".format(custom_list.title))
term_set_id = "3b712032-95c4-4bb5-952d-f85ae9288f99"
tax_field = custom_list.fields.create_taxonomy_field("Country", term_set_id).execute_query()
Expand All @@ -18,9 +19,9 @@

print("Updating list item...")
item.set_property("Country", TaxonomyFieldValue("Sweden", "f9a6dae9-633c-474b-b35e-b235cf2b9e73"))
#item.set_property("Countries",
# TaxonomyFieldValueCollection([TaxonomyFieldValue("Sweden", "f9a6dae9-633c-474b-b35e-b235cf2b9e73")]))

item.set_property("Countries",
TaxonomyFieldValueCollection([TaxonomyFieldValue("Sweden", "f9a6dae9-633c-474b-b35e-b235cf2b9e73")]))
item.update().execute_query()

print("Cleaning up temporary resources...")
custom_list.delete_object().execute_query()
5 changes: 5 additions & 0 deletions office365/runtime/client_runtime_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def _process_response(resp):
action(*args, **kwargs)

self.pending_request().afterExecute += _process_response

execute_first = kwargs.pop("execute_first", False)
if execute_first and len(self._queries) > 1:
self._queries.insert(0, self._queries.pop())

return self

def after_execute(self, action, once=True, *args, **kwargs):
Expand Down
16 changes: 11 additions & 5 deletions office365/sharepoint/listitems/listitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def update_overwrite_version(self):

def set_comments_disabled(self, value):
"""
Sets the value of CommentsDisabled (section 3.2.5.87.1.1.8) for the item.
Sets the value of CommentsDisabled for the item.
:type value: bool
:param bool value: Indicates whether comments for this item are disabled or not.
"""
qry = ServiceOperationQuery(self, "SetCommentsDisabled", [value])
self.context.add_query(qry)
Expand Down Expand Up @@ -491,20 +491,26 @@ def _set_taxonomy_field_value(self, name, value):
def _tax_field_loaded():
tax_text_field = self.parent_list.fields.get_by_id(tax_field.properties["TextField"])

def _tax_text_field_loaded():
def _tax_text_field_loaded(return_type):
self.set_property(tax_text_field.properties["StaticName"], str(value))
tax_text_field.ensure_property("StaticName", _tax_text_field_loaded)
tax_text_field.select(["StaticName"]).get().after_execute(_tax_text_field_loaded, execute_first=True)

tax_field.ensure_property("TextField", _tax_field_loaded)

def ensure_type_name(self, target_list):
def ensure_type_name(self, target_list, action=None):
"""
Determine metadata annotation for ListItem entity
:param office365.sharepoint.lists.list.List target_list: List resource
:param () -> None action: Event handler
"""
if self._entity_type_name is None:
def _list_loaded():
self._entity_type_name = target_list.properties['ListItemEntityTypeFullName']
if callable(action):
action()
target_list.ensure_property("ListItemEntityTypeFullName", _list_loaded)
else:
if callable(action):
action()
return self
11 changes: 5 additions & 6 deletions office365/sharepoint/webhooks/subscription_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ def add(self, parameters):
return_type = Subscription(self.context)
self.add_child(return_type)

def _create_query(information):
def _create_and_add_query(information):
"""
:type information: SubscriptionInformation
"""
payload = {"parameters": information}
return ServiceOperationQuery(self, "Add", None, payload, None, return_type)
qry = ServiceOperationQuery(self, "Add", None, payload, None, return_type)
self.context.add_query(qry)

if isinstance(parameters, SubscriptionInformation):
qry = _create_query(parameters)
self.context.add_query(qry)
_create_and_add_query(parameters)
else:
def _parent_loaded():
next_qry = _create_query(SubscriptionInformation(parameters, self._parent.properties["Id"]))
self.context.add_query(next_qry)
_create_and_add_query(SubscriptionInformation(parameters, self._parent.properties["Id"]))
self._parent.ensure_property("Id", _parent_loaded)
return return_type

Expand Down
3 changes: 2 additions & 1 deletion office365/sharepoint/webs/context_web_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class ContextWebInformation(ClientValue):

def __init__(self, form_digest_value=None, form_digest_timeout_secs=None):
"""
:param str form_digest_value: Specifies a valid form digest for the site
:param str form_digest_value: An object that is inserted into a page and is used by a protocol server
to validate client requests. The validation is specific to a user, site, and time period.
:param int form_digest_timeout_secs: Specifies the amount of time in seconds before security validation expires.
"""
super(ContextWebInformation, self).__init__()
Expand Down
9 changes: 3 additions & 6 deletions tests/sharepoint/test_taxonomy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.fields.field import Field
from office365.sharepoint.taxonomy.field import TaxonomyField
from office365.sharepoint.taxonomy.groups.group import TermGroup
from office365.sharepoint.taxonomy.sets.set import TermSet
from office365.sharepoint.taxonomy.stores.store import TermStore
from office365.sharepoint.taxonomy.terms.term import Term
from tests import test_team_site_url, test_client_credentials
from tests.sharepoint.sharepoint_case import SPTestCase


Expand All @@ -17,7 +15,6 @@ class TestSPTaxonomy(SPTestCase):
@classmethod
def setUpClass(cls):
super(TestSPTaxonomy, cls).setUpClass()
team_ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)

@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -45,9 +42,9 @@ def test4_get_terms(self):
self.assertGreater(len(terms), 0)
self.assertIsInstance(terms[0], Term)

#def test5_search_term(self):
# result = self.tax_svc.term_store.search_term("Sweden").execute_query()
# self.assertIsNotNone(result.resource_path)
def test5_search_term(self):
result = self.client.taxonomy.term_store.search_term("Sweden").execute_query()
self.assertIsNotNone(result.resource_path)

def test6_create_list_tax_field(self):
term_set_id = "b49f64b3-4722-4336-9a5c-56c326b344d4"
Expand Down

0 comments on commit ab02fa9

Please sign in to comment.