Remove "/static/" from doc URLs.

This creates a permanent redirect for any doc URL that references the
"static" path (i.e. all doc URLs), which allows a format similar to:

/docs/current/index.html

This is in response to not having "interactive" as an available option,
which should lead to shorter, less confusing URLs.
This commit is contained in:
Jonathan S. Katz
2018-11-04 11:32:18 -05:00
parent 1da9859a11
commit 17f9b7f070
2 changed files with 19 additions and 14 deletions

View File

@ -17,7 +17,7 @@ from pgweb.core.models import Version
from models import DocPage
from forms import DocCommentForm
def docpage(request, version, typ, filename):
def docpage(request, version, filename):
loaddate = None
# Get the current version both to map the /current/ url, and to later
# determine if we allow comments on this page.
@ -25,8 +25,6 @@ def docpage(request, version, typ, filename):
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:
@ -49,7 +47,7 @@ def docpage(request, version, typ, filename):
if ver >= 10 and version.find('.') > -1:
# Version 10 and up, but specified as 10.0 / 11.0 etc, so redirect back without the
# decimal.
return HttpResponseRedirect("/docs/{0}/static/{1}.html".format(int(ver), filename))
return HttpResponsePermanentRedirect("/docs/{0}/{1}.html".format(int(ver), filename))
fullname = "%s.%s" % (filename, extension)
page = get_object_or_404(DocPage, version=ver, file=fullname)
@ -61,10 +59,6 @@ def docpage(request, version, typ, filename):
'testing':"COALESCE((SELECT testing FROM core_version v WHERE v.tree=version),0)",
}).order_by('-supported', 'version').only('version', 'file')
if typ=="interactive":
# Interactive documents are disabled, so redirect to static page
return HttpResponsePermanentRedirect("/docs/{0}/static/{1}.html".format(version, filename))
return render(request, 'docs/docspage.html', {
'page': page,
'supported_versions': [v for v in versions if v.supported],
@ -75,11 +69,20 @@ def docpage(request, version, typ, filename):
'loaddate': loaddate,
})
def docsrootpage(request, version, typ):
return docpage(request, version, typ, 'index')
def docspermanentredirect(request, version, typ, page, *args):
"""Provides a permanent redirect from the old static/interactive pages to
the modern pages that do not have said keywords.
"""
url = "/docs/{}/".format(version)
if page:
url += page
return HttpResponsePermanentRedirect(url)
def docsrootpage(request, version):
return docpage(request, version, 'index')
def redirect_root(request, version):
return HttpResponseRedirect("/docs/%s/static/" % version)
return HttpResponsePermanentRedirect("/docs/%s/" % version)
def root(request):
versions = Version.objects.filter(Q(supported=True) | Q(testing__gt=0,tree__gt=0)).order_by('-tree')
@ -130,7 +133,7 @@ def commentform(request, itemid, version, filename):
v = get_object_or_404(Version, tree=version)
if not v.supported:
# No docs comments on unsupported versions
return HttpResponseRedirect("/docs/{0}/static/{1}".format(version, filename))
return HttpResponseRedirect("/docs/{0}/{1}".format(version, filename))
if request.method == 'POST':
form = DocCommentForm(request.POST)

View File

@ -57,8 +57,10 @@ urlpatterns = [
url(r'^docs/$', pgweb.docs.views.root),
url(r'^docs/manuals/$', pgweb.docs.views.manuals),
url(r'^docs/manuals/archive/$', pgweb.docs.views.manualarchive),
url(r'^docs/(current|devel|\d+(?:\.\d)?)/(static|interactive)/(.*).html?$', pgweb.docs.views.docpage),
url(r'^docs/(current|devel|\d+(?:\.\d)?)/(static|interactive)/$', pgweb.docs.views.docsrootpage),
# Legacy URLs for accessing the docs page; provides a permanent redirect
url(r'^docs/(current|devel|\d+(?:\.\d)?)/(static|interactive)/((.*).html?)?$', pgweb.docs.views.docspermanentredirect),
url(r'^docs/(current|devel|\d+(?:\.\d)?)/(.*).html?$', pgweb.docs.views.docpage),
url(r'^docs/(current|devel|\d+(?:\.\d)?)/$', pgweb.docs.views.docsrootpage),
url(r'^docs/(current|devel|\d+(?:\.\d)?)/$', pgweb.docs.views.redirect_root),
url(r'^community/$', pgweb.core.views.community),