33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# Create your views here.
|
|
from django.shortcuts import render
|
|
from django.http import HttpResponse
|
|
from django.core.urlresolvers import reverse
|
|
from papiezator.pope_utils import select_best_pope, read_pope, unpopable, pope_or_death
|
|
from papiezator.models import DECIMAL_PLACES, Pope
|
|
|
|
|
|
def index(request):
|
|
c = {
|
|
"absolute_url": request.build_absolute_uri(reverse("papiezator:conclave", args=[200,300])),
|
|
"absolute_url_exp": request.build_absolute_uri("width/height/")
|
|
}
|
|
return render(request, "papiezator/index.html", c)
|
|
|
|
def conclave(request, width, height, pope_id=0):
|
|
width, height = int(width), int(height)
|
|
if not unpopable(width, height):
|
|
|
|
|
|
pope = pope_or_death(Pope, id=pope_id)
|
|
if pope:
|
|
aspect_ratio = round(width/height, DECIMAL_PLACES)
|
|
pope_image = select_best_pope(aspect_ratio, pope)
|
|
|
|
if pope_image:
|
|
return HttpResponse(
|
|
read_pope(width, height, pope_image),
|
|
mimetype="image/jpeg"
|
|
)
|
|
return HttpResponse(":c")
|
|
|