From d29d306377668d2e7ad2ab393f59faba1c44c3ba Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Thu, 2 May 2024 15:24:13 +0200 Subject: [PATCH] update add_list_item return type for sharepoint service --- gso/services/sharepoint.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gso/services/sharepoint.py b/gso/services/sharepoint.py index b4b412db..8547c3b3 100644 --- a/gso/services/sharepoint.py +++ b/gso/services/sharepoint.py @@ -46,14 +46,20 @@ class SPClient: .items.get(request_configuration=request_configuration) ) - async def add_list_item(self, list_name: str, fields: dict[str, str]): + async def add_list_item(self, list_name: str, fields: dict[str, str]) -> str: """Add a new entry to a SharePoint list. :param str list_name: The name of the list. :param dict[str, str] fields: Any pre-filled fields in the list item. Can be left empty. + + :return str: The URL of the list in which a new item has been created. """ request_body = ListItem(fields=FieldValueSet(additional_data=fields)) - return ( + new_item = ( await self.client.sites.by_site_id(self.site_id) - .lists.by_list_id(self.list_ids[list_name]).items.post(request_body) + .lists.by_list_id(self.list_ids[list_name]) + .items.post(request_body) ) + + # Strip the last part of the URL, since we want the link to the list, not the list item. + return new_item.web_url.rsplit("/", 1)[0] -- GitLab