Add Python 2 compatibility for schedule builder with functools32
- Legacy-Id: 17895
This commit is contained in:
parent
c8e0a83b47
commit
1aad1bee48
|
@ -6,9 +6,13 @@ import datetime
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import functools
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
try:
|
||||||
|
from functools import lru_cache
|
||||||
|
except ImportError:
|
||||||
|
from functools32 import lru_cache
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
@ -583,7 +587,7 @@ class Session(object):
|
||||||
self.last_cost = cost
|
self.last_cost = cost
|
||||||
return violations, cost
|
return violations, cost
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=10000)
|
@lru_cache(maxsize=10000)
|
||||||
def _calculate_cost_overlapping_groups(self, overlapping_sessions):
|
def _calculate_cost_overlapping_groups(self, overlapping_sessions):
|
||||||
violations, cost = [], 0
|
violations, cost = [], 0
|
||||||
for other in overlapping_sessions:
|
for other in overlapping_sessions:
|
||||||
|
@ -603,7 +607,7 @@ class Session(object):
|
||||||
cost += len(conflict_people) * self.conflict_people_penalty
|
cost += len(conflict_people) * self.conflict_people_penalty
|
||||||
return violations, cost
|
return violations, cost
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=10000)
|
@lru_cache(maxsize=10000)
|
||||||
def _calculate_cost_business_logic(self, overlapping_sessions):
|
def _calculate_cost_business_logic(self, overlapping_sessions):
|
||||||
violations, cost = [], 0
|
violations, cost = [], 0
|
||||||
for other in overlapping_sessions:
|
for other in overlapping_sessions:
|
||||||
|
@ -645,8 +649,7 @@ class Session(object):
|
||||||
cost += self.business_constraint_costs['session_overlap_ad']
|
cost += self.business_constraint_costs['session_overlap_ad']
|
||||||
return violations, cost
|
return violations, cost
|
||||||
|
|
||||||
# TODO: Python 2 compatibility
|
@lru_cache(maxsize=10000)
|
||||||
@functools.lru_cache(maxsize=10000)
|
|
||||||
def _calculate_cost_my_other_sessions(self, my_sessions):
|
def _calculate_cost_my_other_sessions(self, my_sessions):
|
||||||
violations, cost = [], 0
|
violations, cost = [], 0
|
||||||
my_sessions = list(my_sessions)
|
my_sessions = list(my_sessions)
|
||||||
|
|
|
@ -70,4 +70,4 @@ Unidecode>=0.4.18
|
||||||
xml2rfc>=2.35.0
|
xml2rfc>=2.35.0
|
||||||
xym>=0.4.4,!=0.4.7,<1.0
|
xym>=0.4.4,!=0.4.7,<1.0
|
||||||
#zxcvbn-python>=4.4.14 # Not needed until we do back-end password entropy validation
|
#zxcvbn-python>=4.4.14 # Not needed until we do back-end password entropy validation
|
||||||
|
functools32==3.2.3-2; python_version < '3'
|
Loading…
Reference in a new issue