Reduce functional complexity (McCabe max 18 → max 12)

This commit is contained in:
Raphael Michel
2015-03-13 01:03:19 +01:00
parent 7c240e5c35
commit b8bb71d8a3
8 changed files with 267 additions and 229 deletions

View File

@@ -11,6 +11,16 @@ from pretix.control.signals import restriction_formset
from .models import TimeRestriction
# The maximum validity of our cached values is the next date, one of our
# timeframe_from or tiemframe_to actions happens
def timediff(restrictions):
for r in restrictions:
if r.timeframe_from >= now():
yield (r.timeframe_from - now()).total_seconds()
if r.timeframe_to >= now():
yield (r.timeframe_to - now()).total_seconds()
@receiver(determine_availability)
def availability_handler(sender, **kwargs):
# Handle the signal's input arguments
@@ -34,15 +44,6 @@ def availability_handler(sender, **kwargs):
# interfere with other plugins.
variations = [d.copy() for d in variations]
# The maximum validity of our cached values is the next date, one of our
# timeframe_from or tiemframe_to actions happens
def timediff(restrictions):
for r in restrictions:
if r.timeframe_from >= now():
yield (r.timeframe_from - now()).total_seconds()
if r.timeframe_to >= now():
yield (r.timeframe_to - now()).total_seconds()
try:
cache_validity = min(timediff(restrictions))
except ValueError: