Skip to content

Commit

Permalink
Merge 797bb7c into 8ea23d1
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed May 6, 2016
2 parents 8ea23d1 + 797bb7c commit 50bb962
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ matrix:
fast_finish: true
install:
- sed -ie "s#test-4.3#test-$PLONE_VERSION#" buildout.cfg
- python bootstrap.py --setuptools-version=20.9.0
- python bootstrap.py --setuptools-version=21.0.0
- bin/buildout annotate
- bin/buildout
before_script:
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.1b2 (unreleased)
------------------

- Allow traversing to micro-updates (closes `#19`_).
[rodfersou]

- Use POST as request method on form used to edit micro-updates.
[hvelarde]

Expand Down Expand Up @@ -109,3 +112,4 @@ Changelog
.. _`#7`: https://github.com/collective/collective.liveblog/issues/7
.. _`#10`: https://github.com/collective/collective.liveblog/issues/10
.. _`#14`: https://github.com/collective/collective.liveblog/issues/14
.. _`#19`: https://github.com/collective/collective.liveblog/issues/19
9 changes: 9 additions & 0 deletions src/collective/liveblog/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
template="templates/view.pt"
/>

<browser:page
for="collective.liveblog.interfaces.ILiveblog"
name="microupdate"
class="collective.liveblog.browser.view.MicroUpdate"
permission="zope2.View"
layer="collective.liveblog.interfaces.IBrowserLayer"
template="templates/microupdate.pt"
/>

<browser:page
for="collective.liveblog.interfaces.ILiveblog"
name="update"
Expand Down
4 changes: 3 additions & 1 deletion src/collective/liveblog/browser/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class Header(ViewletBase):

def available(self):
"""Return True if an image has been defined."""
return self.context.image is not None
is_microupdate = (
self.request.getURL().replace(self.context.absolute_url(), '') != '/view')
return self.context.image is not None and not is_microupdate
68 changes: 68 additions & 0 deletions src/collective/liveblog/browser/templates/microupdate.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<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"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="collective.liveblog">
<head>
<metal:block metal:fill-slot="top_slot"
tal:define="dummy python:request.set('disable_border',1)" />
</head>
<body>
<metal:block fill-slot="main">
<article itemscope
itemtype="http://schema.org/BlogPosting"
tal:define="update view/update"
tal:condition="update">
<header>
<div tal:replace="structure provider:plone.abovecontenttitle" />
<h1 class="documentFirstHeading"
itemprop="headline"
tal:content="update/title"
tal:condition="update/title">
Title
</h1>
<div class="documentByLine">
<tal:byline condition="view/show_byline">
<span i18n:translate="label_by_author">
by
<span itemprop="author"
tal:content="update/creator"
i18n:name="byline" />
</span>
&mdash;
<tal:mod i18n:translate="box_last_modified">
last modified
</tal:mod>
<span tal:replace="update/datetime">
August 16, 2001 at 23:35:59
</span>
</tal:byline>
</div>
</header>
<div tal:replace="structure provider:plone.abovecontentbody" />
<div id="content-core"
itemprop="articleBody">
<section id="micro-updates">
<article class="microupdate"
data-timestamp=""
itemprop="comment"
itemscope
itemtype="http://schema.org/Comment"
tal:condition="update"
tal:attributes="data-timestamp update/timestamp">
<div class="microupdate-text"
itemprop="text"
tal:content="structure update/text" />
</article>
</section>
</div>
<div tal:replace="structure provider:plone.belowcontentbody" />
<div class="back"><span i18n:translate=""
tal:omit-tag="">Extracted from:</span> <a tal:attributes="href context/absolute_url"
tal:content="context/Title" /></div>
</article>
</metal:block>
</body>
</html>
21 changes: 13 additions & 8 deletions src/collective/liveblog/browser/templates/view.pt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@
tal:attributes="datetime update/isoformat;
title update/datetime;
data-date update/date;
data-time update/time">
<span class="microupdate-time" tal:content="update/time" />
data-time update/time;
data-timestamp update/timestamp">
<a tal:attributes="href string:microupdate/${update/timestamp}">
<span class="microupdate-time" tal:content="update/time" />
</a>
</time>
</div>
</article>
Expand All @@ -68,14 +71,16 @@
<script>
/* show dates for micro-updates older than today */
var today = new Date().toISOString().substr(0, 10);
$("time").each(function () {
$("time a").each(function () {
"use strict";
var datetime = $(this).attr("datetime").substr(0, 10),
date = $(this).attr("data-date"),
time = $(this).attr("data-time");
var $time = $(this).parent(),
datetime = $time.attr("datetime").substr(0, 10),
date = $time.attr("data-date"),
time = $time.attr("data-time"),
timestamp = $time.attr("data-timestamp");
if (today > datetime) {
$(this).html("<span class='microupdate-date'>" + date + "</span> " +
"<span class='microupdate-time'>" + time + "</span>");
$(this).html("<a href='microupdate/" + timestamp + "'><span class='microupdate-date'>" + date + "</span> " +
"<span class='microupdate-time'>" + time + "</span></a>");
}
});
</script>
Expand Down
18 changes: 18 additions & 0 deletions src/collective/liveblog/browser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from plone import api
from plone.memoize import ram
from time import time
from zExceptions import NotFound
from zope.publisher.browser import BrowserView


Expand Down Expand Up @@ -37,3 +38,20 @@ def automatic_updates_enabled(self):
def now(self):
"""Return a timestamp for the current date and time."""
return str(time())


class MicroUpdate(BrowserView, BaseView):

"""Default microupdate view for Liveblog."""

update = None

def publishTraverse(self, request, name):
"""Get the selected microupdate"""
microupdate = [
mu for mu in self.context.get_microupdates()
if mu['timestamp'] == name]
if len(microupdate) != 1:
raise NotFound
self.update = microupdate[0]
return self
2 changes: 2 additions & 0 deletions src/collective/liveblog/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
i18n:attributes="title; description"
/>

<include package=".upgrades" />

<utility factory=".setuphandlers.HiddenProfiles" name="collective.liveblog" />

</configure>
2 changes: 1 addition & 1 deletion src/collective/liveblog/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>1000</version>
<version>1001</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
</dependencies>
Expand Down
10 changes: 6 additions & 4 deletions src/collective/liveblog/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
}
.portaltype-liveblog article .field input[type="text"] {
width: 100%;
line-height: 125%;
color: black;
letter-spacing: -0.05em;
margin: inherit -0.05em;
font-size: 2em;
font-weight: bold;
}
Expand Down Expand Up @@ -38,6 +34,9 @@
padding: 1em 0 0 0;
position: relative;
}
.template-microupdate.portaltype-liveblog #micro-updates article {
border-top: none;
}
.microupdate-byline time {
background: #f1f1f1;
padding: 1em 0;
Expand All @@ -64,6 +63,9 @@
.microupdate-title, .microupdate-text, .microupdate-byline p {
margin-left: 110px;
}
.template-microupdate.portaltype-liveblog .microupdate-text {
margin-left: auto;
}
.microupdate-byline {
color: #666;
}
Expand Down
49 changes: 49 additions & 0 deletions src/collective/liveblog/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from collective.liveblog.testing import INTEGRATION_TESTING

import unittest


class UpgradeTestCaseBase(unittest.TestCase):

layer = INTEGRATION_TESTING

def setUp(self, from_version, to_version):
self.portal = self.layer['portal']
self.setup = self.portal['portal_setup']
self.profile_id = u'collective.liveblog:default'
self.from_version = from_version
self.to_version = to_version

def get_upgrade_step(self, title):
"""Get the named upgrade step."""
self.setup.setLastVersionForProfile(self.profile_id, self.from_version)
upgrades = self.setup.listUpgrades(self.profile_id)
steps = [s for s in upgrades[0] if s['title'] == title]
return steps[0] if steps else None

def execute_upgrade_step(self, step):
"""Execute an upgrade step."""
request = self.layer['request']
request.form['profile_id'] = self.profile_id
request.form['upgrades'] = [step['id']]
self.setup.manage_doUpgrades(request=request)

@property
def total_steps(self):
"""Return the number of steps in the upgrade."""
self.setup.setLastVersionForProfile(self.profile_id, self.from_version)
upgrades = self.setup.listUpgrades(self.profile_id)
assert len(upgrades) > 0
return len(upgrades[0])


class Upgrade1000to1001TestCase(UpgradeTestCaseBase):

def setUp(self):
UpgradeTestCaseBase.setUp(self, u'1000', u'1001')

def test_upgrade_to_1001_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertTrue(int(version) >= int(self.to_version))
self.assertEqual(self.total_steps, 1)
4 changes: 4 additions & 0 deletions src/collective/liveblog/tests/test_viewlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ def test_viewlet_is_available(self):
self.assertFalse(viewlet.available())
from plone.namedfile.file import NamedBlobImage
self.liveblog.image = NamedBlobImage()
self.assertFalse(viewlet.available())
self.request['URL'] = 'http://nohost/plone/liveblog/view'
self.assertTrue(viewlet.available())
self.request['URL'] = 'http://nohost/plone/liveblog/microupdate/1462277979.55'
self.assertFalse(viewlet.available())
19 changes: 19 additions & 0 deletions src/collective/liveblog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import timedelta
from plone import api
from time import time
from zExceptions import NotFound
from zope.interface import alsoProvides

import unittest
Expand Down Expand Up @@ -52,6 +53,24 @@ def test_date_is_shown_in_microupdates_older_than_today(self):
self.assertIn(comment, self.view())


class MicroupdateViewTestCase(ViewTestCase):

def setUp(self):
super(MicroupdateViewTestCase, self).setUp()
self.view = api.content.get_view('microupdate', self.liveblog, self.request)

def test_show_microupdate(self):
_create_microupdates(self.liveblog, 1)
with self.assertRaises(NotFound):
self.view.publishTraverse(self.request, 'asdf')

timestamp = self.liveblog.get_microupdates()[0]['timestamp']
self.view.publishTraverse(self.request, timestamp)
self.assertIn('template-microupdate', self.view())
self.assertIn('portaltype-liveblog', self.view())
self.assertIn('<div class="microupdate-text" itemprop="text">1</div>', self.view())


class UpdateViewTestCase(ViewTestCase):

def setUp(self):
Expand Down
21 changes: 21 additions & 0 deletions src/collective/liveblog/upgrades/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding:utf-8 -*-
from plone import api
from collective.liveblog.config import PROJECTNAME

import logging

logger = logging.getLogger(PROJECTNAME)


def cook_css_resources(context):
"""Cook css resources."""
css_tool = api.portal.get_tool('portal_css')
css_tool.cookResources()
logger.info('CSS resources were cooked')


def cook_javascript_resources(context):
"""Cook javascript resources."""
js_tool = api.portal.get_tool('portal_javascripts')
js_tool.cookResources()
logger.info('Javascript resources were cooked')
8 changes: 8 additions & 0 deletions src/collective/liveblog/upgrades/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="collective.liveblog">

<!-- Include Upgrades -->
<include package=".v1001" />

</configure>
1 change: 1 addition & 0 deletions src/collective/liveblog/upgrades/v1001/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
19 changes: 19 additions & 0 deletions src/collective/liveblog/upgrades/v1001/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:gs="http://namespaces.zope.org/genericsetup"
i18n_domain="collective.liveblog">

<gs:upgradeSteps
source="1000"
destination="1001"
profile="collective.liveblog:default">

<gs:upgradeStep
title="Cook CSS resources"
description="There were changes in the CSS files, so we need to cook the resources."
handler="..cook_css_resources"
/>

</gs:upgradeSteps>

</configure>

0 comments on commit 50bb962

Please sign in to comment.