Skip to content

Commit

Permalink
Update <utility /> Directive for Configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
l34marr committed Mar 3, 2016
1 parent bba8a42 commit bd91876
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
6 changes: 3 additions & 3 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 All @@ -32,9 +35,6 @@ 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
26 changes: 7 additions & 19 deletions src/collective/cover/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from zope.component import getUtilitiesFor
from zope.component import getUtility
from zope.component import queryUtility
from zope.interface import implements
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):
implements(IVocabularyFactory)

def __call__(self, context):

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

AvailableLayoutsVocabularyFactory = AvailableLayoutsVocabulary()


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

def __call__(self, context):

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

AvailableTilesVocabularyFactory = AvailableTilesVocabulary()


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

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

GridSystemsVocabularyFactory = GridSystemsVocabulary()


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

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

EnabledTilesVocabularyFactory = EnabledTilesVocabulary()


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

AvailableContentTypesVocabularyFactory = AvailableContentTypesVocabulary()


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

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

return SimpleVocabulary(items)

TileStylesVocabularyFactory = TileStylesVocabulary()
19 changes: 6 additions & 13 deletions src/collective/cover/vocabularies.zcml
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
<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"
factory=".vocabularies.AvailableLayoutsVocabulary"
/>

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

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

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

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

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

</configure>

0 comments on commit bd91876

Please sign in to comment.