From 4636ccac3bcdc06b31e938ee6d84129b6c752585 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 27 Mar 2019 09:14:51 +0100 Subject: [PATCH] Add signals html_page_header, sass_preamble, sass_postamble --- doc/development/api/general.rst | 2 +- src/pretix/presale/context.py | 6 ++- src/pretix/presale/signals.py | 38 +++++++++++++++++++ src/pretix/presale/style.py | 9 +++++ .../presale/templates/pretixpresale/base.html | 1 + .../static/pretixbase/scss/_variables.scss | 16 ++++---- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index f88212bd56..98984c3076 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -26,7 +26,7 @@ Frontend -------- .. automodule:: pretix.presale.signals - :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional + :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, fee_calculation_for_cart, contact_form_fields, question_form_fields, checkout_confirm_messages, checkout_confirm_page_content, checkout_all_optional, html_page_header, sass_preamble, sass_postamble .. automodule:: pretix.presale.signals diff --git a/src/pretix/presale/context.py b/src/pretix/presale/context.py index 24e2e98f15..6735a5ddac 100644 --- a/src/pretix/presale/context.py +++ b/src/pretix/presale/context.py @@ -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 diff --git a/src/pretix/presale/signals.py b/src/pretix/presale/signals.py index 8aed761808..8cca4ac085 100644 --- a/src/pretix/presale/signals.py +++ b/src/pretix/presale/signals.py @@ -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 ```` 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"] ) diff --git a/src/pretix/presale/style.py b/src/pretix/presale/style.py index 6a98da43a9..a7fff3e4b5 100644 --- a/src/pretix/presale/style.py +++ b/src/pretix/presale/style.py @@ -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( diff --git a/src/pretix/presale/templates/pretixpresale/base.html b/src/pretix/presale/templates/pretixpresale/base.html index 7d7e215b54..beb7b5341f 100644 --- a/src/pretix/presale/templates/pretixpresale/base.html +++ b/src/pretix/presale/templates/pretixpresale/base.html @@ -59,6 +59,7 @@ +{{ html_page_header|safe }} {% block above %} {% endblock %}
diff --git a/src/pretix/static/pretixbase/scss/_variables.scss b/src/pretix/static/pretixbase/scss/_variables.scss index 917353cfd6..2bab686d1d 100644 --- a/src/pretix/static/pretixbase/scss/_variables.scss +++ b/src/pretix/static/pretixbase/scss/_variables.scss @@ -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;