Skip to content

Commit

Permalink
examples refactorings and type hints enhancements for taxonomy namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Oct 11, 2023
1 parent b42422d commit 2a00994
Show file tree
Hide file tree
Showing 20 changed files with 754 additions and 81 deletions.
13 changes: 13 additions & 0 deletions examples/sharepoint/fields/create_calculated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Creates calculated site field
"""
from office365.sharepoint.client_context import ClientContext
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
field_name = create_unique_name("CalcColumn")
formula = '=CONCATENATE(Author,":",Created)'
field = client.web.fields.add_calculated(field_name, formula).execute_query()

print("Field {0} has been created".format(field.internal_name))
field.delete_object().execute_query() # clean up
6 changes: 3 additions & 3 deletions examples/sharepoint/fields/create_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
lookup_list = client.web.default_document_library()

lookup_field = client.web.fields.add_lookup_field(
field = client.web.fields.add_lookup_field(
title=field_name,
lookup_list=lookup_list,
lookup_field_name="Title",
allow_multiple_values=True,
).execute_query()
print(f"Field {lookup_field.internal_name} has been created")
lookup_field.delete_object().execute_query()
print("Field {0} has been created", field.internal_name)
field.delete_object().execute_query() # clean up
15 changes: 15 additions & 0 deletions examples/sharepoint/fields/create_taxonomy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Demonstrates how to create a site field of type Taxonomy
"""

from office365.sharepoint.client_context import ClientContext
from tests import create_unique_name, test_client_credentials, test_team_site_url

client = ClientContext(test_team_site_url).with_credentials(test_client_credentials)

# term_sets = client.taxonomy.term_store.get_term_sets_by_name("Sweden").execute_query()

# field_name = create_unique_name("TaxColumn")
# field = client.web.fields.create_taxonomy_field(field_name).execute_query()
# print("Field {0} has been created".format(field.internal_name))
# field.delete_object().execute_query() # clean up
4 changes: 3 additions & 1 deletion examples/sharepoint/taxonomy/export_tax.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
"""
import json

from office365.sharepoint.client_context import ClientContext
Expand All @@ -7,7 +10,6 @@
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)

store = ctx.taxonomy.term_store.get().execute_query()

term_groups = ctx.taxonomy.term_store.term_groups.get_all().execute_query()
for term_group in term_groups: # type: TermGroup
term_sets = term_group.term_sets.get_all().execute_query()
Expand Down
3 changes: 1 addition & 2 deletions examples/sharepoint/taxonomy/get_term_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"""

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.taxonomy.sets.set import TermSet
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
term_group = ctx.taxonomy.term_store.term_groups.get_by_name("Geography")
term_sets = term_group.get_term_sets_by_name("Countries").execute_query()
for ts in term_sets: # type: TermSet
for ts in term_sets:
print(ts.id)
3 changes: 1 addition & 2 deletions examples/sharepoint/taxonomy/search_term.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.taxonomy.terms.term import Term
from tests import test_client_credentials, test_team_site_url

term_name = "Sweden"

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
terms = ctx.taxonomy.term_store.search_term(term_name).execute_query()
for term in terms: # type: Term
for term in terms:
print(term.labels[0])
3 changes: 1 addition & 2 deletions examples/sharepoint/taxonomy/set_field_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
)
from tests import create_unique_name, test_client_credentials, test_team_site_url

print("Creating a custom list...")
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)


print("Creating a custom list...")
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))
Expand Down
6 changes: 4 additions & 2 deletions examples/sharepoint/views/read_custom.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""
Reads custom List View items
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
view = ctx.web.default_document_library().views.get_by_title("All Documents")
items = view.get_items().expand(["Author"]).execute_query()
for item in items: # type: ListItem
for item in items:
print(item.properties)
3 changes: 1 addition & 2 deletions examples/sharepoint/views/read_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
Read list items from a default view
"""
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.listitems.listitem import ListItem
from tests import test_client_credentials, test_team_site_url

ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials)
lib = ctx.web.default_document_library()
items = lib.default_view.get_items().execute_query()
for item in items: # type: ListItem
for item in items:
print(item.properties)
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def export_to_file(path, content):
"--endpoint",
dest="endpoint",
help="Import metadata endpoint",
default="sharepoint",
default="microsoftgraph",
)
parser.add_argument(
"-p",
"--path",
dest="path",
default="./metadata/SharePoint.xml",
default="./metadata/MicrosoftGraph.xml",
help="Import metadata endpoint",
)

Expand Down

0 comments on commit 2a00994

Please sign in to comment.