Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[djangoproject.com] Handle multiple doc versions (en/1.0, en/dev, ...…

…). Also get rid of the "from older docs" message since that's now being more confusing than helpful. Oh, and update to Django 1.0.2 (from 1.0) while I'm at it.

git-svn-id: http://code.djangoproject.com/svn/djangoproject.com@10066 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 88cbd7f2732fd5ec7fa100081d8ec9e80d049547 1 parent a96e3ae
jacob authored
View
48 djangodocs/bin/update-docs.py
@@ -0,0 +1,48 @@
+"""
+Update and build the documentation into files for display with the djangodocs
+app.
+"""
+
+import os
+import sys
+import pysvn
+import sphinx
+
+SVN_DOCS_TRUNK = 'http://code.djangoproject.com/svn/django/trunk/docs/'
+SVN_DOCS_RELEASES = 'http://code.djangoproject.com/svn/django/branches/releases/'
+
+svn = pysvn.Client()
+
+def get_doc_versions():
+ """
+ Get a list of (lang, version, svnurl) tuples of docs to build.
+ """
+ yield ('en', 'dev', SVN_DOCS_TRUNK)
+ for release in svn.ls(SVN_DOCS_RELEASES):
+ version = release.name.split('/')[-1].replace('.X', '')
+ yield ('en', version, "%s/docs/" % release.name)
+
+def update_docs(basedir):
+ """
+ Update all versions of the docs into the given base directory.
+ """
+ for (lang, version, svnurl) in get_doc_versions():
+
+ # Make an SVN checkout (or update) in the destination directory,
+ # creating it if it doesn't exist
+ destdir = os.path.join(basedir, lang, version)
+ if not os.path.exists(destdir):
+ os.makedirs(destdir)
+ svn.checkout(svnurl, destdir)
+
+ # Run Sphinx by faking a commandline. Better than shelling out, I s'pose.
+ sphinx.main([
+ 'sphinx-build', # Fake argv[0]
+ '-b', 'json', # Use the JSON builder
+ '-q', # Be vewy qwiet
+ destdir, # Source file directory
+ os.path.join(destdir, '_build', 'json'), # Destination directory
+ ])
+
+if __name__ == '__main__':
+ update_docs(sys.argv[1])
View
5 djangodocs/settings.py
@@ -8,7 +8,4 @@
ROOT_URLCONF = 'djangodocs.urls'
CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs'
-if DEVELOPMENT_MODE:
- DOCS_PICKLE_ROOT = "/Users/jacob/Projects/Django/upstream/docs/_build/pickle/"
-else:
- DOCS_PICKLE_ROOT = "/home/jacob/django-docs/docs/_build/pickle"
+DOCS_PICKLE_ROOT = "/tmp/djangodocs/"
View
46 djangodocs/templates/docs/doc.html
@@ -27,41 +27,27 @@
form.search .query {
width: 18em;
}
- div#old-docs-warning {
- background-color:#FFFFAA;
- font-size:1.2em;
- line-height:1.3em;
- border: 2px solid #d00;
- padding: .5em;
- margin-top: 1em;
- }
- div#old-docs-warning h3, div#old-docs.warning p {
- margin-top: 0;
- padding: 0.2em 0;
- color: black;
- }
</style>
<link rel="stylesheet" href="http://media.djangoproject.com/css/pygments.css" type="text/css" />
{% endblock %}
{% block billboard %}
- <h2><a href="{{ home }}">Django documentation</a></h2>
+ <h2><a href="{% url document-index lang=lang, version=version %}">Django documentation</a></h2>
{% endblock %}
{% block content %}
{% block body %}
- {% if redirect_from %}
- <div id="old-docs-warning">
- <h3>Welcome to the new documentation.</h3>
- <p>
- We've recently reorganized the documentation, and you requested an
- out-of-date page. We've tried to redirect you to the right place, but we
- might have gotten it wrong. If you can't find what you're looking for
- here, you might try <a href="{{ home }}/search/">searching for it</a>.
- </p>
- </div>
- {% endif %}
+ <h2 class="deck">
+ {% ifequal version "dev" %}
+ This document is for Django's SVN release, which can be
+ significantly different from previous releases. Get old docs here:
+ <a href="{% url document-detail lang=lang, version="1.0", url=docurl %}">Django 1.0</a>
+ {% else %}
+ This document describes Django version {{ version }}. For development documentation,
+ <a href="{% url document-detail lang=lang, version="dev", url=docurl %}">go here</a>.
+ {% endifequal %}
+ </h2>
{{ doc.body|safe }}
{% endblock %}
@@ -114,14 +100,14 @@ <h2 id="comments">Questions/Feedback</h2>
<ul>
{% block browse %}
{% if doc.prev %}
- <li>Prev: <a href="{{ doc.prev.link }}">{{ doc.prev.title }}</a></li>
+ <li>Prev: <a href="{{ doc.prev.link }}">{{ doc.prev.title|safe }}</a></li>
{% endif %}
{% if doc.next %}
- <li>Next: <a href="{{ doc.next.link }}">{{ doc.next.title }}</a></li>
+ <li>Next: <a href="{{ doc.next.link }}">{{ doc.next.title|safe }}</a></li>
{% endif %}
- <li><a href="{{ home }}contents/">Table of contents</a></li>
+ <li><a href="{% url document-detail lang=lang, version=version, url="contents" %}">Table of contents</a></li>
{% for doc, title, accesskey, shorttitle in env.rellinks %}
- <li><a href="{{ home }}{{ doc }}/">{{ title }}</a></li>
+ <li><a href="{% url document-detail lang=lang, version=version, url=doc %}">{{ title }}</a></li>
{% endfor %}
{% endblock %}
</ul>
@@ -132,7 +118,7 @@ <h2 id="comments">Questions/Feedback</h2>
<ul>
{% block breadcrumbs %}
<li>
- <a href="{{ home }}">{{ env.docstitle }}</a>
+ <a href="{% url document-index lang=lang, version=version %}">{{ env.docstitle }}</a>
{% for p in doc.parents %}
<ul><li><a href="{{ p.link }}">{{ p.title|safe }}</a>
{% endfor %}
View
22 djangodocs/views.py
@@ -7,6 +7,7 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from unipath import FSPath as Path
+import simplejson
def index(request):
return HttpResponseRedirect(
@@ -25,27 +26,30 @@ def language(request, lang):
)
def document(request, lang, version, url):
- if lang != 'en' or version != 'dev': raise Http404()
-
- docroot = Path(settings.DOCS_PICKLE_ROOT)
+ docroot = Path(settings.DOCS_PICKLE_ROOT).child(lang, version, "_build", "json")
+ if not docroot.exists():
+ raise Http404()
# First look for <bits>/index.fpickle, then for <bits>.fpickle
- bits = url.strip('/').split('/') + ['index.fpickle']
+ bits = url.strip('/').split('/') + ['index.fjson']
doc = docroot.child(*bits)
if not doc.exists():
- bits = bits[:-2] + ['%s.fpickle' % bits[-2]]
+ bits = bits[:-2] + ['%s.fjson' % bits[-2]]
doc = docroot.child(*bits)
if not doc.exists():
raise Http404("'%s' does not exist" % doc)
- bits[-1] = bits[-1].replace('.fpickle', '')
+ bits[-1] = bits[-1].replace('.fjson', '')
template_names = [
'docs/%s.html' % '-'.join([b for b in bits if b]),
'docs/doc.html'
]
return render_to_response(template_names, RequestContext(request, {
- 'doc': pickle.load(open(doc, 'rb')),
- 'env': pickle.load(open(docroot.child('globalcontext.pickle'), 'rb')),
+ 'doc': simplejson.load(open(doc, 'rb')),
+ 'env': simplejson.load(open(docroot.child('globalcontext.json'), 'rb')),
+ 'lang': lang,
+ 'version': version,
+ 'docurl': url,
'update_date': datetime.datetime.fromtimestamp(docroot.child('last_build').mtime()),
'home': urlresolvers.reverse('document-index', kwargs={'lang':lang, 'version':version}),
'search': urlresolvers.reverse('document-search', kwargs={'lang':lang, 'version':version}),
@@ -82,7 +86,7 @@ def search(request, lang, version):
return render_to_response('docs/search.html', RequestContext(request, {
'query': request.GET.get('q'),
'query_string': mutable_get.urlencode(),
- 'env': pickle.load(open(docroot.child('globalcontext.pickle'), 'rb')),
+ 'env': simplejson.load(open(docroot.child('globalcontext.json'), 'rb')),
'home': urlresolvers.reverse('document-index', kwargs={'lang':lang, 'version':version}),
'search': urlresolvers.reverse('document-search', kwargs={'lang':lang, 'version':version}),
}))

0 comments on commit 88cbd7f

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