forked from CGM_Public/pretix_original
Fixed #86 -- Decide about variations at product creation
This commit is contained in:
@@ -211,6 +211,10 @@ class Item(LoggedModel):
|
|||||||
return min([q.availability() for q in self.quotas.all()],
|
return min([q.availability() for q in self.quotas.all()],
|
||||||
key=lambda s: (s[0], s[1] if s[1] is not None else sys.maxsize))
|
key=lambda s: (s[0], s[1] if s[1] is not None else sys.maxsize))
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def has_variations(self):
|
||||||
|
return self.variations.exists()
|
||||||
|
|
||||||
|
|
||||||
class ItemVariation(models.Model):
|
class ItemVariation(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import copy
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import BooleanField, ModelMultipleChoiceField
|
from django.forms import BooleanField, ModelMultipleChoiceField
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext as __, ugettext_lazy as _
|
||||||
|
|
||||||
from pretix.base.forms import I18nModelForm
|
from pretix.base.forms import I18nModelForm
|
||||||
from pretix.base.models import (
|
from pretix.base.models import (
|
||||||
@@ -101,6 +101,20 @@ 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.'))
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -4,10 +4,20 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
{% if object.id %}
|
{% if object.id %}
|
||||||
<h1>{% trans "Modify product:" %} {{ object.name }}</h1>
|
<h1>{% trans "Modify product:" %} {{ object.name }}</h1>
|
||||||
|
{% if object.has_variations %}
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
<li {% if "event.item" == url_name %}class="active"{% endif %}><a href="{% url 'control:event.item' organizer=request.event.organizer.slug event=request.event.slug item=object.id %}">{% trans "General information" %}</a></li>
|
<li {% if "event.item" == url_name %}class="active"{% endif %}>
|
||||||
<li {% if "event.item.variations" == url_name %}class="active"{% endif %}><a href="{% url 'control:event.item.variations' organizer=request.event.organizer.slug event=request.event.slug item=object.id %}">{% trans "Variations" %}</a></li>
|
<a href="{% url 'control:event.item' organizer=request.event.organizer.slug event=request.event.slug item=object.id %}">
|
||||||
|
{% trans "General information" %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li {% if "event.item.variations" == url_name %}class="active"{% endif %}>
|
||||||
|
<a href="{% url 'control:event.item.variations' organizer=request.event.organizer.slug event=request.event.slug item=object.id %}">
|
||||||
|
{% trans "Variations" %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<h1>{% trans "Create product" %}</h1>
|
<h1>{% trans "Create product" %}</h1>
|
||||||
<p>{% blocktrans trimmed %}
|
<p>{% blocktrans trimmed %}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
<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,8 @@ from pretix.base.models import (
|
|||||||
Item, ItemCategory, ItemVariation, Question, Quota,
|
Item, ItemCategory, ItemVariation, Question, Quota,
|
||||||
)
|
)
|
||||||
from pretix.control.forms.item import (
|
from pretix.control.forms.item import (
|
||||||
CategoryForm, ItemFormGeneral, ItemVariationForm, QuestionForm, QuotaForm,
|
CategoryForm, ItemCreateForm, ItemFormGeneral, ItemVariationForm,
|
||||||
|
QuestionForm, QuotaForm,
|
||||||
)
|
)
|
||||||
from pretix.control.permissions import (
|
from pretix.control.permissions import (
|
||||||
EventPermissionRequiredMixin, event_permission_required,
|
EventPermissionRequiredMixin, event_permission_required,
|
||||||
@@ -491,7 +492,7 @@ class ItemDetailMixin(SingleObjectMixin):
|
|||||||
|
|
||||||
|
|
||||||
class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
class ItemCreate(EventPermissionRequiredMixin, CreateView):
|
||||||
form_class = ItemFormGeneral
|
form_class = ItemCreateForm
|
||||||
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