add copy item info functionality

This commit is contained in:
Adam Sumner
2017-01-30 19:57:31 -05:00
parent 4f4e5854f2
commit dbec76bf5a
4 changed files with 29 additions and 7 deletions
+3 -3
View File
@@ -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)):
+15 -4
View File
@@ -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)
@@ -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" %}
</fieldset>
<fieldset>
<legend>{% trans "Price settings" %}</legend>
+10
View File
@@ -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