Skip to content

Commit

Permalink
Add option to select content type to use glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Aug 13, 2015
1 parent 1064682 commit 084d714
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/collective/glossary/config.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# -*- coding: utf-8 -*-
PROJECTNAME = 'collective.glossary'

# by default, all standard content types will be searchable
DEFAULT_ENABLED_CONTENT_TYPES = [
'Document',
'News Item'
]
1 change: 1 addition & 0 deletions src/collective/glossary/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<include package=".browser" />

<include file="profiles.zcml" />
<include file="vocabulary.zcml" />

</configure>
11 changes: 11 additions & 0 deletions src/collective/glossary/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from collective.glossary import _
from collective.glossary.config import DEFAULT_ENABLED_CONTENT_TYPES
from plone.directives import form
from plone.namedfile.field import NamedBlobImage
from zope import schema
Expand All @@ -21,6 +22,16 @@ class IGlossarySettings(form.Schema):
default=True,
)

enabled_content_types = schema.List(
title=_(u'Enabled Content Types'),
description=_(u'Only objects of these content types will apply the glossary'),
required=False,
default=DEFAULT_ENABLED_CONTENT_TYPES,
# we are going to list only the main content types in the widget
value_type=schema.Choice(
vocabulary=u'collective.glossary.AvailableContentTypes'),
)


class IGlossary(form.Schema):

Expand Down
18 changes: 18 additions & 0 deletions src/collective/glossary/vocabulary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from plone.app.vocabularies.types import ReallyUserFriendlyTypesVocabulary
from zope.schema.vocabulary import SimpleVocabulary


class AvailableContentTypesVocabulary(ReallyUserFriendlyTypesVocabulary):
"""
Inherit from plone.app.vocabularies.ReallyUserFriendlyTypes; and filter
the results. We don't want glossary to be listed.
"""

def __call__(self, context):
items = super(AvailableContentTypesVocabulary, self).__call__(context)
items = [i for i in items if i.token not in ('Glossary', 'Term')]
return SimpleVocabulary(items)


availableContentTypesVocabulary = AvailableContentTypesVocabulary()
9 changes: 9 additions & 0 deletions src/collective/glossary/vocabulary.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<configure xmlns="http://namespaces.zope.org/zope">

<utility
provides="zope.schema.interfaces.IVocabularyFactory"
component=".vocabulary.availableContentTypesVocabulary"
name="collective.glossary.AvailableContentTypes"
/>

</configure>

0 comments on commit 084d714

Please sign in to comment.