Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed May 25, 2016
1 parent 6bcc3cd commit 5d278a8
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 49 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,9 @@ Changelog
1.1b3 (unreleased)
------------------

- Remove liveblog workflow, now a liveblog is automatically inactivated after one day without new microupdates (closes `#31`_).
- Liveblogs use now standard `simple_publication_workflow`;
automatic updates in liveblogs are now turned off if there are no new micro-updates in the last 24 hours;
`liveblog_workflow` was removed (closes `#31`_).
[rodfersou]

- Use absolute paths to link to micro-updates.
Expand Down
9 changes: 5 additions & 4 deletions README.rst
Expand Up @@ -70,7 +70,7 @@ Usage

After installing the package you will see a new content type available: Liveblog.

A liveblog has a title, a description and an image field.
Liveblogs have title, description, image and text fields.
The image field is used to set up a header on the liveblog.

.. figure:: https://raw.github.com/collective/collective.liveblog/master/create-liveblog.png
Expand All @@ -96,8 +96,9 @@ All people viewing your liveblog will receive automatic updates every minute.
:height: 560px
:width: 640px

Micro-updates can be viewed as separate pieces of content;
this makes easy to share them in social networks.
Micro-updates can be viewed as separate pieces of content,
using the link in their timestamp,
making easy to share them in social networks.

.. figure:: https://raw.github.com/collective/collective.liveblog/master/microupdate.png
:align: center
Expand All @@ -118,7 +119,7 @@ This way we avoid interrupting editors from their work.
:height: 500px
:width: 640px

The liveblog is automatically deactivated if there are no micro-updates in the last day.
Automatic updates in liveblogs are turned off if there are no new micro-updates in the last 24 hours.

How does it work
----------------
Expand Down
6 changes: 1 addition & 5 deletions src/collective/liveblog/browser/recent_updates.py
@@ -1,15 +1,11 @@
# -*- coding: utf-8 -*-
from App.Common import rfc1123_date
from collective.liveblog.browser.base import BaseView
from collective.liveblog.config import PROJECTNAME
from collective.liveblog.logger import logger
from datetime import datetime
from time import time
from zope.publisher.browser import BrowserView

import logging

logger = logging.getLogger(PROJECTNAME)


class RecentUpdates(BrowserView, BaseView):

Expand Down
10 changes: 4 additions & 6 deletions src/collective/liveblog/browser/view.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from collective.liveblog.browser.base import BaseView
from datetime import datetime
from datetime import timedelta
from DateTime import DateTime
from plone.memoize import ram
from time import time
from zope.publisher.browser import BrowserView
Expand Down Expand Up @@ -30,11 +29,10 @@ def has_updates(self):
@property
def automatic_updates_enabled(self):
"""Check if the Livelog must be updated automatically.
Automatic updates are disabled if no updates in the last day.
Automatic updates are turned off if there are no new
micro-updates in the last 24 hours.
"""
timestamp = self.context.modified().timeTime()
modified = datetime.fromtimestamp(timestamp)
return datetime.now() - modified < timedelta(days=1)
return (DateTime() - self.context.modified()) < 1

@property
def now(self):
Expand Down
7 changes: 7 additions & 0 deletions src/collective/liveblog/logger.py
@@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
from collective.liveblog.config import PROJECTNAME

import logging


logger = logging.getLogger(PROJECTNAME)
2 changes: 1 addition & 1 deletion src/collective/liveblog/setuphandlers.py
Expand Up @@ -7,7 +7,7 @@ class HiddenProfiles(object):

implements(INonInstallable)

def getNonInstallableProfiles(self):
def getNonInstallableProfiles(self): # pragma: no cover
"""Do not show on Plone's list of installable profiles."""
return [
u'collective.liveblog:uninstall',
Expand Down
19 changes: 14 additions & 5 deletions src/collective/liveblog/tests/test_upgrades.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from collective.liveblog.testing import INTEGRATION_TESTING
from plone import api

import unittest

Expand Down Expand Up @@ -57,11 +58,19 @@ def test_registered_steps(self):
self.assertEqual(steps, 1)

def test_remove_workflow(self):
# address also an issue with Setup permission
title = u'Remove liveblog workflow'
title = u'Migrate liveblog workflow'
step = self._get_upgrade_step_by_title(title)
self.assertIsNotNone(step)
assert step is not None

# too difficult to simulate previous state programmatically
# so we are just going to run the upgrade step here
# simulate (partially) state on previous version
wtool = api.portal.get_tool('portal_workflow')
wtool.setChainForPortalTypes(('Liveblog',), ('liveblog_workflow',))
assert wtool.getChainForPortalType('Liveblog') == ('liveblog_workflow',)

# execute upgrade step and verify changes were applied
self._do_upgrade(step)

self.assertEqual(
wtool.getChainForPortalType('Liveblog'),
('simple_publication_workflow',)
)
8 changes: 2 additions & 6 deletions src/collective/liveblog/upgrades/__init__.py
@@ -1,13 +1,9 @@
# -*- coding:utf-8 -*-
from collective.liveblog.logger import logger
from plone import api
from collective.liveblog.config import PROJECTNAME

import logging

logger = logging.getLogger(PROJECTNAME)


def cook_css_resources(context):
def cook_css_resources(context): # pragma: no cover
"""Cook CSS resources."""
css_tool = api.portal.get_tool('portal_css')
css_tool.cookResources()
Expand Down
35 changes: 17 additions & 18 deletions src/collective/liveblog/upgrades/v1002/__init__.py
@@ -1,34 +1,33 @@
# -*- coding:utf-8 -*-
from collective.liveblog.config import PROJECTNAME
from collective.liveblog.interfaces import ILiveblog
from collective.liveblog.logger import logger
from ftw.upgrade.workflow import WorkflowChainUpdater
from plone import api

import logging


logger = logging.getLogger(PROJECTNAME)


def remove_workflow(context):
"""Remove Liveblog Workflow and migrate objects to
simple_publication_workflow."""
catalog = api.portal.get_tool('portal_catalog')
mapping = {
def migrate_liveblog_workflow(context):
"""Migrate liveblog workflow."""
review_state_mapping = {
('liveblog_workflow', 'simple_publication_workflow'): {
'private': 'private',
'active': 'published',
'inactive': 'published'}
'inactive': 'published',
}
}

catalog = api.portal.get_tool('portal_catalog')
query = dict(object_provides=ILiveblog.__identifier__)
results = catalog.unrestrictedSearchResults(**query)
objects = [b.getObject() for b in results]
objects = (b.getObject() for b in results)

# all existing liveblogs must use now simple_publication_workflow
wtool = api.portal.get_tool('portal_workflow')
with WorkflowChainUpdater(objects, mapping):
with WorkflowChainUpdater(objects, review_state_mapping):
wtool.setChainForPortalTypes(
('Liveblog',), ('simple_publication_workflow',))
# don't fail on upgrade step test
if getattr(wtool, 'liveblog_workflow', False):
api.content.delete(obj=wtool.liveblog_workflow)
logger.info('Liveblog objects now use simple_publication_workflow')

logger.info('Liveblog workflow removed.')
# remove liveblog_workflow
if 'liveblog_workflow' in wtool:
api.content.delete(obj=wtool.liveblog_workflow)
logger.info('Liveblog workflow removed')
6 changes: 3 additions & 3 deletions src/collective/liveblog/upgrades/v1002/configure.zcml
Expand Up @@ -9,9 +9,9 @@
profile="collective.liveblog:default">

<genericsetup:upgradeStep
title="Remove liveblog workflow"
description="Remove liveblog workflow and update objects."
handler=".remove_workflow"
title="Migrate liveblog workflow"
description="Use simple_publication_workflow instead of liveblog_workflow."
handler=".migrate_liveblog_workflow"
/>

</genericsetup:upgradeSteps>
Expand Down

0 comments on commit 5d278a8

Please sign in to comment.