From 4c77e2f16e4669371823169076ed8791e6ca05e2 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 29 Jul 2020 18:29:44 +0200 Subject: [PATCH] Add signals global_html_head, global_html_page_header, and global_html_footer --- doc/development/api/general.rst | 2 +- src/pretix/presale/context.py | 11 ++++++++++- src/pretix/presale/signals.py | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index 72bcba527e..d16c8541d4 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -33,7 +33,7 @@ Frontend -------- .. automodule:: pretix.presale.signals - :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, front_page_bottom_widget, 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, render_seating_plan, checkout_flow_steps, position_info, position_info_top, item_description + :members: html_head, html_footer, footer_link, front_page_top, front_page_bottom, front_page_bottom_widget, 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, render_seating_plan, checkout_flow_steps, position_info, position_info_top, item_description, global_html_head, globla_html_footer, global_html_page_header .. automodule:: pretix.presale.signals diff --git a/src/pretix/presale/context.py b/src/pretix/presale/context.py index d409773609..77e7ea2b7a 100644 --- a/src/pretix/presale/context.py +++ b/src/pretix/presale/context.py @@ -12,7 +12,10 @@ from pretix.helpers.i18n import ( get_javascript_format_without_seconds, get_moment_locale, ) -from .signals import footer_link, html_footer, html_head, html_page_header +from .signals import ( + footer_link, global_html_footer, global_html_head, global_html_page_header, + html_footer, html_head, html_page_header, +) logger = logging.getLogger(__name__) @@ -56,12 +59,18 @@ def _default_context(request): ctx['footer_text'] = str(text) if hasattr(request, 'event') and get_scope(): + for receiver, response in global_html_head.send(None, request=request): + _html_head.append(response) for receiver, response in html_head.send(request.event, request=request): _html_head.append(response) + for receiver, response in global_html_page_header.send(None, request=request): + _html_page_header.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 global_html_footer.send(None, request=request): + _html_foot.append(response) for receiver, response in footer_link.send(request.event, request=request): if isinstance(response, list): _footer += response diff --git a/src/pretix/presale/signals.py b/src/pretix/presale/signals.py index b352223a48..eba269aea0 100644 --- a/src/pretix/presale/signals.py +++ b/src/pretix/presale/signals.py @@ -1,5 +1,40 @@ +from django.dispatch import Signal + from pretix.base.signals import EventPluginSignal +global_html_head = Signal( + providing_args=["request"] +) +""" +This signal allows you to put code inside 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. + +This signal is called regardless of whether your plugin is active for all pages of the system. +""" + +global_html_page_header = Signal( + providing_args=["request"] +) +""" +This signal allows you to put code right in the beginning 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. + +This signal is called regardless of whether your plugin is active for all pages of the system. +""" + +global_html_footer = Signal( + providing_args=["request"] +) +""" +This signal allows you to put code before the end 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. + +This signal is called regardless of whether your plugin is active for all pages of the system. +""" + html_head = EventPluginSignal( providing_args=["request"] )