Allow displaying SVG images in documentation

PostgreSQL 12 adds SVG images in the documentation, so the website
should be able to display them.

The images themselves were already loaded by the docsloader, but the
regexps in the URL would block them from being seen. Fix this by
creating a separate function for the SVGs, since we also don't want to
render them inside teh templates.

This new view must also be tagged with @allow_frames, since the browser
considers the <object> tag used to be a subframe. Without this, they
would be blocked from viewing even on our own site.
This commit is contained in:
Magnus Hagander
2019-03-31 14:19:45 +02:00
parent a23b22f8d5
commit 6587592ee1
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.http import Http404
from django.http import HttpResponse, Http404
from pgweb.util.decorators import login_required, allow_frames, content_sources
from django.db.models import Q
from django.conf import settings
@ -113,6 +113,25 @@ def docpage(request, version, filename):
})
@allow_frames
def docsvg(request, version, filename):
if version == 'current':
ver = Version.objects.filter(current=True)[0].tree
elif version == 'devel':
ver = Decimal(0)
else:
ver = Decimal(version)
if ver == Decimal(0):
raise Http404("Version not found")
if ver < Decimal(12) and ver > Decimal(0):
raise Http404("SVG images don't exist in this version")
page = get_object_or_404(DocPage, version=ver, file="{0}.svg".format(filename))
return HttpResponse(page.content, content_type="image/svg+xml")
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.