forked from CGM_Public/pretix_original
Provide a new API for plugins to add HTML to the <head> of the site
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <head> tag
|
||||
"""
|
||||
html_head = EventPluginSignal(
|
||||
providing_args=[]
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/sb-admin-2.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixcontrol/js/ui/main.js" %}"></script>
|
||||
{% endcompress %}
|
||||
{{ html_head|safe }}
|
||||
</head>
|
||||
<body>
|
||||
<div id="#wrapper">
|
||||
|
||||
21
src/pretix/presale/context.py
Normal file
21
src/pretix/presale/context.py
Normal file
@@ -0,0 +1,21 @@
|
||||
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 != 'presale':
|
||||
return {}
|
||||
|
||||
ctx = {
|
||||
}
|
||||
_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
|
||||
9
src/pretix/presale/signals.py
Normal file
9
src/pretix/presale/signals.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from pretix.base.signals import EventPluginSignal
|
||||
|
||||
|
||||
"""
|
||||
This signal is sent out to include code into the HTML <head> tag
|
||||
"""
|
||||
html_head = EventPluginSignal(
|
||||
providing_args=[]
|
||||
)
|
||||
@@ -14,6 +14,7 @@
|
||||
<script type="text/javascript" src="{% static "bootstrap/dist/js/bootstrap.js" %}"></script>
|
||||
<script type="text/javascript" src="{% static "pretixpresale/js/ui/main.js" %}"></script>
|
||||
{% endcompress %}
|
||||
{{ html_head|safe }}
|
||||
</head>
|
||||
<body>
|
||||
<div class="container event">
|
||||
|
||||
@@ -75,6 +75,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
||||
"django.core.context_processors.tz",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
'pretix.control.context.contextprocessor',
|
||||
'pretix.presale.context.contextprocessor',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'pretix.urls'
|
||||
|
||||
Reference in New Issue
Block a user