From ee6b66329b953194e56b2b4d3b7e53b750668dbf Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 5 Feb 2017 23:20:00 +0100 Subject: [PATCH] server/posts: fix search by aspect ratio It was being rounded to nearest integer because of the width/height columns' data type. --- server/szurubooru/model/post.py | 4 +++- .../tests/search/configs/test_post_search_config.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/model/post.py b/server/szurubooru/model/post.py index d0de485..a3af237 100644 --- a/server/szurubooru/model/post.py +++ b/server/szurubooru/model/post.py @@ -205,7 +205,9 @@ class Post(Base): .correlate_except(PostTag)) canvas_area = sa.orm.column_property(canvas_width * canvas_height) - canvas_aspect_ratio = sa.orm.column_property(canvas_width / canvas_height) + canvas_aspect_ratio = sa.orm.column_property( + sa.sql.expression.func.cast(canvas_width, sa.Float) / + sa.sql.expression.func.cast(canvas_height, sa.Float)) @property def is_featured(self) -> bool: diff --git a/server/szurubooru/tests/search/configs/test_post_search_config.py b/server/szurubooru/tests/search/configs/test_post_search_config.py index 551e09c..ef3cdd9 100644 --- a/server/szurubooru/tests/search/configs/test_post_search_config.py +++ b/server/szurubooru/tests/search/configs/test_post_search_config.py @@ -431,23 +431,27 @@ def test_filter_by_file_size( ('image-area:90000', [3]), ('image-area:20000,90000', [1, 2, 3]), ('image-ar:1', [3]), - ('image-ar:..0.9', [1]), + ('image-ar:..0.9', [1, 4]), ('image-ar:1.1..', [2]), ('image-ar:1/1..1/1', [3]), ('image-ar:1:1..1:1', [3]), + ('image-ar:0.62..0.63', [4]), ]) def test_filter_by_image_size( verify_unpaged, post_factory, input, expected_post_ids): post1 = post_factory(id=1) post2 = post_factory(id=2) post3 = post_factory(id=3) + post4 = post_factory(id=4) post1.canvas_width = 100 post1.canvas_height = 200 post2.canvas_width = 200 post2.canvas_height = 100 post3.canvas_width = 300 post3.canvas_height = 300 - db.session.add_all([post1, post2, post3]) + post4.canvas_width = 480 + post4.canvas_height = 767 + db.session.add_all([post1, post2, post3, post4]) db.session.flush() verify_unpaged(input, expected_post_ids)