Skip to content

Commit

Permalink
WEB-3984 : Don't get banner scale anymore. Get full banner image dire…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
boulch committed Sep 7, 2023
1 parent 9563b4b commit 14aec91
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Changelog
1.1.24 (unreleased)
-------------------

- Remove banner field from cropping editor
- WEB-3984 : Don't get banner scale anymore. Get full banner image directly
[boulch, laulaz]

- WEB-3984 : Remove banner field from cropping editor
[laulaz]


Expand Down
6 changes: 3 additions & 3 deletions src/imio/smartweb/core/tests/test_banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_viewlet_banner(self):
self.folder.banner = NamedBlobImage(**make_named_image())
self.assertTrue(viewlet.available())
self.assertIn(
"background-image:url(http://nohost/plone/folder/@@images/banner-1920",
"background-image:url(http://nohost/plone/folder/@@images/banner?cache_key=",
viewlet.background_style(),
)
template = self.folder.restrictedTraverse("view")
Expand Down Expand Up @@ -124,15 +124,15 @@ def test_banner_child_locally_hidden(self):
# css_bg_image = f"background-image:url({scale.url});"
# css_bg_size = "background-size:cover;"
self.assertIn(
"background-image:url(http://nohost/plone/folder/@@images/banner-1920",
"background-image:url(http://nohost/plone/folder/@@images/banner?cache_key=",
subfolder_viewlet.background_style(),
)
page_viewlet = BannerViewlet(page, self.request, None, None)
page_viewlet.update()
self.assertTrue(page_viewlet.available())
self.assertFalse(page_viewlet.is_banner_locally_hidden)
self.assertIn(
"background-image:url(http://nohost/plone/folder/@@images/banner-1920",
"background-image:url(http://nohost/plone/folder/@@images/banner?cache_key=",
page_viewlet.background_style(),
)

Expand Down
9 changes: 9 additions & 0 deletions src/imio/smartweb/core/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,13 @@
profile="imio.smartweb.core:default"
/>

<genericsetup:upgradeStep
title="Remove deprecated cropping annotations on banner"
description="Remove deprecated cropping annotations on banner"
source="1044"
destination="1045"
handler=".upgrades.remove_deprecated_cropping_annotations"
profile="imio.smartweb.core:default"
/>

</configure>
9 changes: 5 additions & 4 deletions src/imio/smartweb/core/viewlets/banner.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

from imio.smartweb.core.browser.banner.settings import ILocallyHiddenBanner
from imio.smartweb.core.utils import hash_md5
from plone import api
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.viewlets import common
from plone.namedfile.file import NamedBlobImage
from Products.CMFPlone.utils import base_hasattr
from zope.component import queryMultiAdapter


class BannerViewlet(common.ViewletBase):
Expand Down Expand Up @@ -54,8 +54,9 @@ def is_banner_locally_hidden(self):
def background_style(self):
if self.is_banner_hidden:
return ""
images_view = queryMultiAdapter((self.banner_item, self.request), name="images")
scale = images_view.scale("banner", "banner")
css_bg_image = f"background-image:url({scale.url});"
modification_date = self.banner_item.ModificationDate()
modified_hash = hash_md5(modification_date)
image_url = f"{self.banner_item.absolute_url()}/@@images/banner?cache_key={modified_hash}"
css_bg_image = f"background-image:url({image_url});"
css_bg_size = "background-size:cover;"
return " ".join([css_bg_image, css_bg_size])

0 comments on commit 14aec91

Please sign in to comment.