forked from CGM_Public/pretix_original
Improve documentation, add missing migrations
This commit is contained in:
32
src/tixlplugins/timerestriction/migrations/0001_initial.py
Normal file
32
src/tixlplugins/timerestriction/migrations/0001_initial.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tixlbase', '0015_auto_20141006_2205'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TimeRestriction',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
|
||||
('timeframe_from', models.DateTimeField(verbose_name='Start of time frame')),
|
||||
('timeframe_to', models.DateTimeField(verbose_name='End of time frame')),
|
||||
('price', models.DecimalField(max_digits=7, verbose_name='Price in time frame', decimal_places=2, null=True, blank=True)),
|
||||
('event', models.ForeignKey(related_name='restrictions_timerestriction_timerestriction', to='tixlbase.Event', verbose_name='Event')),
|
||||
('items', models.ManyToManyField(to='tixlbase.Item', related_name='restrictions_timerestriction_timerestriction')),
|
||||
('variations', models.ManyToManyField(to='tixlbase.ItemVariation', related_name='restrictions_timerestriction_timerestriction')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
'verbose_name_plural': 'Restrictions',
|
||||
'verbose_name': 'Restriction',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
||||
@@ -59,7 +59,9 @@ def availability_handler(sender, **kwargs):
|
||||
# Make up some unique key for this variation
|
||||
cachekey = 'timerestriction:%d:%s' % (
|
||||
item.pk,
|
||||
",".join(sorted([str(v[1].pk) for v in v.items() if v[0] != 'variation']))
|
||||
",".join(sorted(
|
||||
[str(v[1].pk) for v in v.items() if v[0] != 'variation']
|
||||
))
|
||||
)
|
||||
|
||||
# Fetch from cache, if available
|
||||
@@ -83,19 +85,24 @@ def availability_handler(sender, **kwargs):
|
||||
if 'variation' not in v or v['variation'] not in applied_to:
|
||||
continue
|
||||
|
||||
if restriction.timeframe_from <= now() and restriction.timeframe_to >= now():
|
||||
if (restriction.timeframe_from <= now()
|
||||
and restriction.timeframe_to >= now()):
|
||||
# Selling this item is currently possible
|
||||
available = True
|
||||
# If multiple time frames are currently active, make sure to
|
||||
# get the cheapest price:
|
||||
if restriction.price is not None and (price is None or restriction.price < price):
|
||||
if (restriction.price is not None
|
||||
and (price is None or restriction.price < price)):
|
||||
price = restriction.price
|
||||
|
||||
v['available'] = available
|
||||
v['price'] = price
|
||||
cache.set(
|
||||
cachekey,
|
||||
'%s:%s' % ('True' if available else 'False', str(price) if price else ''),
|
||||
'%s:%s' % (
|
||||
'True' if available else 'False',
|
||||
str(price) if price else ''
|
||||
),
|
||||
cache_validity
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user