Introduce Item.show_quota_left

This commit is contained in:
Raphael Michel
2019-07-10 16:08:21 +02:00
parent 6d6cd3b7cf
commit 491753008d
10 changed files with 63 additions and 7 deletions
+11
View File
@@ -72,6 +72,8 @@ generate_tickets boolean If ``false``, t
non-admission or add-on product, regardless of event
settings. If this is ``null``, regular ticketing
rules apply.
show_quota_left boolean Publicly show how many tickets are still available.
If this is ``null``, the event default is used.
has_variations boolean Shows whether or not this item has variations.
variations list of objects A list with one object for each variation of this item.
Can be empty. Only writable during creation,
@@ -142,6 +144,10 @@ bundles list of objects Definition of b
The ``bundles`` and ``require_bundling`` attributes have been added.
.. versionchanged:: 3.0
The ``show_quota_left`` attribute has been added.
Notes
-----
@@ -207,6 +213,7 @@ Endpoints
"checkin_attention": false,
"has_variations": false,
"generate_tickets": null,
"show_quota_left": null,
"require_approval": false,
"require_bundling": false,
"variations": [
@@ -294,6 +301,7 @@ Endpoints
"hide_without_voucher": false,
"allow_cancel": true,
"generate_tickets": null,
"show_quota_left": null,
"min_per_order": null,
"max_per_order": null,
"checkin_attention": false,
@@ -366,6 +374,7 @@ Endpoints
"hide_without_voucher": false,
"allow_cancel": true,
"generate_tickets": null,
"show_quota_left": null,
"min_per_order": null,
"max_per_order": null,
"checkin_attention": false,
@@ -427,6 +436,7 @@ Endpoints
"min_per_order": null,
"max_per_order": null,
"generate_tickets": null,
"show_quota_left": null,
"checkin_attention": false,
"has_variations": true,
"require_approval": false,
@@ -515,6 +525,7 @@ Endpoints
"require_voucher": false,
"hide_without_voucher": false,
"generate_tickets": null,
"show_quota_left": null,
"allow_cancel": true,
"min_per_order": null,
"max_per_order": null,
+2 -1
View File
@@ -118,7 +118,8 @@ class ItemSerializer(I18nAwareModelSerializer):
'position', 'picture', 'available_from', 'available_until',
'require_voucher', 'hide_without_voucher', 'allow_cancel', 'require_bundling',
'min_per_order', 'max_per_order', 'checkin_attention', 'has_variations', 'variations',
'addons', 'bundles', 'original_price', 'require_approval', 'generate_tickets')
'addons', 'bundles', 'original_price', 'require_approval', 'generate_tickets',
'show_quota_left')
read_only_fields = ('has_variations', 'picture')
def get_serializer_context(self):
@@ -0,0 +1,18 @@
# Generated by Django 2.2.1 on 2019-07-10 13:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0125_voucher_show_hidden_items'),
]
operations = [
migrations.AddField(
model_name='item',
name='show_quota_left',
field=models.NullBooleanField(),
),
]
+11
View File
@@ -308,6 +308,11 @@ class Item(LoggedModel):
verbose_name=_("Generate tickets"),
blank=True, null=True,
)
show_quota_left = models.NullBooleanField(
verbose_name=_("Show number of tickets left"),
help_text=_("Publicly show how many tickets are still available."),
blank=True, null=True,
)
position = models.IntegerField(
default=0
)
@@ -410,6 +415,12 @@ class Item(LoggedModel):
if self.event:
self.event.cache.clear()
@property
def do_show_quota_left(self):
if self.show_quota_left is None:
return self.event.settings.show_quota_left
return self.show_quota_left
def tax(self, price=None, base_price_is='auto', currency=None, include_bundled=False):
price = price if price is not None else self.default_price
+13 -1
View File
@@ -356,6 +356,16 @@ class ItemCreateForm(I18nModelForm):
]
class ShowQuotaNullBooleanSelect(forms.NullBooleanSelect):
def __init__(self, attrs=None):
choices = (
('1', _('(Event default)')),
('2', _('Yes')),
('3', _('No')),
)
super(forms.NullBooleanSelect, self).__init__(attrs, choices)
class TicketNullBooleanSelect(forms.NullBooleanSelect):
def __init__(self, attrs=None):
choices = (
@@ -415,6 +425,7 @@ class ItemUpdateForm(I18nModelForm):
'generate_tickets',
'original_price',
'require_bundling',
'show_quota_left'
]
field_classes = {
'available_from': SplitDateTimeField,
@@ -423,7 +434,8 @@ class ItemUpdateForm(I18nModelForm):
widgets = {
'available_from': SplitDateTimePickerWidget(),
'available_until': SplitDateTimePickerWidget(attrs={'data-date-after': '#id_available_from_0'}),
'generate_tickets': TicketNullBooleanSelect()
'generate_tickets': TicketNullBooleanSelect(),
'show_quota_left': ShowQuotaNullBooleanSelect()
}
@@ -45,6 +45,7 @@
{% bootstrap_field form.original_price addon_after=request.event.currency layout="control" %}
{% bootstrap_field form.require_approval layout="control" %}
{% bootstrap_field form.generate_tickets layout="control" %}
{% bootstrap_field form.show_quota_left layout="control" %}
{% for f in plugin_forms %}
{% bootstrap_form f layout="control" %}
{% endfor %}
+2 -1
View File
@@ -174,7 +174,7 @@ class AddOnsForm(forms.Form):
elif avail[0] < 100:
n += ' {}'.format(_('Currently unavailable'))
else:
if avail[1] is not None and event.settings.show_quota_left:
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:
@@ -236,6 +236,7 @@ class AddOnsForm(forms.Form):
to_attr='_subevent_quotas',
queryset=event.quotas.filter(subevent=subevent))
).distinct()),
'event'
).annotate(
quotac=Count('quotas'),
has_variations=Count('variations')
@@ -81,7 +81,7 @@
{{ var.description|localize|rich_text }}
</div>
{% endif %}
{% if event.settings.show_quota_left %}
{% if item.do_show_quota_left %}
{% include "pretixpresale/event/fragment_quota_left.html" with avail=var.cached_availability %}
{% endif %}
</div>
@@ -187,7 +187,7 @@
{{ item.description|localize|rich_text }}
</div>
{% endif %}
{% if event.settings.show_quota_left %}
{% if item.do_show_quota_left %}
{% include "pretixpresale/event/fragment_quota_left.html" with avail=item.cached_availability %}
{% endif %}
{% if item.min_per_order and item.min_per_order > 1 %}
+2 -2
View File
@@ -198,7 +198,7 @@ class WidgetAPIProductList(EventListMixin, View):
'free_price': item.free_price,
'avail': [
item.cached_availability[0],
item.cached_availability[1] if self.request.event.settings.show_quota_left else None
item.cached_availability[1] if item.do_show_quota_left else None
] if not item.has_variations else None,
'original_price': (
(item.original_price.net
@@ -228,7 +228,7 @@ class WidgetAPIProductList(EventListMixin, View):
),
'avail': [
var.cached_availability[0],
var.cached_availability[1] if self.request.event.settings.show_quota_left else None
var.cached_availability[1] if item.do_show_quota_left else None
],
} for var in item.available_variations
]
+1
View File
@@ -240,6 +240,7 @@ TEST_ITEM_RES = {
"variations": [],
"addons": [],
"bundles": [],
"show_quota_left": None,
"original_price": None
}