Support css & js overrides

This commit is contained in:
Daniel Quinn
2018-07-08 16:06:57 +01:00
parent ff85fb2a23
commit 52f1859455
7 changed files with 116 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
{% extends 'admin/base_site.html' %}
{# NOTE: This should probably be extending base.html. See CSS comment below details. #}
{% load custom_css from customisation %}
{% load custom_js from customisation %}
{% block blockbots %}
{% comment %}
This really should be extending `extrastyle`, but the the
django-flat-responsive package decided that it wanted to put its CSS in
this block, so to make sure that overrides are in fact overriding
everything else, we have to do the Wrong Thing here.
Once we switch to Django 2.x and drop django-flat-responsive, we should
switch this to `extrastyle` where it should be.
{% endcomment %}
{{ block.super }}
{% custom_css %}
{% endblock blockbots %}
{% block footer %}
{% comment %}
The Django admin doesn't have a block for Javascript you'd want placed in
the footer, so we have to use this one instead.
{% endcomment %}
{{ block.super }}
{% custom_js %}
{% endblock footer %}

View File

@@ -0,0 +1,37 @@
import os
from django import template
from django.conf import settings
from django.utils.safestring import mark_safe
register = template.Library()
@register.simple_tag()
def custom_css():
theme_path = os.path.join(
settings.MEDIA_ROOT,
"overrides.css"
)
if os.path.exists(theme_path):
return mark_safe(
'<link rel="stylesheet" type="text/css" href="{}" />'.format(
os.path.join(settings.MEDIA_URL, "overrides.css")
)
)
return ""
@register.simple_tag()
def custom_js():
theme_path = os.path.join(
settings.MEDIA_ROOT,
"overrides.js"
)
if os.path.exists(theme_path):
return mark_safe(
'<script src="{}"></script>'.format(
os.path.join(settings.MEDIA_URL, "overrides.js")
)
)
return ""