From cd46e6cb9cba0f35a784fcbf448c6adeaa94e633 Mon Sep 17 00:00:00 2001 From: Alejandro Casanovas Date: Mon, 11 Nov 2019 17:16:00 +0100 Subject: [PATCH] Query: Fixed bug when filter on None. None should be treated as null. Drive: Added `get_child_folders` method on Drives and Folders --- O365/drive.py | 60 ++++++++++++++++++++++++++++++++++++++------- O365/utils/utils.py | 2 ++ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/O365/drive.py b/O365/drive.py index 36d6d46fa0e71..64206b9aa7a32 100644 --- a/O365/drive.py +++ b/O365/drive.py @@ -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: @@ -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 @@ -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: @@ -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 diff --git a/O365/utils/utils.py b/O365/utils/utils.py index c95d0a1c33002..206e9ccba78a4 100644 --- a/O365/utils/utils.py +++ b/O365/utils/utils.py @@ -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