Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added serving for downloads (Sphinx's :download: directive).

Also lightly refactored the static-serving component to be less repeatitve.
  • Loading branch information...
commit b5b0f37ee7011d62a4ce1973f6432caff6fba984 1 parent 7c9ebf6
@jacobian jacobian authored
Showing with 20 additions and 16 deletions.
  1. +14 −14 django_website/docs/views.py
  2. +6 −2 django_website/urls/docs.py
View
28 django_website/docs/views.py
@@ -36,20 +36,20 @@ def document(request, lang, version, url):
'redirect_from': request.GET.get('from', None),
}))
-def images(request, lang, version, path):
- return django.views.static.serve(
- request,
- document_root = get_doc_root_or_404(lang, version).child('_images'),
- path = path,
- )
-
-def source(request, lang, version, path):
- return django.views.static.serve(
- request,
- document_root = get_doc_root_or_404(lang, version).child('_sources'),
- path = path,
- )
-
+class SphinxStatic(object):
+ """
+ Serve Sphinx static assets from a subdir of the build location.
+ """
+ def __init__(self, subpath):
+ self.subpath = subpath
+
+ def __call__(self, request, lang, version, path):
+ return django.views.static.serve(
+ request,
+ document_root = get_doc_root_or_404(lang, version).child(self.subpath),
+ path = path,
+ )
+
def objects_inventory(request, lang, version):
response = django.views.static.serve(
request,
View
8 django_website/urls/docs.py
@@ -30,11 +30,15 @@
),
url(
r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/_images/(?P<path>.*)$',
- views.images,
+ views.SphinxStatic('_images'),
),
url(
r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/_source/(?P<path>.*)$',
- views.source,
+ views.SphinxStatic('_sources'),
+ ),
+ url(
+ r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/_downloads/(?P<path>.*)$',
+ views.SphinxStatic('_downloads'),
),
url(
r'^(.*)/index/$',
Please sign in to comment.
Something went wrong with that request. Please try again.