From 39513448f300530a4543a733a5b604cc9402084c Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 26 Apr 2017 12:55:44 +0200 Subject: [PATCH] Add signal nav_global --- doc/development/api/general.rst | 2 +- src/pretix/control/context.py | 10 +++++-- src/pretix/control/signals.py | 21 ++++++++++++++- .../control/templates/pretixcontrol/base.html | 26 +++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index b02c6b486..e9a2dd9ad 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -47,7 +47,7 @@ Backend ------- .. automodule:: pretix.control.signals - :members: nav_event, html_head, quota_detail_html, nav_topbar, organizer_edit_tabs + :members: nav_event, html_head, quota_detail_html, nav_topbar, nav_global, organizer_edit_tabs .. automodule:: pretix.base.signals diff --git a/src/pretix/control/context.py b/src/pretix/control/context.py index 83027432c..7589d1778 100644 --- a/src/pretix/control/context.py +++ b/src/pretix/control/context.py @@ -5,7 +5,7 @@ from django.core.urlresolvers import Resolver404, get_script_prefix, resolve from pretix.base.settings import GlobalSettingsObject -from .signals import html_head, nav_event, nav_topbar +from .signals import html_head, nav_event, nav_global, nav_topbar from .utils.i18n import get_javascript_format, get_moment_locale @@ -38,8 +38,14 @@ def contextprocessor(request): _nav_event += response if request.event.settings.get('payment_term_weekdays'): _js_payment_weekdays_disabled = '[0,6]' - ctx['js_payment_weekdays_disabled'] = _js_payment_weekdays_disabled ctx['nav_event'] = _nav_event + ctx['js_payment_weekdays_disabled'] = _js_payment_weekdays_disabled + + _nav_global = [] + if not hasattr(request, 'event'): + for receiver, response in nav_global.send(request, request=request): + _nav_global += response + ctx['nav_global'] = _nav_global _nav_topbar = [] for receiver, response in nav_topbar.send(request, request=request): diff --git a/src/pretix/control/signals.py b/src/pretix/control/signals.py index c94524a8a..8776712b8 100644 --- a/src/pretix/control/signals.py +++ b/src/pretix/control/signals.py @@ -47,7 +47,7 @@ nav_topbar = Signal( ) """ This signal allows you to add additional views to the top navigation bar. -You will get the request as a keyword argument ``return``. +You will get the request as a keyword argument ``request``. 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 @@ -61,6 +61,25 @@ This is no ``EventPluginSignal``, so you do not get the event in the ``sender`` and you may get the signal regardless of whether your plugin is active. """ +nav_global = Signal( + providing_args=["request"] +) +""" +This signal allows you to add additional views to the navigation bar when no event is +selected. You will get the request as a keyword argument ``request``. +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. + +If you use this, you should read the documentation on :ref:`how to deal with URLs ` +in pretix. + +This is no ``EventPluginSignal``, so you do not get the event in the ``sender`` argument +and you may get the signal regardless of whether your plugin is active. +""" + event_dashboard_widgets = EventPluginSignal( providing_args=[] ) diff --git a/src/pretix/control/templates/pretixcontrol/base.html b/src/pretix/control/templates/pretixcontrol/base.html index 1cb7693ce..fef6124b7 100644 --- a/src/pretix/control/templates/pretixcontrol/base.html +++ b/src/pretix/control/templates/pretixcontrol/base.html @@ -168,6 +168,32 @@ {% trans "Organizers" %} + {% for nav in nav_global %} +
  • + + {% if nav.icon %} + + {% endif %} + {{ nav.label }} + + {% if nav.children %} + + + + + {% endif %} +
  • + {% endfor %} {% endblock %}