forked from CGM_Public/pretix_original
Fix #349 -- Allow to clone an event
This commit is contained in:
@@ -9,7 +9,7 @@ from formtools.wizard.views import SessionWizardView
|
||||
|
||||
from pretix.base.models import Event, EventPermission
|
||||
from pretix.control.forms.event import (
|
||||
EventWizardBasicsForm, EventWizardFoundationForm,
|
||||
EventWizardBasicsForm, EventWizardCopyForm, EventWizardFoundationForm,
|
||||
)
|
||||
|
||||
|
||||
@@ -27,17 +27,25 @@ class EventList(ListView):
|
||||
)
|
||||
|
||||
|
||||
def condition_copy(wizard):
|
||||
return EventPermission.objects.filter(
|
||||
user=wizard.request.user, can_change_settings=True, can_change_items=True
|
||||
).exists()
|
||||
|
||||
|
||||
class EventWizard(SessionWizardView):
|
||||
form_list = [
|
||||
('foundation', EventWizardFoundationForm),
|
||||
('basics', EventWizardBasicsForm),
|
||||
('copy', EventWizardCopyForm),
|
||||
]
|
||||
templates = {
|
||||
'foundation': 'pretixcontrol/events/create_foundation.html',
|
||||
'basics': 'pretixcontrol/events/create_basics.html'
|
||||
'basics': 'pretixcontrol/events/create_basics.html',
|
||||
'copy': 'pretixcontrol/events/create_copy.html',
|
||||
}
|
||||
condition_dict = {
|
||||
|
||||
'copy': condition_copy
|
||||
}
|
||||
|
||||
def get_form_kwargs(self, step=None):
|
||||
@@ -55,6 +63,7 @@ class EventWizard(SessionWizardView):
|
||||
def done(self, form_list, form_dict, **kwargs):
|
||||
foundation_data = self.get_cleaned_data_for_step('foundation')
|
||||
basics_data = self.get_cleaned_data_for_step('basics')
|
||||
copy_data = self.get_cleaned_data_for_step('copy')
|
||||
|
||||
with transaction.atomic():
|
||||
event = form_dict['basics'].instance
|
||||
@@ -63,10 +72,6 @@ class EventWizard(SessionWizardView):
|
||||
form_dict['basics'].save()
|
||||
EventPermission.objects.create(event=event, user=self.request.user)
|
||||
|
||||
event.settings.set('timezone', basics_data['timezone'])
|
||||
event.settings.set('locale', basics_data['locale'])
|
||||
event.settings.set('locales', foundation_data['locales'])
|
||||
|
||||
logdata = {}
|
||||
for f in form_list:
|
||||
logdata.update({
|
||||
@@ -74,7 +79,16 @@ class EventWizard(SessionWizardView):
|
||||
})
|
||||
event.log_action('pretix.event.settings', user=self.request.user, data=logdata)
|
||||
|
||||
messages.success(self.request, _('The new event has been created.'))
|
||||
if copy_data and copy_data['copy_from_event']:
|
||||
from_event = copy_data['copy_from_event']
|
||||
event.copy_data_from(from_event)
|
||||
|
||||
event.settings.set('timezone', basics_data['timezone'])
|
||||
event.settings.set('locale', basics_data['locale'])
|
||||
event.settings.set('locales', foundation_data['locales'])
|
||||
|
||||
messages.success(self.request, _('The new event has been created. You can now adjust the event settings in '
|
||||
'detail.'))
|
||||
return redirect(reverse('control:event.settings', kwargs={
|
||||
'organizer': event.organizer.slug,
|
||||
'event': event.slug,
|
||||
|
||||
Reference in New Issue
Block a user