Commits

Anonymous committed 7e19202

unified settings and backend naming

Comments (0)

Files changed (4)

filetransfers/api.py

 from django.utils.importlib import import_module
 import mimetypes
 
-UPLOAD_BACKEND = getattr(settings,
-    'FILETRANSFERS_UPLOAD_BACKEND',
+PREPARE_UPLOAD_BACKEND = getattr(settings,
+    'PREPARE_UPLOAD_BACKEND',
     'filetransfers.backends.default.prepare_upload')
-DOWNLOAD_BACKEND = getattr(settings,
-    'FILETRANSFERS_DOWNLOAD_BACKEND',
+SERVE_FILE_BACKEND = getattr(settings,
+    'SERVE_FILE_BACKEND',
     'filetransfers.backends.default.serve_file')
 PUBLIC_DOWNLOAD_URL_BACKEND = getattr(settings,
-    'FILETRANSFERS_PUBLIC_DOWNLOAD_URL_BACKEND',
+    'PUBLIC_DOWNLOAD_URL_BACKEND',
     'filetransfers.backends.default.public_download_url')
 
 _backends_cache = {}
 
 # Public API
 def prepare_upload(request, url, private=False, backend=None):
-    handler = _load_backend(backend, UPLOAD_BACKEND)
+    handler = _load_backend(backend, PREPARE_UPLOAD_BACKEND)
     result = handler(request, url, private=private)
     if isinstance(result, (tuple, list)):
         return result
 
 def serve_file(request, file, backend=None, save_as=False, content_type=None):
     # Backends are responsible for handling range requests.
-    handler = _load_backend(backend, DOWNLOAD_BACKEND)
+    handler = _load_backend(backend, SERVE_FILE_BACKEND)
     filename = file.name.rsplit('/')[-1]
     if save_as is True:
         save_as = filename

filetransfers/backends/base_url.py

+from django.conf import settings
+
+def public_download_url(file, **kwargs):
+    """
+    Directs downloads to a handler at settings.PUBLIC_DOWNLOADS_URL_BASE
+    """
+    return settings.PUBLIC_DOWNLOADS_URL_BASE + file.name

filetransfers/backends/delegate.py

 def prepare_upload(*args, **kwargs):
     """Delegates uploads to other backends based on private=False or True"""
     if kwargs['private']:
-        kwargs['backend'] = settings.DELEGATE_PRIVATE_UPLOADS
+        kwargs['backend'] = settings.PRIVATE_PREPARE_UPLOAD_BACKEND
     else:
-        kwargs['backend'] = settings.DELEGATE_PUBLIC_UPLOADS
+        kwargs['backend'] = settings.PUBLIC_PREPARE_UPLOAD_BACKEND
     return delegate(*args, **kwargs)

filetransfers/backends/public_url.py

-from django.conf import settings
-
-def public_download_url(file, **kwargs):
-    """
-    Directs downloads to a handler at settings.PUBLIC_DOWNLOADS_URL_BASE
-    """
-    return settings.PUBLIC_DOWNLOADS_URL_BASE + file.name