python-o365
python-o365 copied to clipboard
Sharepoint listitem from driveitem
I would like to be able to update custom column data on a file in Sharepoint. According to the docstring in drive.DriveItem.update, it isn't possible through the DriveItem object so I believe I need to do it through a ListItem object.
def update(self, **kwargs):
""" Updates this item
:param kwargs: all the properties to be updated.
only name and description are allowed at the moment.
:return: Success / Failure
:rtype: bool
"""
I can get the DriveItem corresponding to the document's path. Looking at the Sharepoint graph api, a driveitem resource has the ability to get its corresponding listitem via /items/{item-id}/listitem. I don't see this capability in the O365 Sharepoint module so I am trying to add it (I will submit a MR when it is working). I am just getting familiar with this module and looking for some advice on how to proceed.
My plan is to add a new endpoint to drive.DriveItem._endpoints for listitem.
_endpoints = {
# all prefixed with /drives/{drive_id} on main_resource by default
'list_items': '/items/{id}/children',
'listitem': '/items/{item_id}/listitem',
...
}
Next, add a function to get the listitem in drive.DriveItem. I don't have the parent list so I believe I need to pass conn and protocol.
""" Returns a DriveItem's listitem by it's Id
:return: one item
:rtype: ListItem
"""
if self.object_id:
# reference the current drive_id
url = self.build_url(
self._endpoints.get('listitem').format(item_id=item_id))
response = self.con.get(url)
if not response:
return None
data = response.json()
# Everything received from cloud must be passed as self._cloud_data_key
return SharepointListItem(data)(con=self.con, protocol=self.protocol,
**{self._cloud_data_key: data})
I then need to add the SharepointListItem import. However, when I do that, I get a circular import error.
ImportError: cannot import name 'SharepointListItem' from partially initialized module 'O365.sharepoint' (most likely due to a circular import) (C:\Users\kgray\AppData\Local\pypoetry\Cache\virtualenvs\sharepoint-attributes-KZVL1wbE-py3.9\lib\site-packages\O365\sharepoint.py)
Does anyone have any suggestions how to to do this?
This is a regular python error when you are having a circular import (Module 'a' imports module 'b' imports module 'a' again) Most likely you can simply look up the parents of the module to find the module that you want to import and make provisions so as to use it in your new module