SubEvent editing: Pass copy_from to plugins

This commit is contained in:
Raphael Michel
2021-01-27 18:22:36 +01:00
parent 418c9196ba
commit e09853c6c6
3 changed files with 12 additions and 6 deletions

View File

@@ -291,7 +291,7 @@ As with all plugin signals, the ``sender`` keyword argument will contain the eve
"""
subevent_forms = EventPluginSignal(
providing_args=['request', 'subevent']
providing_args=['request', 'subevent', 'copy_from']
)
"""
This signal allows you to return additional forms that should be rendered on the subevent creation
@@ -301,7 +301,8 @@ as part of the standard validation and rendering cycle and rendered using defaul
styles. It is advisable to set a prefix for your form to avoid clashes with other plugins.
``subevent`` can be ``None`` during creation. Before ``save()`` is called, a ``subevent`` property of
your form instance will automatically being set to the subevent that has just been created.
your form instance will automatically being set to the subevent that has just been created. During
creation, ``copy_from`` can be a subevent that is being copied from.
As with all plugin signals, the ``sender`` keyword argument will contain the event.
"""

View File

@@ -151,7 +151,8 @@ class SubEventEditorMixin(MetaDataEditorMixin):
@cached_property
def plugin_forms(self):
forms = []
for rec, resp in subevent_forms.send(sender=self.request.event, subevent=self.object, request=self.request):
for rec, resp in subevent_forms.send(sender=self.request.event, subevent=self.object, request=self.request,
copy_from=self.copy_from):
if isinstance(resp, (list, tuple)):
forms.extend(resp)
else:
@@ -323,7 +324,7 @@ class SubEventEditorMixin(MetaDataEditorMixin):
@cached_property
def copy_from(self):
if self.request.GET.get("copy_from") and not getattr(self, 'object', None):
if self.request.GET.get("copy_from") and (not getattr(self, 'object', None) or not self.object.pk):
try:
return self.request.event.subevents.get(pk=self.request.GET.get("copy_from"))
except SubEvent.DoesNotExist: