From bbe272c35c52479e278594bcd738b86a7173da1e Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 26 Apr 2017 15:24:16 +0200 Subject: [PATCH] Fix #372 -- Plugin hook for "Copy from event" --- doc/development/api/general.rst | 2 +- src/pretix/base/models/event.py | 4 ++++ src/pretix/base/signals.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/development/api/general.rst b/doc/development/api/general.rst index e9a2dd9ad4..a56ba2291a 100644 --- a/doc/development/api/general.rst +++ b/doc/development/api/general.rst @@ -11,7 +11,7 @@ Core ---- .. automodule:: pretix.base.signals - :members: periodic_task, event_live_issues + :members: periodic_task, event_live_issues, event_copy_data Order events """""""""""" diff --git a/src/pretix/base/models/event.py b/src/pretix/base/models/event.py index 4d7a4df94c..352acafb50 100644 --- a/src/pretix/base/models/event.py +++ b/src/pretix/base/models/event.py @@ -226,6 +226,8 @@ class Event(LoggedModel): def copy_data_from(self, other): from . import ItemAddOn, ItemCategory, Item, Question, Quota + from ..signals import event_copy_data + self.plugins = other.plugins self.save() @@ -297,6 +299,8 @@ class Event(LoggedModel): s.value = 'file://' + newname s.save() + event_copy_data.send(sender=self, other=other) + def generate_invite_token(): return get_random_string(length=32, allowed_chars=string.ascii_lowercase + string.digits) diff --git a/src/pretix/base/signals.py b/src/pretix/base/signals.py index 8381a90973..19b7c65076 100644 --- a/src/pretix/base/signals.py +++ b/src/pretix/base/signals.py @@ -153,6 +153,21 @@ to the user. The receivers are expected to return HTML code. As with all event-plugin signals, the ``sender`` keyword argument will contain the event. """ +event_copy_data = EventPluginSignal( + providing_args=["other"] +) +""" +This signal is sent out when a new event is created as a clone of an existing event, i.e. +the settings from the older event are copied to the newer one. You can listen to this +signal to copy data or configuration stored within your plugin's models as well. + +You don't need to copy data inside the general settings storage which is cloned automatically, +but you might need to modify that data. + +The ``sender`` keyword argument will contain the event of the **new** event. The ``other`` +keyword argument will contain the event to **copy from**. +""" + periodic_task = django.dispatch.Signal() """ This is a regular django signal (no pretix event signal) that we send out every