mirror of
https://github.com/pretix/pretix.git
synced 2026-09-14 16:24:43 +00:00
* add copy item info functionality * fix formatting * Revert "fix formatting" This reverts commit779bd79e8b. * Revert "add copy item info functionality" This reverts commitdbec76bf5a. * add copy functionality * copy questions from item * add copy functionality * copy questions from item * add copy functionality * copy questions from item
This commit is contained in:
committed by
Raphael Michel
parent
4c2c302bfd
commit
8661bfe4a4
@@ -105,12 +105,32 @@ class ItemCreateForm(I18nModelForm):
|
|||||||
'You can select the variations in the next step.'),
|
'You can select the variations in the next step.'),
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.event = kwargs['event']
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
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):
|
def save(self, *args, **kwargs):
|
||||||
instance = super().save(*args, **kwargs)
|
instance = super().save(*args, **kwargs)
|
||||||
if self.cleaned_data.get('has_variations'):
|
if self.cleaned_data.get('has_variations'):
|
||||||
ItemVariation.objects.create(
|
if self.cleaned_data.get('copy_from') and self.cleaned_data.get('copy_from').has_variations:
|
||||||
item=instance, value=__('Standard')
|
for variation in self.cleaned_data['copy_from'].variations.all():
|
||||||
)
|
ItemVariation.objects.create(item=instance, value=variation.value, active=variation.active,
|
||||||
|
position=variation.position, default_price=variation.default_price)
|
||||||
|
else:
|
||||||
|
ItemVariation.objects.create(
|
||||||
|
item=instance, value=__('Standard')
|
||||||
|
)
|
||||||
|
|
||||||
|
for question in Question.objects.filter(items=self.cleaned_data.get('copy_from')):
|
||||||
|
question.items.add(instance)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{% trans "General information" %}</legend>
|
<legend>{% trans "General information" %}</legend>
|
||||||
{% bootstrap_field form.name layout="horizontal" %}
|
{% bootstrap_field form.name layout="horizontal" %}
|
||||||
|
{% bootstrap_field form.copy_from layout="horizontal" %}
|
||||||
{% bootstrap_field form.has_variations layout="horizontal" %}
|
{% bootstrap_field form.has_variations layout="horizontal" %}
|
||||||
{% bootstrap_field form.admission layout="horizontal" %}
|
{% bootstrap_field form.admission layout="horizontal" %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@@ -766,6 +766,16 @@ class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
|||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
messages.success(self.request, _('Your changes have been saved.'))
|
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)
|
ret = super().form_valid(form)
|
||||||
form.instance.log_action('pretix.event.item.added', user=self.request.user, data={
|
form.instance.log_action('pretix.event.item.added', user=self.request.user, data={
|
||||||
k: (form.cleaned_data.get(k).name
|
k: (form.cleaned_data.get(k).name
|
||||||
|
|||||||
Reference in New Issue
Block a user