Skip to content

Commit

Permalink
API: Fix cloning events with meta data (PRETIXEU-9FZ)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Dec 5, 2023
1 parent c8b8fba commit d6d6b73
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions doc/api/resources/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/pretix/api/serializers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def create(self, validated_data):
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)
Expand Down
2 changes: 1 addition & 1 deletion src/pretix/api/views/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def perform_create(self, serializer):
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)
Expand Down
11 changes: 6 additions & 5 deletions src/pretix/base/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def payment_term_last(self):
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
Expand All @@ -798,10 +798,11 @@ def copy_data_from(self, other):
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
Expand Down
7 changes: 2 additions & 5 deletions src/tests/api/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand All @@ -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'
)
Expand Down

0 comments on commit d6d6b73

Please sign in to comment.