-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility of having an image on the header of the Liveblog
- Loading branch information
Showing
9 changed files
with
165 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from five import grok | ||
from plone.app.layout.viewlets.interfaces import IAboveContent | ||
from collective.liveblog.interfaces import ILiveblog | ||
from collective.liveblog.interfaces import IBrowserLayer | ||
|
||
grok.templatedir('templates') | ||
|
||
|
||
class Header(grok.Viewlet): | ||
|
||
"""A viewlet to include a header in the Liveblog.""" | ||
|
||
grok.name('collective.liveblog.header') | ||
grok.context(ILiveblog) | ||
grok.layer(IBrowserLayer) | ||
grok.require('zope2.View') | ||
grok.viewletmanager(IAboveContent) | ||
|
||
def available(self): | ||
"""Return True if an image has been defined.""" | ||
return self.context.image is not None |
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 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" | ||
xmlns:tal="http://xml.zope.org/namespaces/tal" | ||
xmlns:metal="http://xml.zope.org/namespaces/metal" | ||
xmlns:i18n="http://xml.zope.org/namespaces/i18n" | ||
i18n:domain="collective.liveblog"> | ||
<body> | ||
<tal:viewlet condition="viewlet/available"> | ||
<div id="liveblog-header"> | ||
<img tal:define="scale context/@@images" | ||
tal:replace="structure python:scale.scale('image').tag()" /> | ||
</div> | ||
</tal:viewlet> | ||
</body> | ||
</html> |
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
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,64 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Test case for viewlets on the package. | ||
For more information on how to test viewlets, see: | ||
http://developer.plone.org/views/viewlets.html#finding-viewlets-programmatically | ||
""" | ||
from plone import api | ||
from Products.Five.browser import BrowserView as View | ||
from collective.liveblog.interfaces import IBrowserLayer | ||
from collective.liveblog.testing import INTEGRATION_TESTING | ||
from zope.component import queryMultiAdapter | ||
from zope.interface import alsoProvides | ||
from zope.viewlet.interfaces import IViewletManager | ||
|
||
import unittest | ||
|
||
|
||
class ViewletTestCase(unittest.TestCase): | ||
|
||
"""Tests for viewlets.""" | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer['portal'] | ||
self.request = self.layer['request'] | ||
alsoProvides(self.request, IBrowserLayer) | ||
|
||
with api.env.adopt_roles(['Manager']): | ||
self.liveblog = api.content.create( | ||
self.portal, 'Liveblog', 'liveblog') | ||
|
||
def _get_viewlet_manager(self): | ||
context = self.liveblog | ||
request = self.request | ||
view = View(context, request) | ||
manager = queryMultiAdapter( | ||
(context, request, view), IViewletManager, 'plone.abovecontent') | ||
|
||
return manager | ||
|
||
def test_viewlet_is_registered(self): | ||
manager = self._get_viewlet_manager() | ||
self.assertTrue(manager) | ||
manager.update() | ||
self.assertIn(u'collective.liveblog.header', manager) | ||
|
||
def test_viewlet_order(self): | ||
manager = self._get_viewlet_manager() | ||
manager.update() | ||
self.assertEqual(len(manager.viewlets), 2) | ||
viewlets = [v.__name__ for v in manager.viewlets] | ||
self.assertListEqual( | ||
viewlets, [u'plone.path_bar', u'collective.liveblog.header']) | ||
|
||
def test_viewlet_is_available(self): | ||
manager = self._get_viewlet_manager() | ||
manager.update() | ||
viewlet = manager[u'collective.liveblog.header'] | ||
viewlet.update() | ||
self.assertFalse(viewlet.available()) | ||
from plone.namedfile.file import NamedBlobImage | ||
self.liveblog.image = NamedBlobImage() | ||
self.assertTrue(viewlet.available()) |