0001-Introduce-documentation-redirects-for-doc-pages-that.patch
text/plain
Filename: 0001-Introduce-documentation-redirects-for-doc-pages-that.patch
Type: text/plain
Part: 0
Patch
Format: format-patch
Series: patch 0001
Subject: Introduce documentation redirects for doc pages that are renamed
| File | + | − |
|---|---|---|
| pgweb/docs/admin.py | 2 | 1 |
| pgweb/docs/migrations/0004_docpageredirect.py | 24 | 0 |
| pgweb/docs/models.py | 11 | 0 |
| pgweb/docs/views.py | 13 | 2 |
From e2120f0a80697d13dc6d951f363d01feb60c9b9d Mon Sep 17 00:00:00 2001
From: "Jonathan S. Katz" <jonathan.katz@crunchydata.com>
Date: Tue, 11 Feb 2020 14:41:46 -0500
Subject: [PATCH] Introduce documentation redirects for doc pages that are
renamed
The web documentation used to suffer from a problem that if a
documentation page were renamed in a newer version, any references
pointing to said documentation would be lost. For example, the feature
known as "Default Roles" was renamed to "Privileged Roles" but caused
a change in the URL.
This patch introduces the ability to create a "DocPageRedirect" by
specifying the previous name of the documentation page (e.g.
"default-roles.html") and the new name (e.g. "privileged-roles.html")
such that the continuity is preserved between versions.
---
pgweb/docs/admin.py | 3 ++-
pgweb/docs/migrations/0004_docpageredirect.py | 24 +++++++++++++++++++
pgweb/docs/models.py | 11 +++++++++
pgweb/docs/views.py | 15 ++++++++++--
4 files changed, 50 insertions(+), 3 deletions(-)
create mode 100644 pgweb/docs/migrations/0004_docpageredirect.py
diff --git a/pgweb/docs/admin.py b/pgweb/docs/admin.py
index d2f2590..79f1d12 100644
--- a/pgweb/docs/admin.py
+++ b/pgweb/docs/admin.py
@@ -1,5 +1,6 @@
from django.contrib import admin
-from .models import DocPageAlias
+from .models import DocPageAlias, DocPageRedirect
admin.site.register(DocPageAlias)
+admin.site.register(DocPageRedirect)
diff --git a/pgweb/docs/migrations/0004_docpageredirect.py b/pgweb/docs/migrations/0004_docpageredirect.py
new file mode 100644
index 0000000..d19f959
--- /dev/null
+++ b/pgweb/docs/migrations/0004_docpageredirect.py
@@ -0,0 +1,24 @@
+# Generated by Django 2.2.12 on 2020-04-24 23:16
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('docs', '0003_docs_alias'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='DocPageRedirect',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('redirect_from', models.CharField(max_length=64, unique=True, help_text='Page to redirect from, e.g. "old_page.html"')),
+ ('redirect_to', models.CharField(max_length=64, unique=True, help_text='Page to redirect to, e.g. "new_page.html"')),
+ ],
+ options={
+ 'verbose_name_plural': 'Doc page redirects',
+ },
+ ),
+ ]
diff --git a/pgweb/docs/models.py b/pgweb/docs/models.py
index 87afe1c..a4558a6 100644
--- a/pgweb/docs/models.py
+++ b/pgweb/docs/models.py
@@ -33,3 +33,14 @@ class DocPageAlias(models.Model):
class Meta:
db_table = 'docsalias'
verbose_name_plural = 'Doc page aliases'
+
+
+class DocPageRedirect(models.Model):
+ """DocPageRedirect offers the ability to redirect from a page that has been
+ completely removed from the PostgreSQL documentation
+ """
+ redirect_from = models.CharField(max_length=64, null=False, blank=False, unique=True, help_text='Page to redirect from, e.g. "old_page.html"')
+ redirect_to = models.CharField(max_length=64, null=False, blank=False, unique=True, help_text='Page to redirect from, e.g. "new_page.html"')
+
+ class Meta:
+ verbose_name_plural = "Doc page redirects"
diff --git a/pgweb/docs/views.py b/pgweb/docs/views.py
index 0566129..6763795 100644
--- a/pgweb/docs/views.py
+++ b/pgweb/docs/views.py
@@ -16,7 +16,7 @@ from pgweb.util.misc import send_template_mail
from pgweb.core.models import Version
from pgweb.util.db import exec_to_dict
-from .models import DocPage
+from .models import DocPage, DocPageRedirect
from .forms import DocCommentForm
@@ -94,7 +94,18 @@ def docpage(request, version, filename):
url += "{}/{}".format(release_version, fullname)
return HttpResponsePermanentRedirect(url)
- page = get_object_or_404(DocPage, version=ver, file=fullname)
+ # try to get the page outright. If it's not found, check to see if it's a
+ # doc alias with a redirect, and if so, redirect to that page
+ try:
+ page = DocPage.objects.get(version=ver, file=fullname)
+ except DocPage.DoesNotExist:
+ # if the page does not exist but there is a special pgae redirect, check
+ # for the existence of that. if that does not exist, then we're really
+ # done and can 404
+ page_redirect = get_object_or_404(DocPageRedirect, redirect_from=fullname)
+ url = "/docs/{}/{}".format(version, page_redirect.redirect_to)
+ return HttpResponsePermanentRedirect(url)
+
versions = DocPage.objects.extra(
where=["file=%s OR file IN (SELECT file2 FROM docsalias WHERE file1=%s) OR file IN (SELECT file1 FROM docsalias WHERE file2=%s)"],
params=[fullname, fullname, fullname],
--
2.21.1 (Apple Git-122.3)