mirror of
https://github.com/pretix/pretix.git
synced 2026-05-09 15:54:03 +00:00
Use a simpler form for creating items
This commit is contained in:
@@ -97,7 +97,32 @@ class QuotaForm(I18nModelForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ItemFormGeneral(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 save(self, *args, **kwargs):
|
||||||
|
instance = super().save(*args, **kwargs)
|
||||||
|
if self.cleaned_data.get('has_variations'):
|
||||||
|
ItemVariation.objects.create(
|
||||||
|
item=instance, value=__('Standard')
|
||||||
|
)
|
||||||
|
return instance
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Item
|
||||||
|
localized_fields = '__all__'
|
||||||
|
fields = [
|
||||||
|
'name',
|
||||||
|
'admission',
|
||||||
|
'default_price',
|
||||||
|
'tax_rate',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ItemUpdateForm(I18nModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['category'].queryset = self.instance.event.categories.all()
|
self.fields['category'].queryset = self.instance.event.categories.all()
|
||||||
@@ -120,21 +145,6 @@ class ItemFormGeneral(I18nModelForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ItemCreateForm(ItemFormGeneral):
|
|
||||||
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 save(self, *args, **kwargs):
|
|
||||||
instance = super().save(*args, **kwargs)
|
|
||||||
if self.cleaned_data.get('has_variations'):
|
|
||||||
ItemVariation.objects.create(
|
|
||||||
item=instance, value=__('Standard')
|
|
||||||
)
|
|
||||||
return instance
|
|
||||||
|
|
||||||
|
|
||||||
class ItemVariationForm(I18nModelForm):
|
class ItemVariationForm(I18nModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ItemVariation
|
model = ItemVariation
|
||||||
|
|||||||
24
src/pretix/control/templates/pretixcontrol/item/create.html
Normal file
24
src/pretix/control/templates/pretixcontrol/item/create.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{% extends "pretixcontrol/item/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
{% block inside %}
|
||||||
|
<form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
|
||||||
|
{% csrf_token %}
|
||||||
|
<fieldset>
|
||||||
|
<legend>{% trans "General information" %}</legend>
|
||||||
|
{% bootstrap_field form.name layout="horizontal" %}
|
||||||
|
{% bootstrap_field form.has_variations layout="horizontal" %}
|
||||||
|
{% bootstrap_field form.admission layout="horizontal" %}
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>{% trans "Price settings" %}</legend>
|
||||||
|
{% bootstrap_field form.default_price layout="horizontal" %}
|
||||||
|
{% bootstrap_field form.tax_rate layout="horizontal" %}
|
||||||
|
</fieldset>
|
||||||
|
<div class="form-group submit-group">
|
||||||
|
<button type="submit" class="btn btn-primary btn-save">
|
||||||
|
{% trans "Save and continue with more settings" %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
@@ -8,9 +8,6 @@
|
|||||||
<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.active layout="horizontal" %}
|
{% bootstrap_field form.active layout="horizontal" %}
|
||||||
{% if form.has_variations %}
|
|
||||||
{% bootstrap_field form.has_variations layout="horizontal" %}
|
|
||||||
{% endif %}
|
|
||||||
{% bootstrap_field form.category layout="horizontal" %}
|
{% bootstrap_field form.category layout="horizontal" %}
|
||||||
{% bootstrap_field form.admission layout="horizontal" %}
|
{% bootstrap_field form.admission layout="horizontal" %}
|
||||||
{% bootstrap_field form.description layout="horizontal" %}
|
{% bootstrap_field form.description layout="horizontal" %}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from pretix.base.models import (
|
|||||||
Item, ItemCategory, ItemVariation, Question, QuestionOption, Quota,
|
Item, ItemCategory, ItemVariation, Question, QuestionOption, Quota,
|
||||||
)
|
)
|
||||||
from pretix.control.forms.item import (
|
from pretix.control.forms.item import (
|
||||||
CategoryForm, ItemCreateForm, ItemFormGeneral, ItemVariationForm,
|
CategoryForm, ItemCreateForm, ItemUpdateForm, ItemVariationForm,
|
||||||
QuestionForm, QuestionOptionForm, QuotaForm,
|
QuestionForm, QuestionOptionForm, QuotaForm,
|
||||||
)
|
)
|
||||||
from pretix.control.permissions import (
|
from pretix.control.permissions import (
|
||||||
@@ -568,7 +568,7 @@ class ItemDetailMixin(SingleObjectMixin):
|
|||||||
|
|
||||||
class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
||||||
form_class = ItemCreateForm
|
form_class = ItemCreateForm
|
||||||
template_name = 'pretixcontrol/item/index.html'
|
template_name = 'pretixcontrol/item/create.html'
|
||||||
permission = 'can_change_items'
|
permission = 'can_change_items'
|
||||||
|
|
||||||
def get_success_url(self) -> str:
|
def get_success_url(self) -> str:
|
||||||
@@ -601,7 +601,7 @@ class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
|||||||
|
|
||||||
|
|
||||||
class ItemUpdateGeneral(ItemDetailMixin, EventPermissionRequiredMixin, UpdateView):
|
class ItemUpdateGeneral(ItemDetailMixin, EventPermissionRequiredMixin, UpdateView):
|
||||||
form_class = ItemFormGeneral
|
form_class = ItemUpdateForm
|
||||||
template_name = 'pretixcontrol/item/index.html'
|
template_name = 'pretixcontrol/item/index.html'
|
||||||
permission = 'can_change_items'
|
permission = 'can_change_items'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user