Add new signal logentry_object_link

This commit is contained in:
Raphael Michel
2017-09-13 17:36:13 +02:00
parent 9cd3e2d494
commit ed35c4f74e
5 changed files with 51 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ Backend
.. automodule:: pretix.base.signals
:members: logentry_display, requiredaction_display
:members: logentry_display, logentry_object_link, requiredaction_display
Vouchers
""""""""

View File

@@ -114,6 +114,19 @@ method to make your receivers available::
def ready(self):
from . import signals # NOQA
You can optionally specify code that is executed when your plugin is activated for an event
in the ``installed`` method::
class PaypalApp(AppConfig):
def installed(self, event):
pass # Your code here
Note that ``installed`` will *not* be called if the plugin in indirectly activated for an event
because the event is created with settings copied from another event.
Views
-----

View File

@@ -8,6 +8,8 @@ from django.utils.functional import cached_property
from django.utils.html import escape
from django.utils.translation import pgettext_lazy, ugettext_lazy as _
from pretix.base.signals import logentry_object_link
class LogEntry(models.Model):
"""
@@ -146,6 +148,9 @@ class LogEntry(models.Model):
elif a_text:
return a_text
else:
for receiver, response in logentry_object_link.send(self.event, logentry=self):
if response:
return response
return ''
@cached_property

View File

@@ -166,6 +166,34 @@ to the user. The receivers are expected to return plain text.
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
"""
logentry_object_link = EventPluginSignal(
providing_args=["logentry"]
)
"""
To display the relationship of an instance of the ``LogEntry`` model to another model
to a human user, ``pretix.base.signals.logentry_object_link`` will be sent out with a
``logentry`` argument.
The first received response that is not ``None`` will be used to display the related object
to the user. The receivers are expected to return a HTML link. The internal implementation
builds the links like this::
a_text = _('Tax rule {val}')
a_map = {
'href': reverse('control:event.settings.tax.edit', kwargs={
'event': sender.slug,
'organizer': sender.organizer.slug,
'rule': logentry.content_object.id
}),
'val': escape(logentry.content_object.name),
}
a_map['val'] = '<a href="{href}">{val}</a>'.format_map(a_map)
return a_text.format_map(a_map)
Make sure that any user content in the HTML code you return is properly escaped!
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
"""
requiredaction_display = EventPluginSignal(
providing_args=["action", "request"]
)

View File

@@ -205,6 +205,10 @@ class EventPlugins(EventSettingsViewMixin, EventPermissionRequiredMixin, Templat
if getattr(plugins_available[module], 'restricted', False):
if not request.user.is_superuser:
continue
if hasattr(plugins_available[module].app, 'installed'):
getattr(plugins_available[module].app, 'installed')(self.request.event)
self.request.event.log_action('pretix.event.plugins.enabled', user=self.request.user,
data={'plugin': module})
if module not in plugins_active: