Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Aymeric Augustin authored February 09, 2013
16  docs/context_processors.py
... ...
@@ -1,18 +1,4 @@
1  
-from django.conf import settings
2  
-from django.core.cache import cache
3  
-
4 1
 from docs.models import DocumentRelease
5 2
 
6 3
 def recent_release(request):
7  
-    recent_release = cache.get('recent_release')
8  
-    if not recent_release:
9  
-        try:
10  
-            recent_release = DocumentRelease.objects.default().version
11  
-        except DocumentRelease.DoesNotExist:
12  
-            recent_release = 'dev'
13  
-        cache.set(
14  
-            DocumentRelease.DEFAULT_CACHE_KEY,
15  
-            recent_release,
16  
-            settings.CACHE_MIDDLEWARE_SECONDS,
17  
-        )
18  
-    return {'RECENT_RELEASE': recent_release}
  4
+    return {'RECENT_RELEASE': DocumentRelease.objects.default_version()}
16  docs/models.py
... ...
@@ -1,11 +1,25 @@
1  
-from django.db import models
2 1
 from django.conf import settings
3 2
 from django.core.cache import cache
  3
+from django.db import models
4 4
 
5 5
 class DocumentReleaseManager(models.Manager):
6 6
     def default(self):
7 7
         return DocumentRelease.objects.get(is_default=True)
8 8
 
  9
+    def default_version(self):
  10
+        default_version = cache.get(DocumentRelease.DEFAULT_CACHE_KEY)
  11
+        if not default_version:
  12
+            try:
  13
+                default_version = DocumentRelease.objects.default().version
  14
+            except DocumentRelease.DoesNotExist:
  15
+                default_version = 'dev'
  16
+            cache.set(
  17
+                DocumentRelease.DEFAULT_CACHE_KEY,
  18
+                default_version,
  19
+                settings.CACHE_MIDDLEWARE_SECONDS,
  20
+            )
  21
+        return default_version
  22
+
9 23
 class DocumentRelease(models.Model):
10 24
     """
11 25
     A "release" of documentation -- i.e. English for v1.2.
4  docs/urls.py
@@ -19,6 +19,10 @@
19 19
         views.language,
20 20
     ),
21 21
     url(
  22
+        r'^(?P<lang>[a-z-]+)/stable/(?P<url>.*)$',
  23
+        views.stable,
  24
+    ),
  25
+    url(
22 26
         r'^(?P<lang>[a-z-]+)/(?P<version>[\w.-]+)/$',
23 27
         views.document,
24 28
         {'url': ''},
12  docs/views.py
@@ -11,6 +11,7 @@
11 11
 
12 12
 import haystack.views
13 13
 
  14
+from .context_processors import recent_release
14 15
 from .forms import DocSearchForm
15 16
 from .models import DocumentRelease
16 17
 from .utils import get_doc_root_or_404, get_doc_path_or_404
@@ -22,6 +23,11 @@ def index(request):
22 23
 def language(request, lang):
23 24
     return redirect(DocumentRelease.objects.default())
24 25
 
  26
+def stable(request, lang, version, url):
  27
+    path = request.get_full_path()
  28
+    version = DocumentRelease.objects.default_version()
  29
+    return redirect(path.replace(version, default_version, 1))
  30
+
25 31
 def document(request, lang, version, url):
26 32
     # If either of these can't be encoded as ascii then later on down the line an
27 33
     # exception will be emitted by unipath, proactively check for bad data (mostly
@@ -31,14 +37,16 @@ def document(request, lang, version, url):
31 37
         url.encode("ascii")
32 38
     except UnicodeEncodeError:
33 39
         raise Http404
  40
+
  41
+    docroot = get_doc_root_or_404(lang, version)
  42
+    doc_path = get_doc_path_or_404(docroot, url)
  43
+
34 44
     if version == 'dev':
35 45
         rtd_version = 'latest'
36 46
     elif version >= '1.5':
37 47
         rtd_version = version + '.x'
38 48
     else:
39 49
         rtd_version = version + '.X'
40  
-    docroot = get_doc_root_or_404(lang, version)
41  
-    doc_path = get_doc_path_or_404(docroot, url)
42 50
 
43 51
     template_names = [
44 52
         'docs/%s.html' % docroot.rel_path_to(doc_path).replace(doc_path.ext, ''),

0 notes on commit 170944d

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