mirror of
https://github.com/jazzband/django-downloadview.git
synced 2026-05-08 15:44:49 +00:00
Merge pull request #31 from novagile/master
Refs #29 - Improved HTTPDownloadView
This commit is contained in:
commit
33a23a48c3
4 changed files with 28 additions and 12 deletions
|
|
@ -4,7 +4,8 @@ Changelog
|
|||
1.1 (unreleased)
|
||||
----------------
|
||||
|
||||
**Backward incompatible changes.**
|
||||
Various improvements.
|
||||
Contains **backward incompatible changes.**
|
||||
|
||||
- Added HTTPDownloadView to proxy to arbitrary URL.
|
||||
|
||||
|
|
|
|||
|
|
@ -76,4 +76,4 @@ download_generated_hello_world = StringIODownloadView.as_view()
|
|||
|
||||
download_http_hello_world = views.HTTPDownloadView.as_view(
|
||||
url=u'https://raw.github.com/benoitbryon/django-downloadview/master/demo/demoproject/download/fixtures/hello-world.txt',
|
||||
name=u'hello-world.txt')
|
||||
basename=u'hello-world.txt')
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ from django.views.generic.base import View
|
|||
from django.views.generic.detail import BaseDetailView
|
||||
from django.views.static import was_modified_since
|
||||
|
||||
import requests
|
||||
|
||||
from django_downloadview import files
|
||||
from django_downloadview.response import DownloadResponse
|
||||
|
||||
|
|
@ -134,18 +136,30 @@ class VirtualDownloadView(BaseDownloadView):
|
|||
|
||||
class HTTPDownloadView(BaseDownloadView):
|
||||
"""Proxy files that live on remote servers."""
|
||||
#: URL to download (the one we are proxying).
|
||||
url = u''
|
||||
|
||||
#: Additional keyword arguments for request handler.
|
||||
request_kwargs = {}
|
||||
name = u''
|
||||
|
||||
def get_request_factory(self):
|
||||
"""Return request factory to perform actual HTTP request."""
|
||||
return requests.get
|
||||
|
||||
def get_request_kwargs(self):
|
||||
"""Return keyword arguments for use with request factory."""
|
||||
return self.request_kwargs
|
||||
|
||||
def get_url(self):
|
||||
"""Return remote file URL (the one we are proxying)."""
|
||||
return self.url
|
||||
|
||||
def get_file(self):
|
||||
"""Return wrapper which has an ``url`` attribute."""
|
||||
url = self.get_url()
|
||||
request_kwargs = self.request_kwargs
|
||||
return files.HTTPFile(name=self.name, url=url, **request_kwargs)
|
||||
return files.HTTPFile(request_factory=self.get_request_factory(),
|
||||
name=self.get_basename(),
|
||||
url=self.get_url(),
|
||||
**self.get_request_kwargs())
|
||||
|
||||
|
||||
class ObjectDownloadView(DownloadMixin, BaseDetailView):
|
||||
|
|
|
|||
|
|
@ -56,21 +56,22 @@ eggs = zest.releaser
|
|||
recipe = evg.recipe.activate
|
||||
|
||||
[versions]
|
||||
Django = 1.5
|
||||
Jinja2 = 2.6
|
||||
Pygments = 1.6
|
||||
Sphinx = 1.1.3
|
||||
bpython = 0.10.1
|
||||
buildout-versions = 1.7
|
||||
coverage = 3.6
|
||||
distribute = 0.6.34
|
||||
Django = 1.5
|
||||
django-nose = 1.1
|
||||
docutils = 0.10
|
||||
Jinja2 = 2.6
|
||||
nose = 1.2.1
|
||||
Pygments = 1.6
|
||||
python-termstyle = 0.1.9
|
||||
rednose = 0.3
|
||||
requests = 1.2.0
|
||||
Sphinx = 1.1.3
|
||||
sphinxcontrib-testbuild = 0.1.1
|
||||
zc.recipe.egg = 1.3.2
|
||||
z3c.recipe.mkdir = 0.5
|
||||
z3c.recipe.scripts = 1.0.1
|
||||
zc.recipe.egg = 1.3.2
|
||||
zest.releaser = 3.43
|
||||
django-nose = 1.1
|
||||
|
|
|
|||
Loading…
Reference in a new issue