|
| 1 | +from office365.sharepoint.client_context import ClientContext |
| 2 | +from office365.sharepoint.fields.field_creation_information import FieldCreationInformation |
| 3 | +from office365.sharepoint.fields.field_multi_user_value import FieldMultiUserValue |
| 4 | +from office365.sharepoint.fields.field_type import FieldType |
| 5 | +from office365.sharepoint.fields.field_user_value import FieldUserValue |
| 6 | +from office365.sharepoint.lists.list_creation_information import ListCreationInformation |
| 7 | +from office365.sharepoint.lists.list_template_type import ListTemplateType |
| 8 | +from tests import create_unique_name, test_site_url, test_client_credentials, test_user_principal_name |
| 9 | + |
| 10 | + |
| 11 | +def create_tasks_list(client): |
| 12 | + """ |
| 13 | +
|
| 14 | + :type client: ClientContext |
| 15 | + """ |
| 16 | + list_title = create_unique_name("Tasks N") |
| 17 | + list_create_info = ListCreationInformation(list_title, |
| 18 | + None, |
| 19 | + ListTemplateType.TasksWithTimelineAndHierarchy) |
| 20 | + |
| 21 | + target_list = client.web.lists.add(list_create_info).execute_query() |
| 22 | + field_info = FieldCreationInformation("Manager", FieldType.User) |
| 23 | + user_field = target_list.fields.add(field_info).execute_query() |
| 24 | + return target_list |
| 25 | + |
| 26 | + |
| 27 | +ctx = ClientContext(test_site_url).with_credentials(test_client_credentials) |
| 28 | +tasks_list = create_tasks_list(ctx) |
| 29 | + |
| 30 | +#user = ctx.web.current_user.get().execute_query() |
| 31 | +user = ctx.web.ensure_user(test_user_principal_name) |
| 32 | +multi_user_value = FieldMultiUserValue() |
| 33 | +multi_user_value.add(FieldUserValue.from_user(user)) |
| 34 | + |
| 35 | +item_to_create = tasks_list.add_item({ |
| 36 | + "Title": "New Task", |
| 37 | + "AssignedTo": multi_user_value, |
| 38 | + "Manager": FieldUserValue.from_user(user) |
| 39 | +}).execute_query() |
| 40 | + |
| 41 | +multi_user_value_alt = FieldMultiUserValue() |
| 42 | +multi_user_value_alt.add(FieldUserValue(user.id)) |
| 43 | + |
| 44 | +item_to_create_alt = tasks_list.add_item({ |
| 45 | + "Title": "New Task 2", |
| 46 | + "AssignedTo": multi_user_value_alt |
| 47 | +}).execute_query() |
| 48 | + |
0 commit comments