-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Branch: refs/heads/master Date: 2022-07-14T16:04:36+02:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.scale@0f7168c Fixed getting original data for a tile. Fixes plone/plone.scale#64 Files changed: A news/64.bugfix M plone/scale/storage.py Repository: plone.scale Branch: refs/heads/master Date: 2022-07-18T12:05:59+02:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.scale@8cde451 Fixed tests. These tests used 'True' as dummy result, but that needs to be something that resembles an image now. Files changed: M plone/scale/tests/test_storage.py Repository: plone.scale Branch: refs/heads/master Date: 2022-07-19T16:14:42+02:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.scale@c4ceb41 pre_scale: rename variable 'field' to 'value'. That is a more correct name. Files changed: M plone/scale/storage.py Repository: plone.scale Branch: refs/heads/master Date: 2022-07-19T16:18:22+02:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.scale@56c5fc6 Merge pull request #65 from plone/maurits-get-original-value-issue-64 Fixed getting original data for a tile. Files changed: A news/64.bugfix M plone/scale/storage.py M plone/scale/tests/test_storage.py
- Loading branch information
1 parent
7eb6198
commit 885e56c
Showing
1 changed file
with
46 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,71 @@ | ||
Repository: plone.app.contentmenu | ||
Repository: plone.scale | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2022-07-19T12:39:52+02:00 | ||
Author: Peter Mathis (petschki) <peter.mathis@kombinat.at> | ||
Commit: https://github.com/plone/plone.app.contentmenu/commit/f80010c24c0db0a78fa8cbe21976fcf61aec091e | ||
Date: 2022-07-14T16:04:36+02:00 | ||
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> | ||
Commit: https://github.com/plone/plone.scale/commit/0f7168cfc4155c2856a19f61f4c3c6147adafc4c | ||
|
||
Fix missing "menuItem/extras/li_class" | ||
Fixed getting original data for a tile. | ||
|
||
Fixes https://github.com/plone/plone.scale/issues/64 | ||
|
||
Files changed: | ||
M plone/app/contentmenu/contentmenu.pt | ||
A news/64.bugfix | ||
M plone/scale/storage.py | ||
|
||
b'diff --git a/plone/app/contentmenu/contentmenu.pt b/plone/app/contentmenu/contentmenu.pt\nindex dace8de..4f5546c 100644\n--- a/plone/app/contentmenu/contentmenu.pt\n+++ b/plone/app/contentmenu/contentmenu.pt\n@@ -7,7 +7,7 @@\n <tal:menus repeat="menuItem menu">\n <tal:def define="submenu menuItem/submenu;\n identifier menuItem/extra/id">\n- <li id="${menuItem/extra/id}" class="${python:\'dropend\' if (submenu and toolbar_pos == \'side\') else \'\'}">\n+ <li id="${menuItem/extra/id}" class="${menuItem/extra/li_class|nothing} ${python:\'dropend\' if (submenu and toolbar_pos == \'side\') else \'\'}">\n \n <a href="#"\n i18n:attributes="title;"\n' | ||
b'diff --git a/news/64.bugfix b/news/64.bugfix\nnew file mode 100644\nindex 0000000..7d79da1\n--- /dev/null\n+++ b/news/64.bugfix\n@@ -0,0 +1,2 @@\n+Fixed getting original data for a tile.\n+[maurits]\ndiff --git a/plone/scale/storage.py b/plone/scale/storage.py\nindex fd3fca0..70365bb 100644\n--- a/plone/scale/storage.py\n+++ b/plone/scale/storage.py\n@@ -229,7 +229,8 @@ def pre_scale(self, **parameters):\n # There is nothing we can do.\n return\n fieldname = parameters.get("fieldname", None)\n- if scaling_factory.get_original_value(fieldname=fieldname) is None:\n+ field = scaling_factory.get_original_value(fieldname=fieldname)\n+ if field is None:\n # Either an empty field, or the field does not exist.\n return\n \n@@ -238,21 +239,14 @@ def pre_scale(self, **parameters):\n # Start with a basis.\n width = parameters.get("width")\n height = parameters.get("height")\n- mimetype = ""\n- if "fieldname" in parameters:\n- # We should get this in a different way probably.\n- field = getattr(self.context, parameters["fieldname"], None)\n- if field:\n- orig_width, orig_height = field.getImageSize()\n- mode = get_scale_mode(\n- parameters.get("direction") or parameters.get("mode") or "contain"\n- )\n- width, height = calculate_scaled_dimensions(\n- orig_width, orig_height, width, height, mode\n- )\n- mimetype = field.contentType\n- if not (width and height):\n- width = height = 400\n+ orig_width, orig_height = field.getImageSize()\n+ mode = get_scale_mode(\n+ parameters.get("direction") or parameters.get("mode") or "contain"\n+ )\n+ width, height = calculate_scaled_dimensions(\n+ orig_width, orig_height, width, height, mode\n+ )\n+ mimetype = field.contentType\n key = self.hash(**parameters)\n info = dict(\n uid=uid,\n' | ||
|
||
Repository: plone.app.contentmenu | ||
Repository: plone.scale | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2022-07-19T12:41:52+02:00 | ||
Author: Peter Mathis (petschki) <peter.mathis@kombinat.at> | ||
Commit: https://github.com/plone/plone.app.contentmenu/commit/736071a2eccbf1a107daec6708b3b94af4f40dc8 | ||
Date: 2022-07-18T12:05:59+02:00 | ||
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> | ||
Commit: https://github.com/plone/plone.scale/commit/8cde451f196b06a0e6374396f4b2ab8bf2716454 | ||
|
||
Fixed tests. | ||
|
||
These tests used 'True' as dummy result, but that needs to be something that resembles an image now. | ||
|
||
Files changed: | ||
M plone/scale/tests/test_storage.py | ||
|
||
b'diff --git a/plone/scale/tests/test_storage.py b/plone/scale/tests/test_storage.py\nindex 4456878..e643fe0 100644\n--- a/plone/scale/tests/test_storage.py\n+++ b/plone/scale/tests/test_storage.py\n@@ -10,6 +10,17 @@\n import zope.annotation.interfaces\n \n \n+_marker = object()\n+\n+\n+class DummyImage:\n+ contentType = "image/jpeg"\n+\n+ def getImageSize(self):\n+ # width, height\n+ return 60, 40\n+\n+\n @implementer(zope.annotation.interfaces.IAttributeAnnotatable)\n class _DummyContext:\n pass\n@@ -19,10 +30,12 @@ class AnnotationStorageTests(TestCase):\n \n layer = zca.UNIT_TESTING\n \n- def _provide_dummy_scale_adapter(self, result=True):\n+ def _provide_dummy_scale_adapter(self, result=_marker):\n from plone.scale.interfaces import IImageScaleFactory\n from zope.component import adapter\n \n+ if result is _marker:\n+ result = DummyImage()\n factory = self.factory\n \n @implementer(IImageScaleFactory)\n@@ -81,18 +94,15 @@ def testPreScaleNoWidthAndHeight(self):\n self._provide_dummy_scale_adapter()\n storage = self.storage\n # It is actually pretty silly to not pass a width and height.\n- # We default to 400 then, unless the factory does something different,\n- # which our dummy scale adapter does.\n- # But that is not called when using pre_scale.\n+ # We get the original width and height then.\n scale = storage.pre_scale(foo=23, bar=42)\n self.assertIn("uid", scale)\n self.assertIn("key", scale)\n self.assertEqual(scale["data"], None)\n- self.assertEqual(scale["width"], 400)\n- self.assertEqual(scale["height"], 400)\n- # Since in these tests we do not have a real image,\n- # we have no proper mimetype either.\n- self.assertEqual(scale["mimetype"], "")\n+ # We get the values from the DummyImage class.\n+ self.assertEqual(scale["width"], 60)\n+ self.assertEqual(scale["height"], 40)\n+ self.assertEqual(scale["mimetype"], "image/jpeg")\n \n def testPreScaleForNonExistingScale(self):\n self._provide_dummy_scale_adapter()\n@@ -103,7 +113,7 @@ def testPreScaleForNonExistingScale(self):\n self.assertEqual(scale["data"], None)\n self.assertEqual(scale["width"], 50)\n self.assertEqual(scale["height"], 80)\n- self.assertEqual(scale["mimetype"], "")\n+ self.assertEqual(scale["mimetype"], "image/jpeg")\n # Request the same pre scale.\n scale2 = storage.pre_scale(width=50, height=80)\n self.assertEqual(scale2["uid"], scale["uid"])\n@@ -142,7 +152,7 @@ def test_get_or_generate(self):\n self.assertIsNone(placeholder["data"])\n self.assertEqual(placeholder["width"], 50)\n self.assertEqual(placeholder["height"], 80)\n- self.assertEqual(placeholder["mimetype"], "")\n+ self.assertEqual(placeholder["mimetype"], "image/jpeg")\n # \'get_or_generate\' gets the pre generated placeholder info\n # and generates the scale.\n real = storage.get_or_generate(uid)\n' | ||
|
||
Repository: plone.scale | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2022-07-19T16:14:42+02:00 | ||
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> | ||
Commit: https://github.com/plone/plone.scale/commit/c4ceb413cba4d3d1fb786204d5219213c40dd2e4 | ||
|
||
pre_scale: rename variable 'field' to 'value'. | ||
|
||
changenote | ||
That is a more correct name. | ||
|
||
Files changed: | ||
A news/43.bugfix | ||
M plone/scale/storage.py | ||
|
||
b'diff --git a/news/43.bugfix b/news/43.bugfix\nnew file mode 100644\nindex 0000000..f08cae0\n--- /dev/null\n+++ b/news/43.bugfix\n@@ -0,0 +1,2 @@\n+Fix missing `menuItem/extra/li_class`.\n+[petschki]\n' | ||
b'diff --git a/plone/scale/storage.py b/plone/scale/storage.py\nindex 70365bb..dbde4a3 100644\n--- a/plone/scale/storage.py\n+++ b/plone/scale/storage.py\n@@ -229,9 +229,9 @@ def pre_scale(self, **parameters):\n # There is nothing we can do.\n return\n fieldname = parameters.get("fieldname", None)\n- field = scaling_factory.get_original_value(fieldname=fieldname)\n- if field is None:\n- # Either an empty field, or the field does not exist.\n+ value = scaling_factory.get_original_value(fieldname=fieldname)\n+ if value is None:\n+ # Either an empty value, or the field does not exist.\n return\n \n # There is no info, or it is outdated. Recreate the scale info.\n@@ -239,14 +239,14 @@ def pre_scale(self, **parameters):\n # Start with a basis.\n width = parameters.get("width")\n height = parameters.get("height")\n- orig_width, orig_height = field.getImageSize()\n+ orig_width, orig_height = value.getImageSize()\n mode = get_scale_mode(\n parameters.get("direction") or parameters.get("mode") or "contain"\n )\n width, height = calculate_scaled_dimensions(\n orig_width, orig_height, width, height, mode\n )\n- mimetype = field.contentType\n+ mimetype = value.contentType\n key = self.hash(**parameters)\n info = dict(\n uid=uid,\n' | ||
|
||
Repository: plone.app.contentmenu | ||
Repository: plone.scale | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2022-07-19T13:29:06+02:00 | ||
Author: Peter Mathis (petschki) <petschki@users.noreply.github.com> | ||
Commit: https://github.com/plone/plone.app.contentmenu/commit/c182acd5b7e8554fcd64215268cf1441682a6841 | ||
Date: 2022-07-19T16:18:22+02:00 | ||
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> | ||
Commit: https://github.com/plone/plone.scale/commit/56c5fc6a449856d7848d9b589e3a4f5828e02642 | ||
|
||
Merge pull request #43 from plone/petschki-missing-liclass | ||
Merge pull request #65 from plone/maurits-get-original-value-issue-64 | ||
|
||
Fix missing `menuItem/extra/li_class` | ||
Fixed getting original data for a tile. | ||
|
||
Files changed: | ||
A news/43.bugfix | ||
M plone/app/contentmenu/contentmenu.pt | ||
A news/64.bugfix | ||
M plone/scale/storage.py | ||
M plone/scale/tests/test_storage.py | ||
|
||
b'diff --git a/news/43.bugfix b/news/43.bugfix\nnew file mode 100644\nindex 0000000..f08cae0\n--- /dev/null\n+++ b/news/43.bugfix\n@@ -0,0 +1,2 @@\n+Fix missing `menuItem/extra/li_class`.\n+[petschki]\ndiff --git a/plone/app/contentmenu/contentmenu.pt b/plone/app/contentmenu/contentmenu.pt\nindex dace8de..4f5546c 100644\n--- a/plone/app/contentmenu/contentmenu.pt\n+++ b/plone/app/contentmenu/contentmenu.pt\n@@ -7,7 +7,7 @@\n <tal:menus repeat="menuItem menu">\n <tal:def define="submenu menuItem/submenu;\n identifier menuItem/extra/id">\n- <li id="${menuItem/extra/id}" class="${python:\'dropend\' if (submenu and toolbar_pos == \'side\') else \'\'}">\n+ <li id="${menuItem/extra/id}" class="${menuItem/extra/li_class|nothing} ${python:\'dropend\' if (submenu and toolbar_pos == \'side\') else \'\'}">\n \n <a href="#"\n i18n:attributes="title;"\n' | ||
b'diff --git a/news/64.bugfix b/news/64.bugfix\nnew file mode 100644\nindex 0000000..7d79da1\n--- /dev/null\n+++ b/news/64.bugfix\n@@ -0,0 +1,2 @@\n+Fixed getting original data for a tile.\n+[maurits]\ndiff --git a/plone/scale/storage.py b/plone/scale/storage.py\nindex fd3fca0..dbde4a3 100644\n--- a/plone/scale/storage.py\n+++ b/plone/scale/storage.py\n@@ -229,8 +229,9 @@ def pre_scale(self, **parameters):\n # There is nothing we can do.\n return\n fieldname = parameters.get("fieldname", None)\n- if scaling_factory.get_original_value(fieldname=fieldname) is None:\n- # Either an empty field, or the field does not exist.\n+ value = scaling_factory.get_original_value(fieldname=fieldname)\n+ if value is None:\n+ # Either an empty value, or the field does not exist.\n return\n \n # There is no info, or it is outdated. Recreate the scale info.\n@@ -238,21 +239,14 @@ def pre_scale(self, **parameters):\n # Start with a basis.\n width = parameters.get("width")\n height = parameters.get("height")\n- mimetype = ""\n- if "fieldname" in parameters:\n- # We should get this in a different way probably.\n- field = getattr(self.context, parameters["fieldname"], None)\n- if field:\n- orig_width, orig_height = field.getImageSize()\n- mode = get_scale_mode(\n- parameters.get("direction") or parameters.get("mode") or "contain"\n- )\n- width, height = calculate_scaled_dimensions(\n- orig_width, orig_height, width, height, mode\n- )\n- mimetype = field.contentType\n- if not (width and height):\n- width = height = 400\n+ orig_width, orig_height = value.getImageSize()\n+ mode = get_scale_mode(\n+ parameters.get("direction") or parameters.get("mode") or "contain"\n+ )\n+ width, height = calculate_scaled_dimensions(\n+ orig_width, orig_height, width, height, mode\n+ )\n+ mimetype = value.contentType\n key = self.hash(**parameters)\n info = dict(\n uid=uid,\ndiff --git a/plone/scale/tests/test_storage.py b/plone/scale/tests/test_storage.py\nindex 4456878..e643fe0 100644\n--- a/plone/scale/tests/test_storage.py\n+++ b/plone/scale/tests/test_storage.py\n@@ -10,6 +10,17 @@\n import zope.annotation.interfaces\n \n \n+_marker = object()\n+\n+\n+class DummyImage:\n+ contentType = "image/jpeg"\n+\n+ def getImageSize(self):\n+ # width, height\n+ return 60, 40\n+\n+\n @implementer(zope.annotation.interfaces.IAttributeAnnotatable)\n class _DummyContext:\n pass\n@@ -19,10 +30,12 @@ class AnnotationStorageTests(TestCase):\n \n layer = zca.UNIT_TESTING\n \n- def _provide_dummy_scale_adapter(self, result=True):\n+ def _provide_dummy_scale_adapter(self, result=_marker):\n from plone.scale.interfaces import IImageScaleFactory\n from zope.component import adapter\n \n+ if result is _marker:\n+ result = DummyImage()\n factory = self.factory\n \n @implementer(IImageScaleFactory)\n@@ -81,18 +94,15 @@ def testPreScaleNoWidthAndHeight(self):\n self._provide_dummy_scale_adapter()\n storage = self.storage\n # It is actually pretty silly to not pass a width and height.\n- # We default to 400 then, unless the factory does something different,\n- # which our dummy scale adapter does.\n- # But that is not called when using pre_scale.\n+ # We get the original width and height then.\n scale = storage.pre_scale(foo=23, bar=42)\n self.assertIn("uid", scale)\n self.assertIn("key", scale)\n self.assertEqual(scale["data"], None)\n- self.assertEqual(scale["width"], 400)\n- self.assertEqual(scale["height"], 400)\n- # Since in these tests we do not have a real image,\n- # we have no proper mimetype either.\n- self.assertEqual(scale["mimetype"], "")\n+ # We get the values from the DummyImage class.\n+ self.assertEqual(scale["width"], 60)\n+ self.assertEqual(scale["height"], 40)\n+ self.assertEqual(scale["mimetype"], "image/jpeg")\n \n def testPreScaleForNonExistingScale(self):\n self._provide_dummy_scale_adapter()\n@@ -103,7 +113,7 @@ def testPreScaleForNonExistingScale(self):\n self.assertEqual(scale["data"], None)\n self.assertEqual(scale["width"], 50)\n self.assertEqual(scale["height"], 80)\n- self.assertEqual(scale["mimetype"], "")\n+ self.assertEqual(scale["mimetype"], "image/jpeg")\n # Request the same pre scale.\n scale2 = storage.pre_scale(width=50, height=80)\n self.assertEqual(scale2["uid"], scale["uid"])\n@@ -142,7 +152,7 @@ def test_get_or_generate(self):\n self.assertIsNone(placeholder["data"])\n self.assertEqual(placeholder["width"], 50)\n self.assertEqual(placeholder["height"], 80)\n- self.assertEqual(placeholder["mimetype"], "")\n+ self.assertEqual(placeholder["mimetype"], "image/jpeg")\n # \'get_or_generate\' gets the pre generated placeholder info\n # and generates the scale.\n real = storage.get_or_generate(uid)\n' | ||
|