This solves it.
parent
8466e30825
commit
8ee60a5135
|
@ -35,20 +35,28 @@ def select_best_pope(aspect_ratio, pope):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# popes below and above this ratio
|
# popes below and above this ratio
|
||||||
lte = PopeImage.objects.filter(aspect_ratio__lte=aspect_ratio, pope=pope).order_by('-aspect_ratio')[0:1]
|
popes = []
|
||||||
gte = PopeImage.objects.filter(aspect_ratio__gte=aspect_ratio, pope=pope).order_by('aspect_ratio')[0:1]
|
popes.extend(
|
||||||
|
PopeImage.objects.filter(
|
||||||
|
aspect_ratio__lte=aspect_ratio,
|
||||||
|
pope=pope).order_by('-aspect_ratio')[0:1]
|
||||||
|
)
|
||||||
|
|
||||||
if gte and lte:
|
popes.extend(
|
||||||
|
PopeImage.objects.filter(
|
||||||
|
aspect_ratio__gte=aspect_ratio,
|
||||||
|
pope=pope).order_by('aspect_ratio')[0:1]
|
||||||
|
)
|
||||||
|
|
||||||
|
if popes:
|
||||||
p = min(
|
p = min(
|
||||||
[lte[0], gte[0]],
|
popes,
|
||||||
key=lambda x: abs(aspect_ratio - x.aspect_ratio)
|
key=lambda x: abs(aspect_ratio - x.aspect_ratio)
|
||||||
)
|
)
|
||||||
return p
|
return p
|
||||||
|
|
||||||
# if there are no popes above or below this ratio # do i want to get rid of this?
|
else:
|
||||||
elif gte: return gte[0]
|
return None
|
||||||
elif lte: return lte[0]
|
|
||||||
else: return None
|
|
||||||
|
|
||||||
|
|
||||||
def unpopable(width, height):
|
def unpopable(width, height):
|
||||||
|
|
Loading…
Reference in New Issue