33 lines
1006 B
Python
33 lines
1006 B
Python
# Create your views here.
|
|
from django.shortcuts import render
|
|
from django.http import HttpResponse
|
|
from PIL import Image
|
|
from io import BytesIO # FIXME:
|
|
from papiezator.pope_utils import select_best_pope
|
|
from papiezator.exceptions import ENOPopeException
|
|
from papiezator.models import decimal_places
|
|
|
|
|
|
def index(request):
|
|
|
|
return render(request, "papiezator/index.html")
|
|
|
|
def conclave(request, width, height):
|
|
width, height = int(width), int(height)
|
|
if width > 0 and height > 0:
|
|
aspect_ratio = round(width/height, decimal_places)
|
|
import ipdb; ipdb.set_trace()
|
|
try:
|
|
pope = select_best_pope(aspect_ratio)
|
|
except ENOPopeException:
|
|
return HttpResponse("czarny dym")
|
|
|
|
im = Image.open(pope.path)
|
|
im = im.resize((width, height))
|
|
f = BytesIO() # FIXME: ceriously.
|
|
im.save(f, "jpeg")
|
|
f.seek(0)
|
|
return HttpResponse(f.read(), mimetype="image/jpeg")
|
|
else:
|
|
return HttpResponse("8====D~~~~")
|