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