Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed May 16, 2017
1 parent 293cfeb commit b2f3feb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -6,7 +6,8 @@ There's a frood who really knows where his towel is.
2.1b2 (unreleased)
^^^^^^^^^^^^^^^^^^

- Fix upgrade process between versions 1.0 and 2.0 (fixes `#198`_).
- Fix upgrade process between versions 1.0 and 2.0;
check documentation on migration from 1.x to 2.x (closes `#198`_).
[rodfersou, hvelarde]


Expand Down
50 changes: 24 additions & 26 deletions README.rst
Expand Up @@ -84,32 +84,6 @@ You may use the `NITF Document Type Definition`_ version 3.5 and the `XHTML Ruby
.. _`XML validation`: http://www.xmlvalidation.com/
.. _`opening a support ticket`: https://github.com/collective/collective.nitf/issues

Migration from 1.x to 2.x
^^^^^^^^^^^^^^^^^^^^^^^^^

When migrate from version 1.x to 2.x these changes happen in your portal:

* Now we have a specific permissions to update the configlet ``collective.nitf: Setup``.
* There is no character counter when create a new NITF document.
* Static resources are now named ``nitf.css`` and ``nitf.js`` (easier to debug at the browser).
* The default behaviors of this content type change:

* Remove ``plone.app.referenceablebehavior.referenceable.IReferenceable`` behavior.
* Add ``plone.app.relationfield.behavior.IRelatedItems`` behavior.
* Add ``collective.nitf.behaviors.interfaces.ISection`` behavior.

* Default views also change, what require to review your site theme:

* Default view shows a big image in the news item.
* Rename view ``nitf_galleria`` to ``slideshow_view``. Now ``collective.nitf`` uses ``cycle2`` instead of ``galleria`` to create the slideshow, what make it easier to theme.
* Add new view ``text_only_view`` to open the text without the default big image.

* This package now depends on `collective.js.cycle2`_, and this is the home of cycle2 static resources.

There is an upgrade step to update all content (rename the views, change the behaviors as described above) and also this upgrade step will reindex all objects.

.. _`collective.js.cycle2`: https://github.com/collective/collective.js.cycle2

Internals
---------

Expand Down Expand Up @@ -166,3 +140,27 @@ The following command rebuilds static files and exit (insted of keep watching th
.. code-block:: bash
$ bin/npm_build
Migration from 1.x to 2.x
^^^^^^^^^^^^^^^^^^^^^^^^^

You have to be aware of the following changes when migrating from version 1.x to 2.x:

* Package is no longer compatible with Plone 4.2
* Package no longer depends on Grok
* Package no longer depends on `collective.z3cform.widgets <http://pypi.python.org/pypi/collective.z3cform.widgets>`_;
you should uninstall that dependency manually if there is no other package depending on it on your site
* Package no longer depends on `plone.app.referenceablebehavior <http://pypi.python.org/pypi/plone.app.referenceablebehavior>`_;
the ``IReferenceable`` behavior included there is no longer assigned by default
* The character counter is no longer available
* We use `Cycle2 <http://jquery.malsup.com/cycle2/>`_ instead of `Galleria <https://galleria.io/>`_ as the framework for the slideshow view;
package now depends on `collective.js.cycle2 <https://pypi.python.org/pypi/collective.js.cycle2>`_
* The following views are available for a News Article: ``view``, ``slideshow_view`` and ``text_only_view``
* View templates were completely refactored and support for semantic markup was added;
the default view displays a bigger image
* The following behaviors are assigned by default to the News Article content type: ``plone.app.relationfield.behavior.IRelatedItems`` and ``collective.nitf.behaviors.interfaces.ISection``
* A new permission ``collective.nitf: Setup`` is available to access the control panel configlet and is assigned by default to ``Manager`` and ``Site Administrator`` roles
* Static resources are now named ``nitf.css`` and ``nitf.js`` (easier to debug at the browser)

An upgrade step is available to remove old resources, rename the views, and reindex all News Articles to reflect changes.
The upgrade step will not remove the ``plone.app.referenceablebehavior.referenceable.IReferenceable`` behavior if applied.
2 changes: 1 addition & 1 deletion buildout.cfg
Expand Up @@ -31,7 +31,7 @@ multiprocessing = True
pre-commit-hook = True
return-status-codes = True
flake8 = True
flake8-ignore = E501,P001,T000
flake8-ignore = E501,P001,S001,T000

[instance]
zope-conf-additional += publisher-profile-file ${buildout:directory}/var/instance/profile.dat
Expand Down
10 changes: 4 additions & 6 deletions src/collective/nitf/tests/test_upgrades.py
Expand Up @@ -250,21 +250,19 @@ def test_update_behaviors(self):

# simulate state on previous version
from collective.nitf.upgrades.v2000 import BEHAVIORS_TO_ADD
from collective.nitf.upgrades.v2000 import BEHAVIORS_TO_REMOVE
REFERENCEABLE = 'plone.app.referenceablebehavior.referenceable.IReferenceable'
fti = getUtility(IDexterityFTI, name='collective.nitf.content')
fti.behaviors = tuple(
set(fti.behaviors) - BEHAVIORS_TO_ADD | BEHAVIORS_TO_REMOVE)
set(fti.behaviors) - BEHAVIORS_TO_ADD | set([REFERENCEABLE]))
for b in BEHAVIORS_TO_ADD:
self.assertNotIn(b, fti.behaviors)
for b in BEHAVIORS_TO_REMOVE:
self.assertIn(b, fti.behaviors)
self.assertIn(REFERENCEABLE, fti.behaviors)

# run the upgrade step to validate the update
self.execute_upgrade_step(step)
self.assertNotIn(
'plone.app.referenceablebehavior.referenceable.IReferenceable', fti.behaviors)
self.assertIn('plone.app.relationfield.behavior.IRelatedItems', fti.behaviors)
self.assertIn('collective.nitf.behaviors.interfaces.ISection', fti.behaviors)
self.assertIn(REFERENCEABLE, fti.behaviors) # should not be removed

def test_reindex_news_articles(self):
# check if the upgrade step is registered
Expand Down
6 changes: 1 addition & 5 deletions src/collective/nitf/upgrades/v2000/__init__.py
Expand Up @@ -63,9 +63,6 @@ def update_configlet(setup_tool):
logger.info('Control panel configlet updated.')


BEHAVIORS_TO_REMOVE = frozenset([
'plone.app.referenceablebehavior.referenceable.IReferenceable',
])
BEHAVIORS_TO_ADD = frozenset([
'plone.app.relationfield.behavior.IRelatedItems',
'collective.nitf.behaviors.interfaces.ISection',
Expand All @@ -75,8 +72,7 @@ def update_configlet(setup_tool):
def update_behaviors(setup_tool):
"""Update News Article behaviors."""
fti = getUtility(IDexterityFTI, name='collective.nitf.content')
fti.behaviors = tuple(
set(fti.behaviors) - BEHAVIORS_TO_REMOVE | BEHAVIORS_TO_ADD)
fti.behaviors = tuple(set(fti.behaviors) | BEHAVIORS_TO_ADD)
logger.info('News Article behaviors updated.')


Expand Down

0 comments on commit b2f3feb

Please sign in to comment.