Skip to content

Commit

Permalink
Merge pull request #64 from plone/image-scales
Browse files Browse the repository at this point in the history
Add image_scales support for RealContentListingObject
  • Loading branch information
davisagli authored Apr 2, 2024
2 parents 2eaa880 + 4a6d32d commit c99c7f8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/64.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support image_scales in RealContentListingObject. @davisagli
6 changes: 6 additions & 0 deletions plone/app/contentlisting/realobject.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from Acquisition import aq_get
from plone.app.contentlisting.contentlisting import BaseContentListingObject
from plone.app.contentlisting.interfaces import IContentListingObject
from plone.base.interfaces import IImageScalesAdapter
from plone.base.utils import base_hasattr
from plone.base.utils import human_readable_size
from plone.rfc822.interfaces import IPrimaryFieldInfo
from plone.uuid.interfaces import IUUID
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from zope.interface import implementer


Expand Down Expand Up @@ -105,3 +107,7 @@ def Type(self):
def PortalType(self):
obj = self.getObject()
return obj.portal_type

def image_scales(self):
obj = self.getObject()
return getMultiAdapter((obj, self.request), IImageScalesAdapter)()
22 changes: 22 additions & 0 deletions plone/app/contentlisting/tests/test_integration_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.batching.interfaces import IBatch
from plone.namedfile.file import NamedBlobImage
from Products.CMFCore.utils import getToolByName
from zope.interface.verify import verifyObject

import base64
import unittest


TEST_IMAGE_DATA = base64.b64decode(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
)


class TestSetup(unittest.TestCase):
layer = CONTENTLISTING_FUNCTIONAL_TESTING

Expand Down Expand Up @@ -265,6 +272,21 @@ def test_item_get_none(self):
"result in an AttributeError."
)

def test_item_image_scales(self):
self.folder.invokeFactory(
"Image",
"myimage",
title="My Image",
)
myimage = self.folder.myimage
myimage.image = NamedBlobImage(
data=TEST_IMAGE_DATA,
filename="test.png",
)
item = IContentListingObject(myimage)
image_scales = item.image_scales()
self.assertIn("download", image_scales["image"][0])


class TestFolderContents(unittest.TestCase):
"""Testing that the folder contents browserview works and behaves
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"plone.app.contenttypes[test]",
"plone.app.testing",
"plone.batching",
"plone.namedfile",
"plone.testing",
],
},
Expand Down

0 comments on commit c99c7f8

Please sign in to comment.