forked from CGM_Public/pretix_original
Do not show availability for currently-selected add-on
This commit is contained in:
@@ -134,7 +134,7 @@ class AddOnsForm(forms.Form):
|
||||
This form class is responsible for selecting add-ons to a product in the cart.
|
||||
"""
|
||||
|
||||
def _label(self, event, item_or_variation, avail, override_price=None):
|
||||
def _label(self, event, item_or_variation, avail, override_price=None, initial=False):
|
||||
if isinstance(item_or_variation, ItemVariation):
|
||||
variation = item_or_variation
|
||||
item = item_or_variation.item
|
||||
@@ -172,13 +172,14 @@ class AddOnsForm(forms.Form):
|
||||
taxes=number_format(price.rate), taxname=price.name
|
||||
)
|
||||
|
||||
if avail[0] < Quota.AVAILABILITY_RESERVED:
|
||||
n += ' – {}'.format(_('SOLD OUT'))
|
||||
elif avail[0] < Quota.AVAILABILITY_OK:
|
||||
n += ' – {}'.format(_('Currently unavailable'))
|
||||
else:
|
||||
if avail[1] is not None and item.do_show_quota_left:
|
||||
n += ' – {}'.format(_('%(num)s currently available') % {'num': avail[1]})
|
||||
if not initial:
|
||||
if avail[0] < Quota.AVAILABILITY_RESERVED:
|
||||
n += ' – {}'.format(_('SOLD OUT'))
|
||||
elif avail[0] < Quota.AVAILABILITY_OK:
|
||||
n += ' – {}'.format(_('Currently unavailable'))
|
||||
else:
|
||||
if avail[1] is not None and item.do_show_quota_left:
|
||||
n += ' – {}'.format(_('%(num)s currently available') % {'num': avail[1]})
|
||||
|
||||
if not isinstance(item_or_variation, ItemVariation) and item.picture:
|
||||
n = escape(n)
|
||||
@@ -272,7 +273,8 @@ class AddOnsForm(forms.Form):
|
||||
choices.append(
|
||||
(v.pk,
|
||||
self._label(self.event, v, cached_availability,
|
||||
override_price=var_price_override.get(v.pk)),
|
||||
override_price=var_price_override.get(v.pk),
|
||||
initial=current_addons.get(i.pk) == v.pk),
|
||||
v.description)
|
||||
)
|
||||
|
||||
@@ -308,7 +310,8 @@ class AddOnsForm(forms.Form):
|
||||
continue
|
||||
field = forms.BooleanField(
|
||||
label=self._label(self.event, i, cached_availability,
|
||||
override_price=item_price_override.get(i.pk)),
|
||||
override_price=item_price_override.get(i.pk),
|
||||
initial=i.pk in current_addons),
|
||||
required=False,
|
||||
initial=i.pk in current_addons,
|
||||
help_text=rich_text(str(i.description)),
|
||||
|
||||
@@ -2,7 +2,7 @@ from bs4 import BeautifulSoup
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SoupTest(TestCase):
|
||||
class SoupTestMixin:
|
||||
|
||||
def get_doc(self, *args, **kwargs):
|
||||
response = self.client.get(*args, **kwargs)
|
||||
@@ -17,6 +17,10 @@ class SoupTest(TestCase):
|
||||
return BeautifulSoup(response.content, "lxml")
|
||||
|
||||
|
||||
class SoupTest(SoupTestMixin, TestCase):
|
||||
pass
|
||||
|
||||
|
||||
def extract_form_fields(soup):
|
||||
"""
|
||||
Turn a BeautifulSoup form in to a dict of fields and default values
|
||||
|
||||
@@ -3,9 +3,10 @@ import decimal
|
||||
import json
|
||||
|
||||
from django.core import mail as djmail
|
||||
from django.test import TransactionTestCase
|
||||
from django.utils.timezone import now
|
||||
from django_scopes import scopes_disabled
|
||||
from tests.base import SoupTest, extract_form_fields
|
||||
from tests.base import SoupTestMixin, extract_form_fields
|
||||
|
||||
from pretix.base.models import (
|
||||
Event, Item, ItemVariation, Order, OrderPosition, Organizer, Quota, Team,
|
||||
@@ -13,7 +14,7 @@ from pretix.base.models import (
|
||||
)
|
||||
|
||||
|
||||
class VoucherFormTest(SoupTest):
|
||||
class VoucherFormTest(SoupTestMixin, TransactionTestCase):
|
||||
@scopes_disabled()
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
Reference in New Issue
Block a user