Show links to other versions of docs

Main patch from Marti Raudsepp, but with some fairly extensive changes
This commit is contained in:
Magnus Hagander
2012-06-05 12:24:06 +02:00
parent e897b7a6a4
commit 9a37d893e8
4 changed files with 43 additions and 7 deletions

View File

@ -12,8 +12,17 @@ class DocPage(models.Model):
title = models.CharField(max_length=256, null=True, blank=True)
content = models.TextField(null=True, blank=True)
def display_version(self):
"""Version as used for displaying and in URLs"""
if self.version == 0:
return 'devel'
else:
return str(self.version)
class Meta:
db_table = 'docs'
# Index file first, because we want to list versions by file
unique_together = [('file', 'version')]
class DocComment(PgModel, models.Model):
version = models.DecimalField(max_digits=3, decimal_places=1, null=False)

View File

@ -41,17 +41,20 @@ def docpage(request, version, typ, filename):
else:
indexname = "index.html"
page = get_object_or_404(DocPage, version=ver, file="%s.%s" % (filename, extension))
fullname = "%s.%s" % (filename, extension)
page = get_object_or_404(DocPage, version=ver, file=fullname)
versions = DocPage.objects.filter(file=fullname).extra(select={'supported':"COALESCE((SELECT supported FROM core_version v WHERE v.tree=version), 'f')"}).order_by('-supported', '-version').only('version', 'file')
if typ=="interactive":
comments = DocComment.objects.filter(version=ver, file="%s.%s" % (filename, extension), approved=True).order_by('posted_at')
comments = DocComment.objects.filter(version=ver, file=fullname, approved=True).order_by('posted_at')
else:
comments = None
return render_to_response('docs/docspage.html', {
'page': page,
'supported_versions': [v for v in versions if v.supported],
'unsupported_versions': [v for v in versions if not v.supported],
'title': page.title,
'doc_nav_version': ver > 0 and ver or "devel",
'doc_type': typ,
'comments': comments,
'can_comment': (typ=="interactive" and ver==currver),