diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst new file mode 100644 index 0000000000..e5cc847103 --- /dev/null +++ b/doc/development/api/general.rst @@ -0,0 +1,18 @@ +.. highlight:: python + :linenothreshold: 5 + +General APIs +============ + +This page lists some general signals and hooks which do not belong to a +specific type of plugin but might come in handy for various plugins. + +HTML head injection +------------------- + +These two signals allow you to put code inside the HTML ``
`` tag +of every page. One signal is for the frontend, one for the backend. You +won't get any arguments and can return plain HTML. + +* ``pretix.presale.signals.html_head`` +* ``pretix.control.signals.html_head`` \ No newline at end of file diff --git a/doc/development/api/index.rst b/doc/development/api/index.rst index 1be6a3a8c1..8089265f83 100644 --- a/doc/development/api/index.rst +++ b/doc/development/api/index.rst @@ -9,3 +9,4 @@ Contents: plugins restriction payment + general diff --git a/src/pretix/control/context.py b/src/pretix/control/context.py index 6c4d7b5699..d318b56fef 100644 --- a/src/pretix/control/context.py +++ b/src/pretix/control/context.py @@ -1,14 +1,23 @@ from django.conf import settings from django.core.urlresolvers import resolve +from .signals import html_head def contextprocessor(request): """ Adds data to all template contexts """ + url = resolve(request.path_info) + if url.namespace != 'control': + return {} ctx = { - 'url_name': resolve(request.path_info).url_name, + 'url_name': url.url_name, 'settings': settings, } + _html_head = [] + if hasattr(request, 'event'): + for receiver, response in html_head.send(request.event): + _html_head.append(response) + ctx['html_head'] = "".join(_html_head) return ctx diff --git a/src/pretix/control/signals.py b/src/pretix/control/signals.py index fe50902d33..a44ce0192b 100644 --- a/src/pretix/control/signals.py +++ b/src/pretix/control/signals.py @@ -8,3 +8,10 @@ This signal is sent out to build configuration forms for all restriction formset restriction_formset = EventPluginSignal( providing_args=["item"] ) + +""" +This signal is sent out to include code into the HTML tag +""" +html_head = EventPluginSignal( + providing_args=[] +) diff --git a/src/pretix/control/templates/pretixcontrol/base.html b/src/pretix/control/templates/pretixcontrol/base.html index 136afa9f08..4c9f876a21 100644 --- a/src/pretix/control/templates/pretixcontrol/base.html +++ b/src/pretix/control/templates/pretixcontrol/base.html @@ -17,6 +17,7 @@ {% endcompress %} + {{ html_head|safe }}