Skip to content

Commit

Permalink
Make middleware not slow and crappy.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Jan 27, 2011
1 parent d0b2cba commit 222b7fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/middleware.py
Expand Up @@ -81,7 +81,7 @@ def process_request(self, request):
def process_response(self, request, response):
#Try and make this match as little as possible.
if response.status_code == 200:
if getattr(request, 'serving_docs', False):
if getattr(request, 'add_badge', False):
if response.content.find('Read the Docs') == -1:
response.content = replace_insensitive(
smart_unicode(response.content),
Expand Down
6 changes: 4 additions & 2 deletions core/views.py
Expand Up @@ -108,7 +108,6 @@ def serve_docs(request, project_slug, lang_slug, version_slug, filename):
time.
"""
# A bunch of janky redirect logic. This should be the last time.
request.serving_docs = True
proj = get_object_or_404(Project, slug=project_slug)
default_version = proj.get_default_version()
if not filename:
Expand All @@ -129,7 +128,8 @@ def serve_docs(request, project_slug, lang_slug, version_slug, filename):
'filename': filename
})
return HttpResponseRedirect(url)
valid_version = proj.versions.filter(slug=version_slug).count()
version = proj.versions.filter(slug=version_slug)
valid_version = version.count()
if not valid_version and version_slug != 'latest' and version_slug != 'en':
url = reverse(serve_docs, kwargs={
'project_slug': project_slug,
Expand All @@ -139,6 +139,8 @@ def serve_docs(request, project_slug, lang_slug, version_slug, filename):
'filename': os.path.join(version_slug, filename)
})
return HttpResponsePermanentRedirect(url)
elif valid_version:
request.add_badge = version[0].uploaded
filename = filename.rstrip('/')
basepath = os.path.join(proj.rtd_build_path, version_slug)
if 'html' in filename:
Expand Down

0 comments on commit 222b7fc

Please sign in to comment.