Add new signal nav_item

This commit is contained in:
Raphael Michel
2019-06-14 12:20:06 +02:00
parent 44bef85b66
commit 1ce613ff89
4 changed files with 39 additions and 2 deletions

View File

@@ -237,6 +237,24 @@ As with all plugin signals, the ``sender`` keyword argument will contain the eve
A second keyword argument ``request`` will contain the request object.
"""
nav_item = EventPluginSignal(
providing_args=['request', 'item']
)
"""
This signal is sent out to include tab links on the settings page of an item.
Receivers are expected to return a list of dictionaries. The dictionaries
should contain at least the keys ``label`` and ``url``. You should also return
an ``active`` key with a boolean set to ``True``, when this item should be marked
as active.
If your linked view should stay in the tab-like context of this page, we recommend
that you use ``pretix.control.views.item.ItemDetailMixin`` for your view
and your template inherits from ``pretixcontrol/item/base.html``.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
A second keyword argument ``request`` will contain the request object.
"""
event_settings_widget = EventPluginSignal(
providing_args=['request']
)

View File

@@ -27,6 +27,13 @@
{% trans "Bundled products" %}
</a>
</li>
{% for n in extra_nav %}
<li {% if n.active %}class="active"{% endif %}>
<a href="{{ n.url }}">
{{ n.label }}
</a>
</li>
{% endfor %}
</ul>
{% else %}
<h1>{% trans "Create product" %}</h1>

View File

@@ -33,7 +33,7 @@ from pretix.control.forms.item import (
from pretix.control.permissions import (
EventPermissionRequiredMixin, event_permission_required,
)
from pretix.control.signals import item_forms
from pretix.control.signals import item_forms, nav_item
from . import ChartContainingView, CreateView, PaginationMixin, UpdateView
@@ -782,6 +782,18 @@ class ItemDetailMixin(SingleObjectMixin):
model = Item
context_object_name = 'item'
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
nav = sorted(
sum(
(list(a[1]) for a in nav_item.send(self.request.event, request=self.request, item=self.get_object())),
[]
),
key=lambda r: str(r['label'])
)
ctx['extra_nav'] = nav
return ctx
def get_object(self, queryset=None) -> Item:
try:
if not hasattr(self, 'object') or not self.object: