Skip to content

Commit

Permalink
Add the possibility of having an image on the header of the Liveblog
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed Aug 28, 2014
1 parent 02cc94b commit 1069001
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 30 deletions.
22 changes: 22 additions & 0 deletions src/collective/liveblog/browser/header.py
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
14 changes: 14 additions & 0 deletions src/collective/liveblog/browser/templates/header.pt
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>
6 changes: 3 additions & 3 deletions src/collective/liveblog/browser/templates/updates.pt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
tal:omit-tag=""
i18n:domain="collective.liveblog">
i18n:domain="collective.liveblog"
tal:omit-tag="">
<body tal:omit-tag="">
<div id="micro-updates" tal:omit-tag="">
<div class="microupdate" data-timestamp=""
Expand Down
2 changes: 1 addition & 1 deletion src/collective/liveblog/browser/templates/view.pt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
<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"
metal:use-macro="context/main_template/macros/master"
Expand Down
8 changes: 8 additions & 0 deletions src/collective/liveblog/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from collective.liveblog import _
from plone.directives import form
from plone.namedfile.field import NamedBlobImage
from zope.interface import Interface


Expand All @@ -13,3 +15,9 @@ class ILiveblog(form.Schema):
"""A liveblog is a blog post which is intended to provide a rolling
textual coverage of an ongoing event.
"""

image = NamedBlobImage(
title=_(u'Image'),
description=_(u'This image will be used as a header on the Liveblog.'),
required=False,
)
25 changes: 17 additions & 8 deletions src/collective/liveblog/locales/collective.liveblog.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2014-08-27 13:53+0000\n"
"POT-Creation-Date: 2014-08-28 15:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -18,35 +18,44 @@ msgstr ""
msgid "A liveblog is a blog post which is intended to provide a rolling textual coverage of an ongoing event."
msgstr ""

#: collective/liveblog/templates/view.pt:10
#: collective/liveblog/browser/templates/view.pt:11
msgid "Add micro-update"
msgstr ""

#: collective/liveblog/templates/view.pt:40
#: collective/liveblog/browser/templates/updates.pt:17
#: collective/liveblog/browser/templates/view.pt:42
msgid "By <span>${DYNAMIC_CONTENT}</span> <span title=\"${DYNAMIC_CONTENT}\">${DYNAMIC_CONTENT}</span>"
msgstr ""

#: collective/liveblog/browser.py:83
#: collective/liveblog/interfaces.py:20
msgid "Image"
msgstr ""

#: collective/liveblog/browser/add_microupdate.py:36
msgid "Item published."
msgstr ""

#: collective/liveblog/profiles/default/types/Liveblog.xml
msgid "Liveblog"
msgstr ""

#: collective/liveblog/templates/view.pt:43
#: collective/liveblog/browser/templates/view.pt:49
msgid "No micro-updates yet for this Liveblog."
msgstr ""

#: collective/liveblog/templates/view.pt:27
#: collective/liveblog/browser/templates/view.pt:28
msgid "Publish"
msgstr ""

#: collective/liveblog/browser.py:75
#: collective/liveblog/browser/add_microupdate.py:28
msgid "There were some errors. Required input is missing."
msgstr ""

#: collective/liveblog/templates/view.pt:13
#: collective/liveblog/interfaces.py:21
msgid "This image will be used as a header on the Liveblog."
msgstr ""

#: collective/liveblog/browser/templates/view.pt:14
msgid "Title"
msgstr ""

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2014-08-27 13:53+0000\n"
"PO-Revision-Date: 2014-08-27 10:54-0300\n"
"POT-Creation-Date: 2014-08-28 15:08+0000\n"
"PO-Revision-Date: 2014-08-28 12:10-0300\n"
"Last-Translator: Héctor Velarde <hector.velarde@gmail.com>\n"
"Language-Team: Plone Collective\n"
"MIME-Version: 1.0\n"
Expand All @@ -24,38 +24,47 @@ msgstr ""
"Un blog en vivo es una entrada de blog que pretende proporcionar una "
"cobertura amplia de un evento en curso."

#: collective/liveblog/templates/view.pt:10
#: collective/liveblog/browser/templates/view.pt:11
msgid "Add micro-update"
msgstr "Agregar actualización"

#: collective/liveblog/templates/view.pt:40
#: collective/liveblog/browser/templates/updates.pt:17
#: collective/liveblog/browser/templates/view.pt:42
msgid ""
"By <span>${DYNAMIC_CONTENT}</span> <span title=\"${DYNAMIC_CONTENT}\">"
"${DYNAMIC_CONTENT}</span>"
msgstr ""
"Por <span>${DYNAMIC_CONTENT}</span> <span title=\"${DYNAMIC_CONTENT}\">"
"${DYNAMIC_CONTENT}</span>"

#: collective/liveblog/browser.py:83
#: collective/liveblog/interfaces.py:20
msgid "Image"
msgstr "Imagen"

#: collective/liveblog/browser/add_microupdate.py:36
msgid "Item published."
msgstr "Elemento publicado."

#: collective/liveblog/profiles/default/types/Liveblog.xml
msgid "Liveblog"
msgstr "Blog en vivo"

#: collective/liveblog/templates/view.pt:43
#: collective/liveblog/browser/templates/view.pt:49
msgid "No micro-updates yet for this Liveblog."
msgstr "Todavía no hay actualizaciones para este blog en vivo."

#: collective/liveblog/templates/view.pt:27
#: collective/liveblog/browser/templates/view.pt:28
msgid "Publish"
msgstr "Publicar"

#: collective/liveblog/browser.py:75
#: collective/liveblog/browser/add_microupdate.py:28
msgid "There were some errors. Required input is missing."
msgstr "Ocurrió un error. Falta información requerida."

#: collective/liveblog/templates/view.pt:13
#: collective/liveblog/interfaces.py:21
msgid "This image will be used as a header on the Liveblog."
msgstr "Esta imagen será usada como encabezado del blog en vivo."

#: collective/liveblog/browser/templates/view.pt:14
msgid "Title"
msgstr "Título"
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2014-08-27 13:53+0000\n"
"PO-Revision-Date: 2014-08-27 10:53-0300\n"
"POT-Creation-Date: 2014-08-28 15:08+0000\n"
"PO-Revision-Date: 2014-08-28 12:10-0300\n"
"Last-Translator: Héctor Velarde <hector.velarde@gmail.com>\n"
"Language-Team: Plone Collective\n"
"MIME-Version: 1.0\n"
Expand All @@ -24,38 +24,47 @@ msgstr ""
"Um blog ao vivo é um post de blog que pretende fornecer uma cobertura amplia "
"de um evento em curso."

#: collective/liveblog/templates/view.pt:10
#: collective/liveblog/browser/templates/view.pt:11
msgid "Add micro-update"
msgstr "Adicionar atualização"

#: collective/liveblog/templates/view.pt:40
#: collective/liveblog/browser/templates/updates.pt:17
#: collective/liveblog/browser/templates/view.pt:42
msgid ""
"By <span>${DYNAMIC_CONTENT}</span> <span title=\"${DYNAMIC_CONTENT}\">"
"${DYNAMIC_CONTENT}</span>"
msgstr ""
"Por <span>${DYNAMIC_CONTENT}</span> <span title=\"${DYNAMIC_CONTENT}\">"
"${DYNAMIC_CONTENT}</span>"

#: collective/liveblog/browser.py:83
#: collective/liveblog/interfaces.py:20
msgid "Image"
msgstr "Imagem"

#: collective/liveblog/browser/add_microupdate.py:36
msgid "Item published."
msgstr "Item publicado."

#: collective/liveblog/profiles/default/types/Liveblog.xml
msgid "Liveblog"
msgstr "Blog ao vivo"

#: collective/liveblog/templates/view.pt:43
#: collective/liveblog/browser/templates/view.pt:49
msgid "No micro-updates yet for this Liveblog."
msgstr "Este blog ao vivo ainda não tem atualizações."

#: collective/liveblog/templates/view.pt:27
#: collective/liveblog/browser/templates/view.pt:28
msgid "Publish"
msgstr "Publicar"

#: collective/liveblog/browser.py:75
#: collective/liveblog/browser/add_microupdate.py:28
msgid "There were some errors. Required input is missing."
msgstr "Ocurreu um erro. Falta informação requerida."

#: collective/liveblog/templates/view.pt:13
#: collective/liveblog/interfaces.py:21
msgid "This image will be used as a header on the Liveblog."
msgstr "Esta imagem será usada como o cabeçalho do blog ao vivo."

#: collective/liveblog/browser/templates/view.pt:14
msgid "Title"
msgstr "Título"
64 changes: 64 additions & 0 deletions src/collective/liveblog/tests/test_viewlet.py
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())

0 comments on commit 1069001

Please sign in to comment.