diff --git a/src/pretix/base/forms/__init__.py b/src/pretix/base/forms/__init__.py index 6b38ddb10c..27187b1b9e 100644 --- a/src/pretix/base/forms/__init__.py +++ b/src/pretix/base/forms/__init__.py @@ -22,13 +22,13 @@ class BaseI18nModelForm(BaseModelForm): This is a helperclass to construct an I18nModelForm. """ def __init__(self, *args, **kwargs): - event = kwargs.pop('event', None) + self.event = kwargs.pop('event', None) locales = kwargs.pop('locales', None) super().__init__(*args, **kwargs) - if event or locales: + if self.event or locales: for k, field in self.fields.items(): if isinstance(field, I18nFormField): - field.widget.enabled_langcodes = event.settings.get('locales') if event else locales + field.widget.enabled_langcodes = self.event.settings.get('locales') if self.event else locales class I18nModelForm(six.with_metaclass(ModelFormMetaclass, BaseI18nModelForm)): diff --git a/src/pretix/control/forms/item.py b/src/pretix/control/forms/item.py index 6e1a20853e..d2b4dc187f 100644 --- a/src/pretix/control/forms/item.py +++ b/src/pretix/control/forms/item.py @@ -100,10 +100,21 @@ class QuotaForm(I18nModelForm): class ItemCreateForm(I18nModelForm): - has_variations = forms.BooleanField(label=_('The product should exist in multiple variations'), - help_text=_('Select this option e.g. for t-shirts that come in multiple sizes. ' - 'You can select the variations in the next step.'), - required=False) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['has_variations'] = forms.BooleanField(label=_('The product should exist in multiple variations'), + help_text=_( + 'Select this option e.g. for t-shirts that come in multiple sizes. ' + 'You can select the variations in the next step.'), + required=False) + self.fields['copy_from'] = forms.ModelChoiceField( + label=_("Copy product information"), + queryset=self.event.items.all(), + widget=forms.Select, + empty_label=_('Do not copy'), + required=False + ) def save(self, *args, **kwargs): instance = super().save(*args, **kwargs) diff --git a/src/pretix/control/templates/pretixcontrol/item/create.html b/src/pretix/control/templates/pretixcontrol/item/create.html index 2eeb17a995..e2095a84ce 100644 --- a/src/pretix/control/templates/pretixcontrol/item/create.html +++ b/src/pretix/control/templates/pretixcontrol/item/create.html @@ -9,6 +9,7 @@ {% bootstrap_field form.name layout="horizontal" %} {% bootstrap_field form.has_variations layout="horizontal" %} {% bootstrap_field form.admission layout="horizontal" %} + {% bootstrap_field form.copy_from layout="horizontal" %}
{% trans "Price settings" %} diff --git a/src/pretix/control/views/item.py b/src/pretix/control/views/item.py index 4a3ce985d4..9769bd4883 100644 --- a/src/pretix/control/views/item.py +++ b/src/pretix/control/views/item.py @@ -757,6 +757,16 @@ class ItemCreate(EventPermissionRequiredMixin, CreateView): @transaction.atomic def form_valid(self, form): messages.success(self.request, _('Your changes have been saved.')) + if form.cleaned_data['copy_from']: + form.instance.category = form.cleaned_data['copy_from'].category + form.instance.description = form.cleaned_data['copy_from'].description + form.instance.active = form.cleaned_data['copy_from'].active + form.instance.available_from = form.cleaned_data['copy_from'].available_from + form.instance.available_until = form.cleaned_data['copy_from'].available_until + form.instance.require_voucher = form.cleaned_data['copy_from'].require_voucher + form.instance.hide_without_voucher = form.cleaned_data['copy_from'].hide_without_voucher + form.instance.allow_cancel = form.cleaned_data['copy_from'].allow_cancel + ret = super().form_valid(form) form.instance.log_action('pretix.event.item.added', user=self.request.user, data={ k: (form.cleaned_data.get(k).name