Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Automate the version number on the homepage.

  • Loading branch information...
commit 7eb7fbc9170f200396391c49b7987a64805503b2 1 parent 1a94ced
@aaugustin aaugustin authored
View
2  django_docs/settings.py
@@ -36,7 +36,7 @@
'django.core.context_processors.i18n',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
- 'docs.context_processors.recent_release',
+ 'docs.context_processors.docs_version',
'django.core.context_processors.request',
]
View
3  django_www/settings.py
@@ -73,7 +73,8 @@
'django.core.context_processors.i18n',
'django.core.context_processors.static',
'django.contrib.messages.context_processors.messages',
- 'docs.context_processors.recent_release',
+ 'docs.context_processors.docs_version',
+ 'releases.context_processors.django_version',
]
View
4 docs/context_processors.py
@@ -1,4 +1,4 @@
from docs.models import DocumentRelease
-def recent_release(request):
- return {'RECENT_RELEASE': DocumentRelease.objects.default_version()}
+def docs_version(request):
+ return {'DOCS_VERSION': DocumentRelease.objects.current_version()}
View
24 docs/models.py
@@ -2,29 +2,32 @@
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:
+ def current(self):
+ return self.get(is_default=True)
+
+ def current_version(self):
+ current_version = cache.get(DocumentRelease.DEFAULT_CACHE_KEY)
+ if not current_version:
try:
- default_version = DocumentRelease.objects.default().version
+ current_version = self.current().version
except DocumentRelease.DoesNotExist:
- default_version = 'dev'
+ current_version = 'dev'
cache.set(
DocumentRelease.DEFAULT_CACHE_KEY,
- default_version,
+ current_version,
settings.CACHE_MIDDLEWARE_SECONDS,
)
- return default_version
+ return current_version
+
class DocumentRelease(models.Model):
"""
A "release" of documentation -- i.e. English for v1.2.
"""
- DEFAULT_CACHE_KEY = "%s_recent_release" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
+ DEFAULT_CACHE_KEY = "%s_docs_version" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
SVN = 'svn'
GIT = 'git'
SCM_CHOICES = (
@@ -73,6 +76,7 @@ def human_version(self):
def is_dev(self):
return self.version == 'dev'
+
class Document(models.Model):
"""
An individual document. Used mainly as a hook point for Haystack.
View
5 docs/views.py
@@ -11,7 +11,6 @@
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
@@ -25,8 +24,8 @@ def language(request, lang):
def stable(request, lang, version, url):
path = request.get_full_path()
- default_version = DocumentRelease.objects.default_version()
- return redirect(path.replace(version, default_version, 1))
+ current_version = DocumentRelease.objects.current_version()
+ return redirect(path.replace(version, current_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
View
28 releases/models.py
@@ -5,12 +5,37 @@
from django.db import models
from django.conf import settings
+from django.core.cache import cache
from django.utils.functional import cached_property
from django.utils.version import get_version
+class ReleaseManager(models.Manager):
+
+ def final(self):
+ return self.filter(status='f', major=1)
+
+ def current(self):
+ return self.final().order_by('-minor', '-micro')[0]
+
+ def current_version(self):
+ current_version = cache.get(Release.DEFAULT_CACHE_KEY)
+ if not current_version:
+ try:
+ current_version = self.current().version
+ except Release.DoesNotExist:
+ current_version = ''
+ cache.set(
+ Release.DEFAULT_CACHE_KEY,
+ current_version,
+ settings.CACHE_MIDDLEWARE_SECONDS,
+ )
+ return current_version
+
+
class Release(models.Model):
+ DEFAULT_CACHE_KEY = "%s_django_version" % settings.CACHE_MIDDLEWARE_KEY_PREFIX
STATUS_CHOICES = (
('a', 'alpha'),
('b', 'beta'),
@@ -28,9 +53,12 @@ class Release(models.Model):
status = models.CharField(max_length=1, choices=STATUS_CHOICES, editable=False)
iteration = models.PositiveSmallIntegerField(editable=False)
+ objects = ReleaseManager()
+
def save(self, *args, **kwargs):
self.major, self.minor, self.micro, status, self.iteration = self.version_tuple
self.status = self.STATUS_REVERSE[status]
+ cache.delete(self.DEFAULT_CACHE_KEY)
super(Release, self).save(*args, **kwargs)
def __unicode__(self):
View
2  releases/views.py
@@ -9,7 +9,7 @@
def index(request):
# Build a dictionary of x => latest 1.x.y release
releases = {}
- for release in Release.objects.filter(status='f', major=1).order_by('minor', 'micro'):
+ for release in Release.objects.final().order_by('minor', 'micro'):
releases[release.minor] = release
releases = [releases[minor] for minor in sorted(releases)]
current = releases.pop()
View
2  templates/base_community.html
@@ -47,7 +47,7 @@
<h2>Get help</h2>
<ul>
-<li><strong><a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/faq/">Check our FAQ</a> first</strong>. If you have a basic question that's not answered by the FAQ, <a href="https://code.djangoproject.com/newticket">file a ticket</a> to tell us you think it should be in there.</li>
+<li><strong><a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/faq/">Check our FAQ</a> first</strong>. If you have a basic question that's not answered by the FAQ, <a href="https://code.djangoproject.com/newticket">file a ticket</a> to tell us you think it should be in there.</li>
<li><strong>Chat live with other Django users</strong> in the <a href="irc://irc.freenode.net/django">#django IRC channel on irc.freenode.net</a>.</li>
<li><strong>Ask questions</strong> on the <a href="http://groups.google.com/group/django-users">django-users mailing list</a>.</li>
<li><strong>Report potential security issues in Django via private email to security@djangoproject.com, </strong>and not via Django's Trac instance or the django-developers mailing list</li>
View
22 templates/homepage.html
@@ -11,22 +11,22 @@
<h2 class="deck">Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.</h2>
<p>Developed by a fast-moving online-news operation, Django was designed to handle two challenges: the intensive deadlines of a newsroom and the stringent requirements of the experienced Web developers who wrote it. It lets you build high-performing, elegant Web applications quickly.</p>
<p>Django focuses on automating as much as possible and adhering to the <a href="http://c2.com/cgi/wiki?DontRepeatYourself"><abbr title="Don't Repeat Yourself">DRY</abbr> principle</a>.</p>
-<p>Dive in by <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/overview/">reading the overview &rarr;</a></p>
-<p>When you're ready to code, read the <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/install/">installation guide</a> and <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/tutorial01/">tutorial</a>.</p>
+<p>Dive in by <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/overview/">reading the overview &rarr;</a></p>
+<p>When you're ready to code, read the <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/install/">installation guide</a> and <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/tutorial01/">tutorial</a>.</p>
<div id="content-secondary">
<h2>The Django framework</h2>
<h3>Object-relational mapper</h3>
- <p>Define your <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/db/models/">data models</a> entirely in Python. You get a rich, <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/db/queries/">dynamic database-access API</a> for free &mdash; but you can still write SQL if needed.</p>
+ <p>Define your <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/db/models/">data models</a> entirely in Python. You get a rich, <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/db/queries/">dynamic database-access API</a> for free &mdash; but you can still write SQL if needed.</p>
<h3>Automatic admin interface</h3>
- <p>Save yourself the tedious work of creating interfaces for people to add and update content. <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/tutorial02/">Django does that automatically</a>, and it's production-ready.</p>
+ <p>Save yourself the tedious work of creating interfaces for people to add and update content. <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/tutorial02/">Django does that automatically</a>, and it's production-ready.</p>
<h3>Elegant URL design</h3>
- <p>Design pretty, <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/http/urls/">cruft-free URLs</a> with no framework-specific limitations. Be as flexible as you like.</p>
+ <p>Design pretty, <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/http/urls/">cruft-free URLs</a> with no framework-specific limitations. Be as flexible as you like.</p>
<h3>Template system</h3>
- <p>Use Django's powerful, extensible and designer-friendly <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/templates/">template language</a> to separate design, content and Python code.</p>
+ <p>Use Django's powerful, extensible and designer-friendly <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/templates/">template language</a> to separate design, content and Python code.</p>
<h3>Cache system</h3>
- <p>Hook into memcached or other cache frameworks for <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/cache/">super performance</a> &mdash; caching is as granular as you need.</p>
+ <p>Hook into memcached or other cache frameworks for <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/cache/">super performance</a> &mdash; caching is as granular as you need.</p>
<h3>Internationalization</h3>
- <p>Django has full support for <a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/topics/i18n/">multi-language applications</a>, letting you specify translation strings and providing hooks for language-specific functionality.</p>
+ <p>Django has full support for <a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/topics/i18n/">multi-language applications</a>, letting you specify translation strings and providing hooks for language-specific functionality.</p>
</div>
<!-- END #content-secondary -->
{% endblock %}
@@ -35,13 +35,13 @@ <h2 class="deck">Django is a high-level Python Web framework that encourages rap
<h2>Download</h2>
<ul class="linklist">
- <li class="button-download"><a href="/download/">Latest release: <strong>1.5</strong></a></li>
+ <li class="button-download"><a href="/download/">Latest release: <strong>{{ DJANGO_VERSION }}</strong></a></li>
</ul>
<p>Open source, <a href="https://github.com/django/django/blob/master/LICENSE">BSD license</a></p>
<h2>Documentation</h2>
<ul class="linklist">
- <li><a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/install/">Installation guide</a></li>
- <li><a href="https://docs.djangoproject.com/en/{{ RECENT_RELEASE }}/intro/tutorial01/">Tutorial</a></li>
+ <li><a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/install/">Installation guide</a></li>
+ <li><a href="https://docs.djangoproject.com/en/{{ DOCS_VERSION }}/intro/tutorial01/">Tutorial</a></li>
<li><a href="https://docs.djangoproject.com/">Full index...</a></li>
</ul>
<h2>Sites that use Django</h2>
Please sign in to comment.
Something went wrong with that request. Please try again.