API: Fix cloning events with meta data (PRETIXEU-9FZ)

This commit is contained in:
Raphael Michel
2023-12-05 12:57:14 +01:00
parent c8b8fba171
commit d6d6b73a38
5 changed files with 12 additions and 14 deletions
+2 -2
View File
@@ -343,8 +343,8 @@ Endpoints
Creates a new event with properties as set in the request body. The properties that are copied are: ``is_public``,
``testmode``, ``has_subevents``, settings, plugin settings, items, variations, add-ons, quotas, categories, tax rules, questions.
If the ``plugins``, ``has_subevents`` and/or ``is_public`` fields are present in the post body this will determine their
value. Otherwise their value will be copied from the existing event.
If the ``plugins``, ``has_subevents``, ``meta_data`` and/or ``is_public`` fields are present in the post body this will
determine their value. Otherwise their value will be copied from the existing event.
Please note that you can only copy from events under the same organizer this way. Use the ``clone_from`` parameter
when creating a new event for this instead.
+1 -1
View File
@@ -424,7 +424,7 @@ class CloneEventSerializer(EventSerializer):
new_event = super().create({**validated_data, 'plugins': None})
event = Event.objects.filter(slug=self.context['event'], organizer=self.context['organizer'].pk).first()
new_event.copy_data_from(event)
new_event.copy_data_from(event, skip_meta_data='meta_data' in validated_data)
if plugins is not None:
new_event.set_active_plugins(plugins)
+1 -1
View File
@@ -254,7 +254,7 @@ class EventViewSet(viewsets.ModelViewSet):
new_event = serializer.save(organizer=self.request.organizer)
if copy_from:
new_event.copy_data_from(copy_from)
new_event.copy_data_from(copy_from, skip_meta_data='meta_data' in serializer.validated_data)
if plugins is not None:
new_event.set_active_plugins(plugins)
+6 -5
View File
@@ -775,7 +775,7 @@ class Event(EventMixin, LoggedModel):
time(hour=23, minute=59, second=59)
), tz)
def copy_data_from(self, other):
def copy_data_from(self, other, skip_meta_data=False):
from pretix.presale.style import regenerate_css
from ..signals import event_copy_data
@@ -798,10 +798,11 @@ class Event(EventMixin, LoggedModel):
self.save()
self.log_action('pretix.object.cloned', data={'source': other.slug, 'source_id': other.pk})
for emv in EventMetaValue.objects.filter(event=other):
emv.pk = None
emv.event = self
emv.save(force_insert=True)
if not skip_meta_data:
for emv in EventMetaValue.objects.filter(event=other):
emv.pk = None
emv.event = self
emv.save(force_insert=True)
for fl in EventFooterLink.objects.filter(event=other):
fl.pk = None
+2 -5
View File
@@ -416,7 +416,7 @@ def test_event_create_with_clone(token_client, organizer, event, meta_prop, urls
"location": None,
"slug": "2030",
"meta_data": {
"type": "Conference"
"type": "Workshop"
},
"plugins": [
"pretix.plugins.ticketoutputpdf"
@@ -434,7 +434,7 @@ def test_event_create_with_clone(token_client, organizer, event, meta_prop, urls
assert cloned_event.testmode
assert cloned_event.date_admission.isoformat() == "2018-12-27T08:00:00+00:00"
assert organizer.events.get(slug="2030").meta_values.filter(
property__name=meta_prop.name, value="Conference"
property__name=meta_prop.name, value="Workshop"
).exists()
assert cloned_event.settings.timezone == "Europe/Vienna"
@@ -454,9 +454,6 @@ def test_event_create_with_clone(token_client, organizer, event, meta_prop, urls
"presale_end": None,
"location": None,
"slug": "2031",
"meta_data": {
"type": "Conference"
}
},
format='json'
)