from django.contrib import admin
-from .models import DocPageAlias
+from .models import DocPageAlias, DocPageRedirect
admin.site.register(DocPageAlias)
+admin.site.register(DocPageRedirect)
--- /dev/null
+# 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',
+ },
+ ),
+ ]
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"
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
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],