Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added /stable/ that redirects to the default version.

Refs #18922. Unfortunately this isn't referenced anywhere and I don't
know how search engines could pick this URL.

Refs #19783.
  • Loading branch information...
commit 170944d1f6f554a44e7f6d735a55d13531a9b7cf 1 parent 248bc06
@aaugustin aaugustin authored
View
16 docs/context_processors.py
@@ -1,18 +1,4 @@
-from django.conf import settings
-from django.core.cache import cache
-
from docs.models import DocumentRelease
def recent_release(request):
- recent_release = cache.get('recent_release')
- if not recent_release:
- try:
- recent_release = DocumentRelease.objects.default().version
- except DocumentRelease.DoesNotExist:
- recent_release = 'dev'
- cache.set(
- DocumentRelease.DEFAULT_CACHE_KEY,
- recent_release,
- settings.CACHE_MIDDLEWARE_SECONDS,
- )
- return {'RECENT_RELEASE': recent_release}
+ return {'RECENT_RELEASE': DocumentRelease.objects.default_version()}
View
16 docs/models.py
@@ -1,11 +1,25 @@
-from django.db import models
from django.conf import settings
from django.core.cache import cache
+from django.db import models
class DocumentReleaseManager(models.Manager):
def default(self):
return DocumentRelease.objects.get(is_default=True)
+ def default_version(self):
+ default_version = cache.get(DocumentRelease.DEFAULT_CACHE_KEY)
+ if not default_version:
+ try:
+ default_version = DocumentRelease.objects.default().version
+ except DocumentRelease.DoesNotExist:
+ default_version = 'dev'
+ cache.set(
+ DocumentRelease.DEFAULT_CACHE_KEY,
+ default_version,
+ settings.CACHE_MIDDLEWARE_SECONDS,
+ )
+ return default_version
+
class DocumentRelease(models.Model):
"""
A "release" of documentation -- i.e. English for v1.2.
View
4 docs/urls.py
@@ -19,6 +19,10 @@
views.language,
),
url(
+ r'^(?P<lang>[a-z-]+)/stable/(?P<url>.*)$',
+ views.stable,
+ ),
+ url(
r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/$',
views.document,
{'url': ''},
View
12 docs/views.py
@@ -11,6 +11,7 @@
import haystack.views
+from .context_processors import recent_release
from .forms import DocSearchForm
from .models import DocumentRelease
from .utils import get_doc_root_or_404, get_doc_path_or_404
@@ -22,6 +23,11 @@ def index(request):
def language(request, lang):
return redirect(DocumentRelease.objects.default())
+def stable(request, lang, version, url):
+ path = request.get_full_path()
+ version = DocumentRelease.objects.default_version()
+ return redirect(path.replace(version, default_version, 1))
+
def document(request, lang, version, url):
# If either of these can't be encoded as ascii then later on down the line an
# exception will be emitted by unipath, proactively check for bad data (mostly
@@ -31,14 +37,16 @@ def document(request, lang, version, url):
url.encode("ascii")
except UnicodeEncodeError:
raise Http404
+
+ docroot = get_doc_root_or_404(lang, version)
+ doc_path = get_doc_path_or_404(docroot, url)
+
if version == 'dev':
rtd_version = 'latest'
elif version >= '1.5':
rtd_version = version + '.x'
else:
rtd_version = version + '.X'
- docroot = get_doc_root_or_404(lang, version)
- doc_path = get_doc_path_or_404(docroot, url)
template_names = [
'docs/%s.html' % docroot.rel_path_to(doc_path).replace(doc_path.ext, ''),

0 comments on commit 170944d

Please sign in to comment.
Something went wrong with that request. Please try again.