-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
site_logo in controlpanel + @@sitelogo view
- 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
Showing
11 changed files
with
139 additions
and
7 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
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
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 |
---|---|---|
@@ -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> |
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
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 |
---|---|---|
@@ -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 |
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
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
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
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
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
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 |
---|---|---|
@@ -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" | ||
) |
f52dfea
There was a problem hiding this comment.
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]