mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +00:00
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:
@ -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.
|
||||
|
Reference in New Issue
Block a user