From 992e7e11c1a23318d1ad9d725d1224a4b11ae910 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sat, 7 Sep 2019 20:27:40 -0700 Subject: [PATCH 1/2] Dropbox: add configurable timeout and improve docs --- docs/backends/dropbox.rst | 23 +++++++++++++---------- storages/backends/dropbox.py | 13 +++++++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/backends/dropbox.rst b/docs/backends/dropbox.rst index 6b7aa1fbc..d4ce6b9f4 100644 --- a/docs/backends/dropbox.rst +++ b/docs/backends/dropbox.rst @@ -1,14 +1,13 @@ -DropBox +Dropbox ======= -A custom storage system for Django using Dropbox Storage backend. +A Django files storage using Dropbox as a backend via the official +`Dropbox SDK for Python`_. Currently only v2 of the API is supported. -Before you start configuration, you will need to install `Dropbox SDK for Python`_. +Before you start configuration, you will need to install the SDK +which can be done for you automatically by doing:: - -Install the package:: - - pip install dropbox + pip install django-storages[dropbox] Settings -------- @@ -18,10 +17,14 @@ To use DropBoxStorage set:: DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage' ``DROPBOX_OAUTH2_TOKEN`` - Your DropBox token, if you haven't follow this `guide step`_. + Your Dropbox token. You can obtain one by following the instructions in the `tutorial`_. -``DROPBOX_ROOT_PATH`` +``DROPBOX_ROOT_PATH`` (optional) Allow to jail your storage to a defined directory. -.. _`guide step`: https://www.dropbox.com/developers/documentation/python#tutorial +``DROPBOX_TIMEOUT`` (optional) + Timeout in seconds for making requests to the API. If ``None``, the client will wait forever. + The default is ``100`` seconds which is the current default in the official SDK. + +.. _`tutorial`: https://www.dropbox.com/developers/documentation/python#tutorial .. _`Dropbox SDK for Python`: https://www.dropbox.com/developers/documentation/python#tutorial diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index df29780c6..e4a5adcf9 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -26,6 +26,9 @@ from storages.utils import setting +_DEFAULT_TIMEOUT = 100 + + class DropBoxStorageException(Exception): pass @@ -67,13 +70,15 @@ class DropBoxStorage(Storage): CHUNK_SIZE = 4 * 1024 * 1024 - def __init__(self, oauth2_access_token=None, root_path=None): + def __init__(self, oauth2_access_token=None, root_path=None, timeout=None): oauth2_access_token = oauth2_access_token or setting('DROPBOX_OAUTH2_TOKEN') - self.root_path = root_path or setting('DROPBOX_ROOT_PATH', '/') if oauth2_access_token is None: - raise ImproperlyConfigured("You must configure a token auth at" + raise ImproperlyConfigured("You must configure an auth token at" "'settings.DROPBOX_OAUTH2_TOKEN'.") - self.client = Dropbox(oauth2_access_token) + + self.root_path = root_path or setting('DROPBOX_ROOT_PATH', '/') + timeout = timeout or setting('DROPBOX_TIMEOUT', _DEFAULT_TIMEOUT) + self.client = Dropbox(oauth2_access_token, timeout=timeout) def _full_path(self, name): if name == '/': From a55275c4b981c24748297c3ba1c7cf74bcded3f2 Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Sat, 7 Sep 2019 21:36:42 -0700 Subject: [PATCH 2/2] Fix Flake8 --- storages/backends/dropbox.py | 1 - 1 file changed, 1 deletion(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index e4a5adcf9..0640d1cf3 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -25,7 +25,6 @@ from storages.utils import setting - _DEFAULT_TIMEOUT = 100