Fix #879: Admins can now add custom CSS from their pod settings

This commit is contained in:
Eliot Berriot 2019-07-03 11:06:13 +02:00
parent 78ab153734
commit 7897c8ac7f
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
5 changed files with 84 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import html
import requests
import xml.sax.saxutils
from django import http
from django.conf import settings
@ -51,7 +52,13 @@ def serve_spa(request):
# let's inject our meta tags in the HTML
head += "\n" + "\n".join(render_tags(final_tags)) + "\n</head>"
css = get_custom_css() or ""
if css:
# We add the style add the end of the body to ensure it has the highest
# priority (since it will come after other stylesheets)
body, tail = tail.split("</body>", 1)
css = "<style>{}</style>".format(css)
tail = body + "\n" + css + "\n</body>" + tail
return http.HttpResponse(head + tail)
@ -128,6 +135,14 @@ def get_request_head_tags(request):
return match.func(request, *match.args, **match.kwargs)
def get_custom_css():
css = preferences.get("ui__custom_css").strip()
if not css:
return
return xml.sax.saxutils.escape(css)
class SPAFallbackMiddleware:
def __init__(self, get_response):
self.get_response = get_response