Remove 3rd_party_apps folder, don't include filetransfers it is now instalable from PyPI
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
from django.conf import settings
|
||||
from django.utils.importlib import import_module
|
||||
import mimetypes
|
||||
|
||||
PREPARE_UPLOAD_BACKEND = getattr(settings,
|
||||
'PREPARE_UPLOAD_BACKEND',
|
||||
'filetransfers.backends.default.prepare_upload')
|
||||
SERVE_FILE_BACKEND = getattr(settings,
|
||||
'SERVE_FILE_BACKEND',
|
||||
'filetransfers.backends.default.serve_file')
|
||||
PUBLIC_DOWNLOAD_URL_BACKEND = getattr(settings,
|
||||
'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, PREPARE_UPLOAD_BACKEND)
|
||||
return handler(request, url, private=private)
|
||||
|
||||
def serve_file(request, file, backend=None, save_as=False, content_type=None):
|
||||
# Backends are responsible for handling range requests.
|
||||
handler = _load_backend(backend, SERVE_FILE_BACKEND)
|
||||
filename = file.name.rsplit('/')[-1]
|
||||
if save_as is True:
|
||||
save_as = filename
|
||||
if not content_type:
|
||||
content_type = mimetypes.guess_type(filename)[0]
|
||||
return handler(request, file, save_as=save_as, content_type=content_type)
|
||||
|
||||
def public_download_url(file, backend=None):
|
||||
handler = _load_backend(backend, PUBLIC_DOWNLOAD_URL_BACKEND)
|
||||
return handler(file)
|
||||
|
||||
# Internal utilities
|
||||
def _load_backend(backend, default_backend):
|
||||
if backend is None:
|
||||
backend = default_backend
|
||||
if backend not in _backends_cache:
|
||||
module_name, func_name = backend.rsplit('.', 1)
|
||||
_backends_cache[backend] = getattr(import_module(module_name), func_name)
|
||||
return _backends_cache[backend]
|
||||
@@ -1,7 +0,0 @@
|
||||
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
|
||||
@@ -1,30 +0,0 @@
|
||||
from django.http import HttpResponse
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
def prepare_upload(request, url, **kwargs):
|
||||
"""Directly uploads to the given URL"""
|
||||
return url, {}
|
||||
|
||||
def serve_file(request, file, save_as, content_type, **kwargs):
|
||||
"""
|
||||
Serves the file in chunks for efficiency reasons, but the transfer still
|
||||
goes through Django itself, so it's much worse than using the web server,
|
||||
but at least it works with all configurations.
|
||||
"""
|
||||
response = HttpResponse(ChunkedFile(file), content_type=content_type)
|
||||
if save_as:
|
||||
response['Content-Disposition'] = smart_str(u'attachment; filename=%s' % save_as)
|
||||
if file.size is not None:
|
||||
response['Content-Length'] = file.size
|
||||
return response
|
||||
|
||||
def public_download_url(file, **kwargs):
|
||||
"""No public download URL"""
|
||||
return None
|
||||
|
||||
class ChunkedFile(object):
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
|
||||
def __iter__(self):
|
||||
return self.file.chunks()
|
||||
@@ -1,11 +0,0 @@
|
||||
from django.conf import settings
|
||||
|
||||
from filetransfers.api import prepare_upload as delegate
|
||||
|
||||
def prepare_upload(*args, **kwargs):
|
||||
"""Delegates uploads to other backends based on private=False or True"""
|
||||
if kwargs['private']:
|
||||
kwargs['backend'] = settings.PRIVATE_PREPARE_UPLOAD_BACKEND
|
||||
else:
|
||||
kwargs['backend'] = settings.PUBLIC_PREPARE_UPLOAD_BACKEND
|
||||
return delegate(*args, **kwargs)
|
||||
@@ -1,10 +0,0 @@
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
def serve_file(request, file, **kwargs):
|
||||
"""Serves files by redirecting to file.url (e.g., useful for Amazon S3)"""
|
||||
return HttpResponseRedirect(smart_str(file.url))
|
||||
|
||||
def public_download_url(file, **kwargs):
|
||||
"""Directs downloads to file.url (useful for normal file system storage)"""
|
||||
return file.url
|
||||
@@ -1,12 +0,0 @@
|
||||
from django.http import HttpResponse
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
def serve_file(request, file, save_as, content_type, **kwargs):
|
||||
"""Lets the web server serve the file using the X-Sendfile extension"""
|
||||
response = HttpResponse(content_type=content_type)
|
||||
response['X-Sendfile'] = file.path
|
||||
if save_as:
|
||||
response['Content-Disposition'] = smart_str(u'attachment; filename=%s' % save_as)
|
||||
if file.size is not None:
|
||||
response['Content-Length'] = file.size
|
||||
return response
|
||||
@@ -1,17 +0,0 @@
|
||||
from django.template import Library
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..api import public_download_url
|
||||
|
||||
register = Library()
|
||||
|
||||
_hidden_data_field = '<input type="hidden" name="%s" value="%s" />'
|
||||
|
||||
@register.simple_tag
|
||||
def render_upload_data(data):
|
||||
inputs = ''.join(_hidden_data_field % item for item in data.items())
|
||||
if inputs:
|
||||
return mark_safe('<div style="display:none">%s</div>' % inputs)
|
||||
return ''
|
||||
|
||||
register.filter(public_download_url)
|
||||
@@ -3,6 +3,7 @@ APScheduler==2.0.3
|
||||
cssmin==0.1.4
|
||||
|
||||
Django==1.4.13
|
||||
django-filetransfers==0.1.0
|
||||
django-pagination==1.0.7
|
||||
django-compressor==1.1.1
|
||||
django-taggit==0.9.3
|
||||
|
||||
@@ -15,7 +15,6 @@ sys.path.append(os.path.join(PROJECT_ROOT, 'modules'))
|
||||
sys.path.append(os.path.join(PROJECT_ROOT, 'customization_apps'))
|
||||
sys.path.append(os.path.join(PROJECT_ROOT, 'apps'))
|
||||
sys.path.append(os.path.join(PROJECT_ROOT, 'shared_apps'))
|
||||
sys.path.append(os.path.join(PROJECT_ROOT, '3rd_party_apps'))
|
||||
|
||||
PROJECT_TITLE = 'Mayan EDMS'
|
||||
PROJECT_NAME = 'mayan'
|
||||
|
||||
Reference in New Issue
Block a user