diff --git a/src/papiezator/models.py b/src/papiezator/models.py index 6738040..1ffcfe2 100644 --- a/src/papiezator/models.py +++ b/src/papiezator/models.py @@ -3,7 +3,7 @@ from django.db import models decimal_places = 3 class Pope(models.Model): - path = models.CharField(max_length=200) + path = models.CharField(max_length=200, primary_key=True) width = models.IntegerField() height = models.IntegerField() aspect_ratio = models.FloatField() @@ -13,7 +13,7 @@ class Pope(models.Model): return self.path.split('/')[-1] class PopeVersion(models.Model): - pope_id = models.AutoField(primary_key=True) + pope_id = models.CharField(max_length=8, primary_key=True) pope_name = models.CharField(max_length=200) def __str__(self): diff --git a/src/papiezator/pope_utils.py b/src/papiezator/pope_utils.py index e823b0b..2bffe3c 100644 --- a/src/papiezator/pope_utils.py +++ b/src/papiezator/pope_utils.py @@ -1,5 +1,4 @@ from papiezator.models import Pope, PerfectPope, decimal_places -from papiezator.exceptions import ENOPopeException from PIL import Image from io import BytesIO # FIXME: @@ -26,9 +25,8 @@ def select_best_pope(aspect_ratio): return_pope = gte[0] elif lte: return_pope = lte[0] - else: - raise ENOPopeException + return None return return_pope @@ -39,6 +37,14 @@ def habemus_papam(aspect_ratio, pope): return pope +def unpopable(width, height): + if width == 0 or height == 0: + return True + if (width+height) > 9000: + return True + return False + + def read_pope(width, height, pope): """ (int, int, Pope) -> bytes @@ -52,12 +58,11 @@ def read_pope(width, height, pope): return f.read() -class PopeMaster: - def __init__(self): - pass - def parse_pope(self, pope): - im = Image.open(pope) - width, height = im.size - aspect_ratio = round(width/height, decimal_places) - return Pope(path=pope, width=width, height=height, aspect_ratio=aspect_ratio) +def parse_pope(path): + im = Image.open(path) + width, height = im.size + aspect_ratio = round(width/height, decimal_places) + return Pope(path=path, width=width, height=height, aspect_ratio=aspect_ratio) + + diff --git a/src/papiezator/templates/papiezator/index.html b/src/papiezator/templates/papiezator/index.html index a322b79..d2e697e 100644 --- a/src/papiezator/templates/papiezator/index.html +++ b/src/papiezator/templates/papiezator/index.html @@ -10,8 +10,8 @@ - - + +