Commits

mitar committed befa2bd

Unified serving static and other files.

  • Participants
  • Parent commits ecd3d2e

Comments (0)

Files changed (2)

File sphinxdoc/urls.py

         name='doc-search',
     ),
     url(
-        r'^(?P<slug>[\w-]+)/_images/(?P<path>.*)$',
-        'images',
-    ),
-    url(
-        r'^(?P<slug>[\w-]+)/_static/(?P<path>.*)$',
-        'static',
-    ),
-    url(
-        r'^(?P<slug>[\w-]+)/_downloads/(?P<path>.*)$',
-        'downloads',
-    ),
-    url(
-        r'^(?P<slug>[\w-]+)/_source/(?P<path>.*)$',
-        'source',
+        r'^(?P<slug>[\w-]+)/(?P<type_>_images|_static|_downloads|_source)/(?P<path>.*)$',
+        'sphinx_serve',
     ),
     url(
         r'^(?P<slug>[\w-]+)/_objects/$',

File sphinxdoc/views.py

 
 
 @cache_page(60 * CACHE_MINUTES)
-def images(request, slug, path):
+def sphinx_serve(request, slug, type_, path):
     """
-    Shows the specified image.
+    Serves sphinx static and other files.
 
     """
     project = get_object_or_404(Project, slug=slug)
     return serve(
         request,
-        document_root=os.path.join(project.path, BUILDDIR, '_images'),
-        path=path,
-    )
-
-
-@cache_page(60 * CACHE_MINUTES)
-def static(request, slug, path):
-    """
-    Shows the specified static file.
-
-    """
-    project = get_object_or_404(Project, slug=slug)
-    return serve(
-        request,
-        document_root=os.path.join(project.path, BUILDDIR, '_static'),
-        path=path,
-    )
-
-
-@cache_page(60 * CACHE_MINUTES)
-def downloads(request, slug, path):
-    """
-    Shows the specified downloads file.
-
-    """
-    project = get_object_or_404(Project, slug=slug)
-    return serve(
-        request,
-        document_root=os.path.join(project.path, BUILDDIR, '_downloads'),
-        path=path,
-    )
-
-
-@cache_page(60 * CACHE_MINUTES)
-def source(request, slug, path):
-    """
-    Shows the ReST source of a document.
-
-    """
-    project = get_object_or_404(Project, slug=slug)
-    return serve(
-        request,
-        document_root=os.path.join(project.path, BUILDDIR, '_sources'),
+        document_root=os.path.join(project.path, BUILDDIR, type_),
         path=path,
     )