Skip to content

Commit

Permalink
site_logo in controlpanel + @@sitelogo view
Browse files Browse the repository at this point in the history
- Caching for ``@@site-logo``.

- Support for portal site logos stored in the portal registry by uploading via
  the site control panel. Add a ``@@site-logo`` view for downloading the logo.
  • Loading branch information
thet committed Jan 22, 2015
1 parent 7474e85 commit f52dfea
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Changelog
5.0b1 (unreleased)
------------------

- Caching for ``@@site-logo``.
[thet]

- Support for portal site logos stored in the portal registry by uploading via
the site control panel. Add a ``@@site-logo`` view for downloading the logo.
[thet]

- Fix the resource registry to save the automatically generated filepath to the
compiled resource on the bundle object after compilation. The filepath is
always in the '++plone++static/' namespace. This fix makes custom bundles
Expand Down
5 changes: 0 additions & 5 deletions Products/CMFPlone/browser/admin.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@

<adapter factory=".admin.AppTraverser" />

<browser:resource
file="plone-logo.png"
name="plone-logo.png"
/>

<browser:resource
file="plone-admin-ui.css"
name="plone-admin-ui.css"
Expand Down
14 changes: 14 additions & 0 deletions Products/CMFPlone/browser/caching.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:cache="http://namespaces.zope.org/cache"
i18n_domain="plone">

<include package="z3c.caching" />
<include package="z3c.caching" file="meta.zcml" />

<cache:ruleset
for=".sitelogo.SiteLogo"
ruleset="plone.stableResource"
/>

</configure>
17 changes: 16 additions & 1 deletion Products/CMFPlone/browser/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone">

<include file="admin.zcml" />
<include file="caching.zcml" zcml:condition="installed z3c.caching"/>

<class class="Products.CMFPlone.Portal.PloneSite">
<implements interface="plone.app.layout.navigation.interfaces.INavigationRoot" />
Expand All @@ -16,6 +19,18 @@
id="Products.CMFPlone.AllowSendto"
title="Allow sendto" />

<browser:resource
file="plone-logo.png"
name="plone-logo.png"
/>

<browser:page
for="*"
name="site-logo"
class=".sitelogo.SiteLogo"
permission="zope.Public"
/>

<browser:page
for="*"
name="sendto_form"
Expand Down
26 changes: 26 additions & 0 deletions Products/CMFPlone/browser/sitelogo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from Products.CMFPlone.interfaces import ISiteSchema
from plone.formwidget.namedfile.converter import b64decode_file
from plone.namedfile.browser import Download
from plone.namedfile.file import NamedImage
from plone.registry.interfaces import IRegistry
from zope.component import getUtility


class SiteLogo(Download):

def __init__(self, context, request):
super(SiteLogo, self).__init__(context, request)
self.filename = None
self.data = None

registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix="plone")
if getattr(settings, 'site_logo', False):
filename, data = b64decode_file(settings.site_logo)
data = NamedImage(data=data, filename=filename)
self.data = data
self.filename = filename
# self.width, self.height = self.data.getImageSize()

def _getFile(self):
return self.data
1 change: 1 addition & 0 deletions Products/CMFPlone/controlpanel/bbb/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def set_webstats_js(self, value):
site_title = property(get_site_title, set_site_title)
webstats_js = property(get_webstats_js, set_webstats_js)

site_logo = ProxyFieldProperty(ISiteSchema['site_logo'])
enable_sitemap = ProxyFieldProperty(ISiteSchema['enable_sitemap'])
exposeDCMetaTags = ProxyFieldProperty(ISiteSchema['exposeDCMetaTags'])
5 changes: 5 additions & 0 deletions Products/CMFPlone/controlpanel/browser/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from Products.CMFPlone import PloneMessageFactory as _
from Products.CMFPlone.interfaces import ISiteSchema
from plone.app.registry.browser import controlpanel
from plone.formwidget.namedfile.widget import NamedImageFieldWidget


class SiteControlPanelForm(controlpanel.RegistryEditForm):
Expand All @@ -12,6 +13,10 @@ class SiteControlPanelForm(controlpanel.RegistryEditForm):
schema = ISiteSchema
schema_prefix = "plone"

def updateFields(self):
super(SiteControlPanelForm, self).updateFields()
self.fields['site_logo'].widgetFactory = NamedImageFieldWidget


class SiteControlPanel(controlpanel.ControlPanelFormWrapper):
form = SiteControlPanelForm
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.interfaces import ISiteSchema
from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_FUNCTIONAL_TESTING
from StringIO import StringIO
from plone.app.testing import SITE_OWNER_NAME, SITE_OWNER_PASSWORD
from plone.registry.interfaces import IRegistry
from plone.testing.z2 import Browser
from zope.component import getMultiAdapter
from zope.component import getUtility
import unittest2 as unittest

# Red pixel with filename pixel.png
SITE_LOGO_BASE64 = 'filenameb64:cGl4ZWwucG5n;datab64:iVBORw0KGgoAAAANSUhEUgAA'\
'AAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z8AAAAMBAQAY3Y2wAAAAA'\
'ElFTkSuQmCC'
SITE_LOGO_HEX = '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00'\
'\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDAT'\
'\x08\xd7c\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\x18\xdd\x8d'\
'\xb0\x00\x00\x00\x00IEND\xaeB`\x82'


class SiteControlPanelFunctionalTest(unittest.TestCase):
"""Test that changes in the site control panel are actually
Expand Down Expand Up @@ -84,6 +94,17 @@ def test_site_title_can_be_looked_up_by_portal_title(self):
self.assertEqual(self.portal.title, u'My Site')
self.assertEqual(self.portal.Title(), u'My Site')

def test_site_logo_is_stored_in_registry(self):
self.browser.open(
"%s/@@site-controlpanel" % self.portal_url)
ctrl = self.browser.getControl(name="form.widgets.site_logo")
ctrl.add_file(StringIO(SITE_LOGO_HEX), 'image/png', 'pixel.png')
self.browser.getControl('Save').click()

registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone')
self.assertEqual(settings.site_logo, SITE_LOGO_BASE64)

def test_exposeDCMetaTags(self):
self.browser.open(
"%s/@@site-controlpanel" % self.portal_url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def test_search_in_controlpanel(self):
def test_site_title_setting(self):
self.assertTrue(hasattr(self.settings, 'site_title'))

def test_site_logo_setting(self):
self.assertTrue(hasattr(self.settings, 'site_logo'))

def test_exposeDCMetaTags_setting(self):
self.assertTrue(hasattr(self.settings, 'exposeDCMetaTags'))

Expand Down
8 changes: 7 additions & 1 deletion Products/CMFPlone/interfaces/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from Products.CMFPlone.utils import validate_json
from basetool import IPloneBaseTool
from plone.locking.interfaces import ILockSettings
from zope import schema
from zope.interface import Interface
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
from zope import schema


class IControlPanel(IPloneBaseTool):
Expand Down Expand Up @@ -866,6 +866,12 @@ class ISiteSchema(ILockSettings):
u"browsers and in syndication feeds."),
default=u'Plone site')

site_logo = schema.ASCII(
title=_(u"Site Logo"),
description=_(u"This shows a custom Logo on your Site."),
required=False,
)

exposeDCMetaTags = schema.Bool(
title=_(u"Expose Dublin Core metadata"),
description=_(u"Exposes the Dublin Core properties as metatags."),
Expand Down
39 changes: 39 additions & 0 deletions Products/CMFPlone/tests/test_sitelogo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.interfaces import ISiteSchema
from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_INTEGRATION_TESTING
from plone.registry.interfaces import IRegistry
from zope.component import getUtility
import unittest2 as unittest

# Red pixel with filename pixel.png
SITE_LOGO_BASE64 = 'filenameb64:cGl4ZWwucG5n;datab64:iVBORw0KGgoAAAANSUhEUgAA'\
'AAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z8AAAAMBAQAY3Y2wAAAAA'\
'ElFTkSuQmCC'
SITE_LOGO_HEX = '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00'\
'\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDAT'\
'\x08\xd7c\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\x18\xdd\x8d'\
'\xb0\x00\x00\x00\x00IEND\xaeB`\x82'


class SiteLogoFunctionalTest(unittest.TestCase):
"""Test the site logo view.
"""
layer = PRODUCTS_CMFPLONE_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']

def test_sitelogo_view(self):
registry = getUtility(IRegistry)
settings = registry.forInterface(ISiteSchema, prefix='plone')
settings.site_logo = SITE_LOGO_BASE64
view = self.portal.restrictedTraverse('@@site-logo')
self.assertTrue(view(), SITE_LOGO_HEX)
view.request.response
headers = view.request.response
self.assertTrue(headers['content-type'], 'image/png')
self.assertTrue(headers['content-length'], '69')
self.assertTrue(
headers['content-disposition'],
"attachment; filename*=UTF-8''pixel.png"
)

1 comment on commit f52dfea

@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=1291f301e0b641f581f8cab9460d1977
plone-5.0-python-2.7 [SUCCESS]

Please sign in to comment.