Files
postgres-web/pgweb/docs/views.py
Magnus Hagander 845c133d0b Explicitly list beta and development versions in docs as "devel"
Previously we listed both those as unsupported, which confused some users
particularly with new beta releases. While they are technically not supported
yet, it gave off the image that specific features would not be in newer
versions anymore, since they got listed as unsupported.

In passing, fix the style of the links in case they only exist in old
versions, which would put an extra | character in the version list.
2013-08-17 15:55:30 +02:00

85 lines
2.8 KiB
Python

from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.template import TemplateDoesNotExist, loader, Context
from django.contrib.auth.decorators import login_required
from decimal import Decimal
from pgweb.util.decorators import ssl_required
from pgweb.util.contexts import NavContext
from pgweb.util.helpers import simple_form
from pgweb.core.models import Version
from models import DocPage, DocComment
from forms import DocCommentForm
def docpage(request, version, typ, filename):
loaddate = None
# Get the current version both to map the /current/ url, and to later
# determine if we allow comments on this page.
currver = Version.objects.filter(current=True)[0].tree
if version == 'current':
ver = currver
elif version == 'devel':
if not typ == 'static':
return HttpResponseRedirect("/docs/devel/static/%s.html" % filename)
ver = Decimal(0)
loaddate = Version.objects.get(tree=Decimal(0)).docsloaded
else:
ver = Decimal(version)
if ver < Decimal("7.1") and ver > Decimal(0):
extension = "htm"
else:
extension = "html"
if ver < Decimal("7.1") and ver > Decimal(0):
indexname = "postgres.htm"
elif ver == Decimal("7.1"):
indexname = "postgres.html"
else:
indexname = "index.html"
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')",
'beta':"CASE WHEN (SELECT beta FROM core_version v WHERE v.tree=version)='t' THEN true WHEN version=0 THEN true ELSE false END",
}).order_by('-supported', '-version').only('version', 'file')
if typ=="interactive":
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],
'devel_versions': [v for v in versions if not v.supported and v.beta],
'unsupported_versions': [v for v in versions if not v.supported and not v.beta],
'title': page.title,
'doc_type': typ,
'comments': comments,
'can_comment': (typ=="interactive" and ver==currver),
'doc_index_filename': indexname,
'loaddate': loaddate,
})
def docsrootpage(request, version, typ):
return docpage(request, version, typ, 'index')
def redirect_root(request, version):
return HttpResponseRedirect("/docs/%s/static/" % version)
@ssl_required
@login_required
def commentform(request, itemid, version, filename):
return simple_form(DocComment, itemid, request, DocCommentForm,
fixedfields={
'version': version,
'file': filename,
},
redirect='/docs/comment_submitted/'
)