Add signals html_page_header, sass_preamble, sass_postamble

This commit is contained in:
Raphael Michel
2019-03-27 09:14:51 +01:00
parent e3518bfb4b
commit 4636ccac3b
6 changed files with 62 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ from pretix.helpers.i18n import (
get_javascript_format_without_seconds, get_moment_locale,
)
from .signals import footer_link, html_footer, html_head
from .signals import footer_link, html_footer, html_head, html_page_header
def contextprocessor(request):
@@ -23,6 +23,7 @@ def contextprocessor(request):
'DEBUG': settings.DEBUG,
}
_html_head = []
_html_page_header = []
_html_foot = []
_footer = []
@@ -45,6 +46,8 @@ def contextprocessor(request):
if hasattr(request, 'event'):
for receiver, response in html_head.send(request.event, request=request):
_html_head.append(response)
for receiver, response in html_page_header.send(request.event, request=request):
_html_page_header.append(response)
for receiver, response in html_footer.send(request.event, request=request):
_html_foot.append(response)
for receiver, response in footer_link.send(request.event, request=request):
@@ -71,6 +74,7 @@ def contextprocessor(request):
ctx['html_head'] = "".join(_html_head)
ctx['html_foot'] = "".join(_html_foot)
ctx['html_page_header'] = "".join(_html_page_header)
ctx['footer'] = _footer
ctx['site_url'] = settings.SITE_URL

View File

@@ -11,6 +11,17 @@ of every page in the frontend. You will get the request as the keyword argument
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
html_page_header = EventPluginSignal(
providing_args=["request"]
)
"""
This signal allows you to put code right in the beginnong of the HTML ``<body>`` tag
of every page in the frontend. You will get the request as the keyword argument
``request`` and are expected to return plain HTML.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
html_footer = EventPluginSignal(
providing_args=["request"]
)
@@ -22,6 +33,33 @@ of every page in the frontend. You will get the request as the keyword argument
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
sass_preamble = EventPluginSignal(
providing_args=["filename"]
)
"""
This signal allows you to put SASS code at the beginning of the event-specific
stylesheet. Keep in mind that this will only be called/rebuilt when the user changes
display settings or pretix gets updated. You will get the filename that is being
generated (usually "main.scss" or "widget.scss"). This SASS code will be loaded *after*
setting of user-defined variables like colors and fonts but *before* pretix' SASS
code.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
sass_postamble = EventPluginSignal(
providing_args=["filename"]
)
"""
This signal allows you to put SASS code at the end of the event-specific
stylesheet. Keep in mind that this will only be called/rebuilt when the user changes
display settings or pretix gets updated. You will get the filename that is being
generated (usually "main.scss" or "widget.scss"). This SASS code will be loaded *after*
all of pretix' SASS code.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""
footer_link = EventPluginSignal(
providing_args=["request"]
)

View File

@@ -16,6 +16,7 @@ from pretix.base.models import Event, Event_SettingsStore, Organizer
from pretix.base.services.tasks import ProfiledTask
from pretix.celery_app import app
from pretix.multidomain.urlreverse import get_domain
from pretix.presale.signals import sass_postamble, sass_preamble
logger = logging.getLogger('pretix.presale.style')
affected_keys = ['primary_font', 'primary_color']
@@ -54,8 +55,16 @@ def compile_scss(object, file="main.scss", fonts=True):
font
))
if isinstance(object, Event):
for recv, resp in sass_preamble.send(object, filename=file):
sassrules.append(resp)
sassrules.append('@import "{}";'.format(file))
if isinstance(object, Event):
for recv, resp in sass_postamble.send(object, filename=file):
sassrules.append(resp)
cf = dict(django_libsass.CUSTOM_FUNCTIONS)
cf['static'] = static
css = sass.compile(

View File

@@ -59,6 +59,7 @@
<meta name="theme-color" content="{{ settings.primary_color|default:"#3b1c4a" }}">
</head>
<body class="nojs" data-locale="{{ request.LANGUAGE_CODE }}" data-now="{% now "U.u" %}" data-datetimeformat="{{ js_datetime_format }}" data-timeformat="{{ js_time_format }}" data-dateformat="{{ js_date_format }}" data-datetimelocale="{{ js_locale }}">
{{ html_page_header|safe }}
{% block above %}
{% endblock %}
<div class="container">

View File

@@ -14,8 +14,8 @@ $gray-lighter: lighten(#000, 93.5%);
$gray-lightest: lighten(#000, 97.25%);
$font-family-sans-serif: "Open Sans", "OpenSans", "Helvetica Neue", Helvetica, Arial, sans-serif !default;
$text-color: #222222;
$text-muted: #999999;
$text-color: #222222 !default;
$text-muted: #999999 !default;
$brand-primary: #7f5a91 !default;
$brand-success: #50a167 !default;
@@ -40,13 +40,13 @@ $navbar-inverse-link-hover-color: $gray-lighter;
$navbar-inverse-brand-hover-color: $gray-lighter;
$navbar-inverse-color: white;
$state-success-bg: white;
$state-success-bg: white !default;
$state-success-border: $brand-success;
$state-info-bg: white;
$state-info-bg: white !default;
$state-info-border: $brand-info;
$state-warning-bg: white;
$state-warning-bg: white !default;
$state-warning-border: $brand-warning;
$state-danger-bg: white;
$state-danger-bg: white !default;
$state-danger-border: $brand-danger;
$panel-success-border: tint($brand-success, 50%);
$panel-success-heading-bg: tint($brand-success, 50%);
@@ -54,5 +54,5 @@ $panel-danger-border: tint($brand-danger, 50%);
$panel-danger-heading-bg: tint($brand-danger, 50%);
$panel-warning-border: tint($brand-warning, 50%);
$panel-warning-heading-bg: tint($brand-warning, 50%);
$panel-default-border: #e5e5e5;
$panel-default-heading-bg: #e5e5e5;
$panel-default-border: #e5e5e5 !default;
$panel-default-heading-bg: #e5e5e5 !default;