Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register alternate view #296

Merged
merged 8 commits into from
Sep 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ There's a frood who really knows where his towel is
1.0a5 (unreleased)
^^^^^^^^^^^^^^^^^^

- Register new alternate view for covers; the new view behaves like a standard
content type view displaying object's title, description and viewlets on
Plone's main_template main slot (closes `#271`_). [hvelarde]

- Fixes content-search in content chooser to correctly get the first
page of results (closes `#276`_). [marcosfromero]

Expand Down Expand Up @@ -251,6 +255,7 @@ There's a frood who really knows where his towel is
.. _`#244`: https://github.com/collective/collective.cover/issues/244
.. _`#259`: https://github.com/collective/collective.cover/issues/259
.. _`#262`: https://github.com/collective/collective.cover/issues/262
.. _`#271`: https://github.com/collective/collective.cover/issues/271
.. _`#274`: https://github.com/collective/collective.cover/issues/274
.. _`#276`: https://github.com/collective/collective.cover/issues/276
.. _`#278`: https://github.com/collective/collective.cover/issues/278
Expand Down
13 changes: 13 additions & 0 deletions src/collective/cover/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,17 @@
/>
</class>

<browser:menuItems
for="collective.cover.content.ICover"
menu="plone_displayviews">
<browser:menuItem
title="Front page view"
action="view"
/>
<browser:menuItem
title="Standard view"
action="standard"
/>
</browser:menuItems>

</configure>
7 changes: 7 additions & 0 deletions src/collective/cover/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ class Cover(Item):
implements(IDAVAware)


# TODO: move browser views to browser folder
class View(grok.View):
grok.context(ICover)
grok.require('zope2.View')
grok.name('view')


class Standard(grok.View):
grok.context(ICover)
grok.require('zope2.View')
grok.name('standard')


class AddCTWidget(grok.View):
grok.context(ICover)
grok.require('cmf.ModifyPortalContent')
Expand Down
6 changes: 6 additions & 0 deletions src/collective/cover/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
handler=".upgrades.tinymce_linkable"
/>

<genericsetup:upgradeStep
title="Register alternate view"
description="The new view behaves like a standard content type view"
handler=".upgrades.register_alternate_view"
/>

</genericsetup:upgradeSteps>

</configure>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<property name="immediate_view">view</property>
<property name="default_view">view</property>
<property name="view_methods">
<element value="view"/>
<element value="view" />
<element value="standard" />
</property>
<property name="default_view_fallback">False</property>
<property name="add_permission">cmf.AddPortalContent</property>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<object name="collective.cover.content" meta_type="Dexterity FTI"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="collective.cover">

<property name="view_methods" purge="False">
<element value="standard" />
</property>
</object>
19 changes: 19 additions & 0 deletions src/collective/cover/templates/standard.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<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"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="collective.cover">

<body>

<metal:content-core fill-slot="content-core">
<metal:block define-macro="content-core">
<div tal:define="layout nocall:context/@@layout"
tal:replace="structure layout/render_view" />
</metal:block>
</metal:content-core>

</body>
</html>
17 changes: 17 additions & 0 deletions src/collective/cover/tests/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collective.cover.upgrades import update_styles_record_4_5
from collective.cover.upgrades import set_new_default_class_4_5
from collective.cover.upgrades import tinymce_linkable
from collective.cover.upgrades import register_alternate_view
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.registry.interfaces import IRecordAddedEvent
Expand Down Expand Up @@ -205,3 +206,19 @@ def test_tinymce_linkables(self):
tinymce_linkable(self.portal)
linkables = self.tinymce.linkable.split('\n')
self.assertIn(u'collective.cover.content', linkables)

def test_register_alternate_view(self):
# default installation includes alternate view
portal_types = self.portal['portal_types']
view_methods = portal_types['collective.cover.content'].view_methods
self.assertIn(u'standard', view_methods)

# remove alternate view to simulate version 4 state
portal_types['collective.cover.content'].view_methods = ('view',)
view_methods = portal_types['collective.cover.content'].view_methods
self.assertNotIn(u'standard', view_methods)

# and now run the upgrade step to validate the update
register_alternate_view(self.portal)
view_methods = portal_types['collective.cover.content'].view_methods
self.assertIn(u'standard', view_methods)
59 changes: 59 additions & 0 deletions src/collective/cover/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-

from collective.cover.testing import INTEGRATION_TESTING
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from zope.component import getMultiAdapter

import unittest


class BrowserViewsTestCase(unittest.TestCase):

layer = INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']

setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.portal.invokeFactory('Folder', 'test-folder')
setRoles(self.portal, TEST_USER_ID, ['Member'])
self.folder = self.portal['test-folder']
self.folder.invokeFactory(
'collective.cover.content',
'c1',
title='Front page',
description='Should I see this?',
)
self.c1 = self.folder['c1']

def test_default_view_registration(self):
portal_types = self.portal['portal_types']
default_view = portal_types['collective.cover.content'].default_view
view_methods = portal_types['collective.cover.content'].view_methods
self.assertEqual(default_view, u'view')
self.assertIn(u'view', view_methods)

# FIXME
@unittest.expectedFailure
def test_default_view_render(self):
view = getMultiAdapter((self.c1, self.request), name='view')
rendered_html = view.render()
# default view should not show title, description or viewlets
self.assertNotIn(rendered_html, 'Front page')
self.assertNotIn(rendered_html, 'Should I see this?')

def test_alternate_view_registration(self):
portal_types = self.portal['portal_types']
view_methods = portal_types['collective.cover.content'].view_methods
self.assertIn(u'standard', view_methods)

# FIXME
@unittest.expectedFailure
def test_alternate_view_render(self):
view = getMultiAdapter((self.c1, self.request), name='standard')
rendered_html = view.render()
# default view should show title, description and viewlets
self.assertIn(rendered_html, 'Front page')
self.assertIn(rendered_html, 'Should I see this?')
14 changes: 14 additions & 0 deletions src/collective/cover/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,17 @@ def tinymce_linkable(context, logger=None):
setup = getToolByName(context, 'portal_setup')
setup.runImportStepFromProfile(profile, 'tinymce_settings')
logger.info("'linkable' property updated in TinyMCE settings")


def register_alternate_view(context, logger=None):
"""Add alternate view for collective.cover.content objects.
See: https://github.com/collective/collective.cover/issues/271
"""

if logger is None:
logger = logging.getLogger(PROJECTNAME)

profile = 'profile-collective.cover:upgrade_4_to_5'
setup = getToolByName(context, 'portal_setup')
setup.runImportStepFromProfile(profile, 'typeinfo')
logger.info("Alternate view for collective.cover.content objects added.")
2 changes: 2 additions & 0 deletions travis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# required in Plone 4.2
collective.js.jqueryui = 1.8.16.9
plone.app.jquerytools = 1.5.6
# Travis CI runs with Firefox 19.0
selenium = 2.32.0

[buildout]
extends =
Expand Down
1 change: 0 additions & 1 deletion versions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ plone.app.robotframework = 0.6.4
robotframework = 2.8.1
robotframework-selenium2library = 1.4.0
robotsuite = 1.4.0
selenium = 2.34.0