Skip to content

Commit

Permalink
Query: Fixed bug when filter on None. None should be treated as null.
Browse files Browse the repository at this point in the history
Drive: Added `get_child_folders` method on Drives and Folders
  • Loading branch information
Alejandro Casanovas committed Nov 11, 2019
1 parent 7e193cb commit cd46e6c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
60 changes: 51 additions & 9 deletions O365/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,10 @@ def get_items(self, limit=None, *, query=None, order_by=None, batch=None):
params['$orderby'] = order_by

if query:
if query.has_filters:
warnings.warn('Filters are not allowed by the '
'Api Provider in this method')
query.clear_filters()
# if query.has_filters:
# warnings.warn('Filters are not allowed by the '
# 'Api Provider in this method')
# query.clear_filters()
if isinstance(query, str):
params['$filter'] = query
else:
Expand All @@ -1034,6 +1034,27 @@ def get_items(self, limit=None, *, query=None, order_by=None, batch=None):
else:
return items

def get_child_folders(self, limit=None, *, query=None, order_by=None, batch=None):
""" Returns all the folders inside this folder
:param int limit: max no. of folders to get. Over 999 uses batch.
:param query: applies a OData filter to the request
:type query: Query or str
:param order_by: orders the result set based on this condition
:type order_by: Query or str
:param int batch: batch size, retrieves items in
batches allowing to retrieve more items than the limit.
:return: list of items in this folder
:rtype: list[DriveItem] or Pagination
"""

if query:
query = query.on_attribute('folder').unequal(None)
else:
query = self.q('folder').unequal(None)

return self.get_items(limit=limit, query=query, order_by=order_by, batch=batch)

def create_child_folder(self, name, description=None):
""" Creates a Child Folder
Expand Down Expand Up @@ -1364,11 +1385,11 @@ def _base_get_list(self, url, limit=None, *, query=None, order_by=None,
params['$orderby'] = order_by

if query:
if query.has_filters:
warnings.warn(
'Filters are not allowed by the Api Provider '
'in this method')
query.clear_filters()
# if query.has_filters:
# warnings.warn(
# 'Filters are not allowed by the Api Provider '
# 'in this method')
# query.clear_filters()
if isinstance(query, str):
params['$filter'] = query
else:
Expand Down Expand Up @@ -1417,6 +1438,27 @@ def get_items(self, limit=None, *, query=None, order_by=None, batch=None):
return self._base_get_list(url, limit=limit, query=query,
order_by=order_by, batch=batch)

def get_child_folders(self, limit=None, *, query=None, order_by=None, batch=None):
""" Returns all the folders inside this folder
:param int limit: max no. of folders to get. Over 999 uses batch.
:param query: applies a OData filter to the request
:type query: Query or str
:param order_by: orders the result set based on this condition
:type order_by: Query or str
:param int batch: batch size, retrieves items in
batches allowing to retrieve more items than the limit.
:return: list of items in this folder
:rtype: list[DriveItem] or Pagination
"""

if query:
query = query.on_attribute('folder').unequal(None)
else:
query = self.q('folder').unequal(None)

return self.get_items(limit=limit, query=query, order_by=order_by, batch=batch)

def get_recent(self, limit=None, *, query=None, order_by=None, batch=None):
""" Returns a collection of recently used DriveItems
Expand Down
2 changes: 2 additions & 0 deletions O365/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ def _parse_filter_word(self, word):
word.isoformat()) # convert datetime to isoformat
elif isinstance(word, bool):
word = str(word).lower()
elif word is None:
word = 'null'
return word

@staticmethod
Expand Down

0 comments on commit cd46e6c

Please sign in to comment.