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