mirror of
https://github.com/pretix/pretix.git
synced 2026-05-04 15:04:03 +00:00
Fixed #108 -- Removed the restrictions system
This commit is contained in:
@@ -80,8 +80,6 @@ class Item(Versionable):
|
||||
An item is a thing which can be sold. It belongs to an event and may or may not belong to a category.
|
||||
Items are often also called 'products' but are named 'items' internally due to historic reasons.
|
||||
|
||||
It has a default price which might by overriden by restrictions.
|
||||
|
||||
:param event: The event this belongs to.
|
||||
:type event: Event
|
||||
:param category: The category this belongs to. May be null.
|
||||
@@ -249,10 +247,9 @@ class Item(Versionable):
|
||||
def get_all_available_variations(self, use_cache: bool=False):
|
||||
"""
|
||||
This method returns a list of all variations which are theoretically
|
||||
possible for sale. It DOES call all activated restriction plugins, and it
|
||||
DOES only return variations which DO have an ItemVariation object, as all
|
||||
variations without one CAN NOT be part of a Quota and therefore can never
|
||||
be available for sale. The only exception is the empty variation
|
||||
possible for sale. It DOES only return variations which DO have an ItemVariation
|
||||
object, as all variations without one CAN NOT be part of a Quota and therefore can
|
||||
never be available for sale. The only exception is the empty variation
|
||||
for items without properties, which never has an ItemVariation object.
|
||||
|
||||
This DOES NOT take into account quotas itself. Use ``is_available`` on the
|
||||
@@ -268,39 +265,18 @@ class Item(Versionable):
|
||||
if use_cache and hasattr(self, '_get_all_available_variations_cache'):
|
||||
return self._get_all_available_variations_cache
|
||||
|
||||
from pretix.base.signals import determine_availability
|
||||
|
||||
variations = self._get_all_generated_variations()
|
||||
responses = determine_availability.send(
|
||||
self.event, item=self,
|
||||
variations=variations, context=None,
|
||||
cache=self.event.get_cache()
|
||||
)
|
||||
|
||||
for i, var in enumerate(variations):
|
||||
var['available'] = var['variation'].active if 'variation' in var else True
|
||||
if 'variation' in var:
|
||||
if var['variation'].default_price:
|
||||
if var['variation'].default_price is not None:
|
||||
var['price'] = var['variation'].default_price
|
||||
else:
|
||||
var['price'] = self.default_price
|
||||
else:
|
||||
var['price'] = self.default_price
|
||||
|
||||
# It is possible, that *multiple* restriction plugins change the default price.
|
||||
# In this case, the cheapest one wins. As soon as there is a restriction
|
||||
# that changes the price, the default price has no effect.
|
||||
|
||||
newprice = None
|
||||
for rec, response in responses:
|
||||
if 'available' in response[i] and not response[i]['available']:
|
||||
var['available'] = False
|
||||
break
|
||||
if 'price' in response[i] and response[i]['price'] is not None \
|
||||
and (newprice is None or response[i]['price'] < newprice):
|
||||
newprice = response[i]['price']
|
||||
var['price'] = newprice or var['price']
|
||||
|
||||
variations = [var for var in variations if var['available']]
|
||||
|
||||
self._get_all_available_variations_cache = variations
|
||||
@@ -322,38 +298,6 @@ class Item(Versionable):
|
||||
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))
|
||||
|
||||
def check_restrictions(self):
|
||||
"""
|
||||
This method is used to determine whether this ItemVariation is restricted
|
||||
in sale by any restriction plugins.
|
||||
|
||||
:returns:
|
||||
|
||||
* ``False``, if the item is unavailable
|
||||
* the item's price, otherwise
|
||||
|
||||
:raises ValueError: if you call this on an item which has properties associated with it.
|
||||
Please use the method on the ItemVariation object you are interested in.
|
||||
"""
|
||||
if self.properties.count() > 0: # NOQA
|
||||
raise ValueError('Do not call this directly on items which have properties '
|
||||
'but call this on their ItemVariation objects')
|
||||
from pretix.base.signals import determine_availability
|
||||
|
||||
vd = VariationDict()
|
||||
responses = determine_availability.send(
|
||||
self.event, item=self,
|
||||
variations=[vd], context=None,
|
||||
cache=self.event.get_cache()
|
||||
)
|
||||
price = self.default_price
|
||||
for rec, response in responses:
|
||||
if 'available' in response[0] and not response[0]['available']:
|
||||
return False
|
||||
elif 'price' in response[0] and response[0]['price'] is not None and response[0]['price'] < price:
|
||||
price = response[0]['price']
|
||||
return price
|
||||
|
||||
|
||||
class Property(Versionable):
|
||||
"""
|
||||
@@ -466,8 +410,6 @@ class ItemVariation(Versionable):
|
||||
values by creating an ItemVariation object for them with active set to
|
||||
False.
|
||||
|
||||
Restrictions can be not only set to items but also directly to variations.
|
||||
|
||||
:param item: The item this variation belongs to
|
||||
:type item: Item
|
||||
:param values: A set of ``PropertyValue`` objects defining this variation
|
||||
@@ -531,31 +473,6 @@ class ItemVariation(Versionable):
|
||||
vd['variation'] = self
|
||||
return vd
|
||||
|
||||
def check_restrictions(self) -> Union[bool, Decimal]:
|
||||
"""
|
||||
This method is used to determine whether this ItemVariation is restricted
|
||||
in sale by any restriction plugins.
|
||||
|
||||
:returns:
|
||||
|
||||
* ``False``, if the item is unavailable
|
||||
* the item's price, otherwise
|
||||
"""
|
||||
from pretix.base.signals import determine_availability
|
||||
|
||||
responses = determine_availability.send(
|
||||
self.item.event, item=self.item,
|
||||
variations=[self.to_variation_dict()], context=None,
|
||||
cache=self.item.event.get_cache()
|
||||
)
|
||||
price = self.default_price if self.default_price is not None else self.item.default_price
|
||||
for rec, response in responses:
|
||||
if 'available' in response[0] and not response[0]['available']:
|
||||
return False
|
||||
elif 'price' in response[0] and response[0]['price'] is not None and response[0]['price'] < price:
|
||||
price = response[0]['price']
|
||||
return price
|
||||
|
||||
def add_values_from_string(self, pk):
|
||||
"""
|
||||
Add values to this ItemVariation using a serialized string of the form
|
||||
@@ -672,47 +589,6 @@ class Question(Versionable):
|
||||
self.event.get_cache().clear()
|
||||
|
||||
|
||||
class BaseRestriction(Versionable):
|
||||
"""
|
||||
A restriction is the abstract concept of a rule that limits the availability
|
||||
of Items or ItemVariations. This model is just an abstract base class to be
|
||||
extended by restriction plugins.
|
||||
"""
|
||||
event = VersionedForeignKey(
|
||||
Event,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="restrictions_%(app_label)s_%(class)s",
|
||||
verbose_name=_("Event"),
|
||||
)
|
||||
item = VersionedForeignKey(
|
||||
Item,
|
||||
blank=True, null=True,
|
||||
verbose_name=_("Item"),
|
||||
related_name="restrictions_%(app_label)s_%(class)s",
|
||||
)
|
||||
variations = VariationsField(
|
||||
'pretixbase.ItemVariation',
|
||||
blank=True,
|
||||
verbose_name=_("Variations"),
|
||||
related_name="restrictions_%(app_label)s_%(class)s",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
verbose_name = _("Restriction")
|
||||
verbose_name_plural = _("Restrictions")
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
super().delete(*args, **kwargs)
|
||||
if self.event:
|
||||
self.event.get_cache().clear()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
if self.event:
|
||||
self.event.get_cache().clear()
|
||||
|
||||
|
||||
class Quota(Versionable):
|
||||
"""
|
||||
A quota is a "pool of tickets". It is there to limit the number of items
|
||||
|
||||
Reference in New Issue
Block a user