Skip to content

Commit

Permalink
support for site_logo from registry
Browse files Browse the repository at this point in the history
- Added support for site logos stored in the portal registry via the site
  control panel for the logo viewlet with a fallback to the  ``OFS.Image``
  based ``logo.png`` file. Removed support of long-gone
  ``base_properties.props`` defined logo names.
  • Loading branch information
thet committed Jan 22, 2015
1 parent e8c6e98 commit 814d98c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
2.5.4 (unreleased)
------------------

- Added support for site logos stored in the portal registry via the site
control panel for the logo viewlet with a fallback to the ``OFS.Image``
based ``logo.png`` file. Removed support of long-gone
``base_properties.props`` defined logo names.
[thet]

- Updated markup for dashboard.
[davisagli]

Expand Down
40 changes: 30 additions & 10 deletions plone/app/layout/viewlets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

from plone.app.layout.globals.interfaces import IViewView
from plone.protect.utils import addTokenToUrl
from plone.formwidget.namedfile.converter import b64decode_file
from plone.namedfile.file import NamedImage


class ViewletBase(BrowserView):
Expand Down Expand Up @@ -191,18 +193,36 @@ class LogoViewlet(ViewletBase):
def update(self):
super(LogoViewlet, self).update()

portal = self.portal_state.portal()
bprops = portal.restrictedTraverse('base_properties', None)
if bprops is not None:
logoName = bprops.logoName
else:
logoName = 'logo.png'

logoTitle = self.portal_state.portal_title()
self.logo_tag = portal.restrictedTraverse(
logoName).tag(title=logoTitle, alt=logoTitle)
# TODO: should this be changed to settings.site_title?

This comment has been minimized.

Copy link
@malthe

malthe Oct 25, 2017

Member

No, I believe the right thing to do is to have PloneSite override Title() and pull the registry-based site title.

Because, you can have a navigation root which has its own "navigation root title", e.g. an English-language folder via plone.app.multilingual.

self.navigation_root_title = self.portal_state.navigation_root_title()

registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix="plone")
logo_title = settings.site_title

if getattr(settings, 'site_logo', False):
filename, data = b64decode_file(settings.site_logo)
data = NamedImage(data=data, filename=filename)
width, height = data.getImageSize()
img_src = '{}/@@site-logo/{}'.format(
self.navigation_root_url, filename)
self.logo_tag = u'<img src="{img_src}" '\
u'width="{width}" height="{height}"'\
u'alt="{logo_title}" title="{logo_title}"/>'.format(
img_src=img_src,
width=width,
height=height,
logo_title=logo_title
)
else:
portal = self.portal_state.navigation_root()
# Support for OFS.Image/skin layer based logos
logo_name = 'logo.png'
self.logo_tag = portal.restrictedTraverse(
logo_name).tag(title=logo_title, alt=logo_title)
# TODO: deprecate the skin layer based logo above and use one
# defined as browser or plone resource.


class GlobalSectionsViewlet(ViewletBase):
index = ViewPageTemplateFile('sections.pt')
Expand Down
41 changes: 31 additions & 10 deletions plone/app/layout/viewlets/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.interfaces import INonStructuralFolder
from Products.CMFPlone.interfaces import ISiteSchema
from plone.app.layout.navigation.interfaces import INavigationRoot
from plone.app.layout.viewlets.common import ContentViewsViewlet
from plone.app.layout.viewlets.common import LogoViewlet
from plone.app.layout.viewlets.common import TitleViewlet
from plone.app.layout.viewlets.common import ViewletBase
from plone.app.layout.viewlets.tests.base import ViewletsTestCase
from plone.protect import authenticator as auth
from plone.registry.interfaces import IRegistry
from zope.component import getUtility
from zope.interface import alsoProvides
from zope.interface import directlyProvides
from zope.interface import noLongerProvides

from Products.CMFPlone.interfaces import INonStructuralFolder

from plone.app.layout.viewlets.tests.base import ViewletsTestCase
from plone.app.layout.viewlets.common import (
ViewletBase, LogoViewlet, TitleViewlet)

from plone.app.layout.viewlets.common import ContentViewsViewlet
from plone.app.layout.navigation.interfaces import INavigationRoot

from plone.protect import authenticator as auth
# Red pixel with filename pixel.png
SITE_LOGO_BASE64 = 'filenameb64:cGl4ZWwucG5n;datab64:iVBORw0KGgoAAAANSUhEUgAA'\
'AAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z8AAAAMBAQAY3Y2wAAAAA'\
'ElFTkSuQmCC'


class TestViewletBase(ViewletsTestCase):
Expand Down Expand Up @@ -119,7 +126,7 @@ def testTitleViewletInPortalfactory(self):
self.assertEqual(viewlet.site_title,
u'Add Page &mdash; Folder')

def testLogoViewlet(self):
def testLogoViewletDefault(self):
"""Logo links towards navigation root
"""
self._invalidateRequestMemoizations()
Expand All @@ -131,3 +138,17 @@ def testLogoViewlet(self):
self.assertEqual(viewlet.navigation_root_title, "Folder")
# there is no theme yet in Plone 5, so we see the old png logo
self.assertTrue("http://nohost/plone/logo.png" in viewlet.logo_tag)

def testLogoViewletRegistry(self):
"""If logo is defined in plone.app.registry, use that one.
"""
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone')
settings.site_logo = SITE_LOGO_BASE64

viewlet = LogoViewlet(self.folder.test, self.app.REQUEST, None)
viewlet.update()
self.assertTrue(
'<img src="http://nohost/plone/@@site-logo/pixel.png"'
' width="1" height="1"alt="Plone site" title="Plone site"/>'
in viewlet.logo_tag)

1 comment on commit 814d98c

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS PASSED
Mr.Roboto url : http://jenkins.plone.org/roboto/get_info?push=1e9de37c1883488d9e718400b980bdf9
plone-5.0-python-2.7 [SUCCESS]

Please sign in to comment.