Add plugin API for adding items to the admin navigation

This commit is contained in:
Raphael Michel
2015-03-21 18:15:43 +01:00
parent a0b1a2e11b
commit 591ded3ff2
4 changed files with 39 additions and 3 deletions
+15 -1
View File
@@ -13,7 +13,21 @@ HTML head injection
These two signals allow you to put code inside the HTML ``<head>`` tag These two signals allow you to put code inside the HTML ``<head>`` tag
of every page. One signal is for the frontend, one for the backend. You of every page. One signal is for the frontend, one for the backend. You
will get the request as a keyword argument ``request`` and can return plain will get the request as a keyword argument ``request`` and can return plain
HTML. HTML. The ``request`` object will have an attribute ``event``.
* ``pretix.presale.signals.html_head`` * ``pretix.presale.signals.html_head``
* ``pretix.control.signals.html_head`` * ``pretix.control.signals.html_head``
Admin navigation
----------------
The following signals allow you to add additional views to the admin panel
navigation. You will get the request as a keyword argument ``return``.
Receivers are expected to return a list of dictionaries. The dictionaries
should contain at least the keys ``label`` and ``url``. You can also return
a fontawesome icon name with the key ``icon``, it will be respected depending
on the type of navigation. You should also return an ``active`` key with a boolean
set to ``True``, when this item should be marked as active. The ``request`` object
will have an attribute ``event``.
``pretix.control.signals.nav_event``:
The sidebar navigation when the admin has selected an event.
+6 -1
View File
@@ -1,6 +1,6 @@
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import resolve from django.core.urlresolvers import resolve
from .signals import html_head from .signals import html_head, nav_event
def contextprocessor(request): def contextprocessor(request):
@@ -20,4 +20,9 @@ def contextprocessor(request):
_html_head.append(response) _html_head.append(response)
ctx['html_head'] = "".join(_html_head) ctx['html_head'] = "".join(_html_head)
_nav_event = []
if hasattr(request, 'event'):
for receiver, response in nav_event.send(request.event, request=request):
_nav_event += response
ctx['nav_event'] = _nav_event
return ctx return ctx
+7
View File
@@ -15,3 +15,10 @@ This signal is sent out to include code into the HTML <head> tag
html_head = EventPluginSignal( html_head = EventPluginSignal(
providing_args=["request"] providing_args=["request"]
) )
"""
This signal is sent out to include navigation items in the event admin
"""
nav_event = EventPluginSignal(
providing_args=["request"]
)
@@ -81,4 +81,14 @@
{% trans "Orders" %} {% trans "Orders" %}
</a> </a>
</li> </li>
{% for nav in nav_event %}
<li>
<a href="{{ nav.url }}" {% if nav.active %}class="active"{% endif %}>
{% if nav.icon %}
<i class="fa fa-{{ nav.icon }} fa-fw"></i>
{% endif %}
{{ nav.label }}
</a>
</li>
{% endfor %}
{% endblock %} {% endblock %}