forked from CGM_Public/pretix_original
Allow creating multiple events in different tabs at the same time
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import logging
|
||||
|
||||
import i18nfield.forms
|
||||
from django import forms
|
||||
from django.forms.models import ModelFormMetaclass
|
||||
from django.utils import six
|
||||
from django.utils.crypto import get_random_string
|
||||
from formtools.wizard.views import SessionWizardView
|
||||
from hierarkey.forms import HierarkeyForm
|
||||
|
||||
from pretix.base.models import Event
|
||||
@@ -71,3 +73,29 @@ class SettingsForm(i18nfield.forms.I18nFormMixin, HierarkeyForm):
|
||||
fname = '%s/%s.%s.%s' % (self.obj.slug, name, nonce, name.split('.')[-1])
|
||||
# TODO: make sure pub is always correct
|
||||
return 'pub/' + fname
|
||||
|
||||
|
||||
class PrefixForm(forms.Form):
|
||||
prefix = forms.CharField(widget=forms.HiddenInput)
|
||||
|
||||
|
||||
class SafeSessionWizardView(SessionWizardView):
|
||||
def get_prefix(self, request, *args, **kwargs):
|
||||
if hasattr(request, '_session_wizard_prefix'):
|
||||
return request._session_wizard_prefix
|
||||
prefix_form = PrefixForm(self.request.POST, prefix=super().get_prefix(request, *args, **kwargs))
|
||||
if not prefix_form.is_valid():
|
||||
request._session_wizard_prefix = get_random_string(length=24)
|
||||
else:
|
||||
request._session_wizard_prefix = prefix_form.cleaned_data['prefix']
|
||||
return request._session_wizard_prefix
|
||||
|
||||
def get_context_data(self, form, **kwargs):
|
||||
context = super().get_context_data(form=form, **kwargs)
|
||||
context['wizard']['prefix_form'] = PrefixForm(
|
||||
prefix=super().get_prefix(self.request),
|
||||
initial={
|
||||
'prefix': self.get_prefix(self.request)
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
{{ wizard.management_form }}
|
||||
{{ wizard.prefix_form }}
|
||||
{% bootstrap_form_errors form %}
|
||||
{% block form %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -12,9 +12,9 @@ from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
from django.views import View
|
||||
from django.views.generic import ListView
|
||||
from formtools.wizard.views import SessionWizardView
|
||||
from i18nfield.strings import LazyI18nString
|
||||
|
||||
from pretix.base.forms import SafeSessionWizardView
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.models import Event, Organizer, Quota, Team
|
||||
from pretix.control.forms.event import (
|
||||
@@ -97,7 +97,7 @@ def condition_copy(wizard):
|
||||
return EventWizardCopyForm.copy_from_queryset(wizard.request.user).exists()
|
||||
|
||||
|
||||
class EventWizard(SessionWizardView):
|
||||
class EventWizard(SafeSessionWizardView):
|
||||
form_list = [
|
||||
('foundation', EventWizardFoundationForm),
|
||||
('basics', EventWizardBasicsForm),
|
||||
|
||||
Reference in New Issue
Block a user