Skip to content

Commit

Permalink
Merge pull request #595 from collective/remove-grok-vocab
Browse files Browse the repository at this point in the history
Remove Grok Dependency for Vocabularies.
  • Loading branch information
hvelarde committed Mar 3, 2016
2 parents 0680721 + a5d6ad0 commit 86717bd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ There's a frood who really knows where his towel is.
1.0a13 (unreleased)
^^^^^^^^^^^^^^^^^^^

- Remove Grok dependency for vocabularies.
[l34marr]

- You can now use a collection to populate a carousel tile;
search results without a lead image will be bypassed (fixes `#574`_).
[rodfersou]
Expand Down
1 change: 1 addition & 0 deletions src/collective/cover/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<include file="permissions.zcml" />
<include file="profiles.zcml" />
<include file="subscribers.zcml" />
<include file="vocabularies.zcml" />

<include package=".behaviors" />
<include package=".browser" />
Expand Down
6 changes: 3 additions & 3 deletions src/collective/cover/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ICoverSettings(form.Schema):
required=True,
default=DEFAULT_AVAILABLE_TILES,
value_type=schema.Choice(
vocabulary=u'collective.cover.EnabledTiles'),
vocabulary='collective.cover.EnabledTiles'),
)

searchable_content_types = schema.List(
Expand All @@ -38,7 +38,7 @@ class ICoverSettings(form.Schema):
default=DEFAULT_SEARCHABLE_CONTENT_TYPES,
# we are going to list only the main content types in the widget
value_type=schema.Choice(
vocabulary=u'collective.cover.AvailableContentTypes'),
vocabulary='collective.cover.AvailableContentTypes'),
)

form.widget(styles='z3c.form.browser.textlines.TextLinesFieldWidget')
Expand All @@ -57,7 +57,7 @@ class ICoverSettings(form.Schema):
description=_(u'Choose a grid system'),
required=True,
default=DEFAULT_GRID_SYSTEM,
vocabulary=u'collective.cover.GridSystems',
vocabulary='collective.cover.GridSystems',
)


Expand Down
12 changes: 6 additions & 6 deletions src/collective/cover/tests/test_vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
self.portal = self.layer['portal']

def test_layouts_vocabulary(self):
name = u'collective.cover.AvailableLayouts'
name = 'collective.cover.AvailableLayouts'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)
layouts = vocabulary(self.portal)
Expand All @@ -29,7 +29,7 @@ def test_layouts_vocabulary(self):
self.assertIn(u'Empty layout', layouts)

def test_available_tiles_vocabulary(self):
name = u'collective.cover.AvailableTiles'
name = 'collective.cover.AvailableTiles'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)
tiles = vocabulary(self.portal)
Expand All @@ -45,7 +45,7 @@ def test_available_tiles_vocabulary(self):
self.assertIn(u'collective.cover.richtext', tiles)

def test_enabled_tiles_vocabulary(self):
name = u'collective.cover.EnabledTiles'
name = 'collective.cover.EnabledTiles'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)
tiles = vocabulary(self.portal)
Expand All @@ -67,15 +67,15 @@ def test_enabled_tiles_vocabulary(self):
self.assertNotIn(u'plone.app.texttile', tiles)

def test_available_content_types_vocabulary(self):
name = u'collective.cover.AvailableContentTypes'
name = 'collective.cover.AvailableContentTypes'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)
available_content_types = vocabulary(self.portal)
self.assertTrue(len(available_content_types) > 0)
self.assertNotIn(u'collective.cover.content', available_content_types)

def test_tile_styles_vocabulary(self):
name = u'collective.cover.TileStyles'
name = 'collective.cover.TileStyles'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)
# in the beginning the vocabulary should contain the default styles
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_tile_styles_vocabulary(self):
self.assertEqual(styles.by_value.keys()[0], u'tile-default')

def test_grid_systems(self):
name = u'collective.cover.GridSystems'
name = 'collective.cover.GridSystems'
vocabulary = queryUtility(IVocabularyFactory, name)
self.assertIsNotNone(vocabulary)

Expand Down
32 changes: 7 additions & 25 deletions src/collective/cover/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from collective.cover.controlpanel import ICoverSettings
from collective.cover.interfaces import IGridSystem
from collective.cover.tiles.base import IPersistentCoverTile
from five import grok
from plone.app.vocabularies.types import ReallyUserFriendlyTypesVocabulary
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileType
from zope.component import getUtilitiesFor
from zope.component import getUtility
from zope.component import queryUtility
from zope.interface import implementer
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


@implementer(IVocabularyFactory)
class AvailableLayoutsVocabulary(object):
grok.implements(IVocabularyFactory)

def __call__(self, context):

Expand All @@ -26,12 +26,9 @@ def __call__(self, context):
items = [SimpleTerm(value=i, title=i) for i in sorted(settings.layouts)]
return SimpleVocabulary(items)

grok.global_utility(AvailableLayoutsVocabulary,
name=u'collective.cover.AvailableLayouts')


@implementer(IVocabularyFactory)
class AvailableTilesVocabulary(object):
grok.implements(IVocabularyFactory)

def __call__(self, context):

Expand All @@ -43,26 +40,20 @@ def __call__(self, context):
items = [SimpleTerm(value=i, title=i) for i in tiles]
return SimpleVocabulary(items)

grok.global_utility(AvailableTilesVocabulary,
name=u'collective.cover.AvailableTiles')


@implementer(IVocabularyFactory)
class GridSystemsVocabulary(object):
grok.implements(IVocabularyFactory)

def __call__(self, context):
items = [SimpleTerm(value=name, title=grid.title)
for (name, grid) in getUtilitiesFor(IGridSystem)]
return SimpleVocabulary(items)

grok.global_utility(GridSystemsVocabulary,
name=u'collective.cover.GridSystems')


@implementer(IVocabularyFactory)
class EnabledTilesVocabulary(object):
"""Return a list of tiles ready to work with collective.cover.
"""
grok.implements(IVocabularyFactory)

def _enabled(self, name):
tile_type = queryUtility(ITileType, name)
Expand All @@ -80,31 +71,24 @@ def __call__(self, context):
items.append(SimpleTerm(value=tile, title=tile_type.title))
return SimpleVocabulary(items)

grok.global_utility(EnabledTilesVocabulary,
name=u'collective.cover.EnabledTiles')


@implementer(IVocabularyFactory)
class AvailableContentTypesVocabulary(ReallyUserFriendlyTypesVocabulary):
"""
Inherit from plone.app.vocabularies.ReallyUserFriendlyTypes; and filter
the results. We don't want covers to be listed.
"""
grok.implements(IVocabularyFactory)

def __call__(self, context):
items = super(AvailableContentTypesVocabulary, self).__call__(context)
items = [i for i in items if i.token != 'collective.cover.content']
return SimpleVocabulary(items)


grok.global_utility(AvailableContentTypesVocabulary,
name=u'collective.cover.AvailableContentTypes')


@implementer(IVocabularyFactory)
class TileStylesVocabulary(object):
"""Creates a vocabulary with the available styles stored in the registry.
"""
grok.implements(IVocabularyFactory)

def __call__(self, context):
registry = getUtility(IRegistry)
Expand All @@ -131,5 +115,3 @@ def __call__(self, context):
items.insert(0, SimpleTerm(value=u'tile-default', title='-Default-'))

return SimpleVocabulary(items)

grok.global_utility(TileStylesVocabulary, name=u'collective.cover.TileStyles')
36 changes: 36 additions & 0 deletions src/collective/cover/vocabularies.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<configure
xmlns="http://namespaces.zope.org/zope"
i18n_domain="collective.cover"
>

<utility
name="collective.cover.AvailableLayouts"
factory=".vocabularies.AvailableLayoutsVocabulary"
/>

<utility
name="collective.cover.AvailableTiles"
factory=".vocabularies.AvailableTilesVocabulary"
/>

<utility
name="collective.cover.GridSystems"
factory=".vocabularies.GridSystemsVocabulary"
/>

<utility
name="collective.cover.EnabledTiles"
factory=".vocabularies.EnabledTilesVocabulary"
/>

<utility
name="collective.cover.AvailableContentTypes"
factory=".vocabularies.AvailableContentTypesVocabulary"
/>

<utility
name="collective.cover.TileStyles"
factory=".vocabularies.TileStylesVocabulary"
/>

</configure>

0 comments on commit 86717bd

Please sign in to comment.