Skip to content

Commit

Permalink
Remove Grok Dependency for Vocabularies.
Browse files Browse the repository at this point in the history
  • Loading branch information
l34marr committed Mar 3, 2016
1 parent 0680721 commit bba8a42
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ There's a frood who really knows where his towel is.
- Clean up static files.
[rodfersou]

- Remove Grok dependency for vocabularies.
[l34marr]

1.0a12 (2015-11-16)
^^^^^^^^^^^^^^^^^^^
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: 13 additions & 19 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 implements
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


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

def __call__(self, context):

Expand All @@ -26,12 +26,11 @@ 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')
AvailableLayoutsVocabularyFactory = AvailableLayoutsVocabulary()


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

def __call__(self, context):

Expand All @@ -43,26 +42,24 @@ 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')
AvailableTilesVocabularyFactory = AvailableTilesVocabulary()


class GridSystemsVocabulary(object):
grok.implements(IVocabularyFactory)
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')
GridSystemsVocabularyFactory = GridSystemsVocabulary()


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

def _enabled(self, name):
tile_type = queryUtility(ITileType, name)
Expand All @@ -80,31 +77,28 @@ 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')
EnabledTilesVocabularyFactory = EnabledTilesVocabulary()


class AvailableContentTypesVocabulary(ReallyUserFriendlyTypesVocabulary):
"""
Inherit from plone.app.vocabularies.ReallyUserFriendlyTypes; and filter
the results. We don't want covers to be listed.
"""
grok.implements(IVocabularyFactory)
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')
AvailableContentTypesVocabularyFactory = AvailableContentTypesVocabulary()


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

def __call__(self, context):
registry = getUtility(IRegistry)
Expand Down Expand Up @@ -132,4 +126,4 @@ def __call__(self, context):

return SimpleVocabulary(items)

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

<utility
name="collective.cover.AvailableLayouts"
component=".vocabularies.AvailableLayoutsVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="collective.cover.AvailableTiles"
component=".vocabularies.AvailableTilesVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="collective.cover.GridSystems"
component=".vocabularies.GridSystemsVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="collective.cover.EnabledTiles"
component=".vocabularies.EnabledTilesVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="collective.cover.AvailableContentTypes"
component=".vocabularies.AvailableContentTypesVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

<utility
name="collective.cover.TileStyles"
component=".vocabularies.TileStylesVocabularyFactory"
provides="zope.schema.interfaces.IVocabularyFactory"
/>

</configure>

0 comments on commit bba8a42

Please sign in to comment.