Improve documentation, add missing migrations

This commit is contained in:
Raphael Michel
2014-10-07 00:46:47 +02:00
parent a64d00aa82
commit b0126e30f3
5 changed files with 179 additions and 6 deletions

View 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,),
),
]

View File

@@ -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
)