Skip to content

Commit

Permalink
Vocabulary from parent object
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmahon committed May 13, 2011
1 parent 5c6511d commit 32159ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions collective/dexterity_class/container_for_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class IContainerforEverything(form.Schema):
# and add directives here as necessary.

form.model("models/container_for_everything.xml")

available_fruits = schema.List(title=_(u"Available Fruits"),
default=[],
value_type=schema.TextLine())


# Custom content-type class; objects created for this content type will
Expand Down
5 changes: 3 additions & 2 deletions collective/dexterity_class/everything_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

from collective.dexterity_class import MessageFactory as _

fruit_list = [_(u'Apples'), _(u'Oranges'), _(u'Berries'), _(u'Bananas')]
fruits = SimpleVocabulary.fromValues(fruit_list)

@grok.provider(schema.interfaces.IContextSourceBinder)
def vocabProvider(context):
""" pick up fruit list from parent """

fruit_list = getattr(context.__parent__, 'available_fruits', [])
return SimpleVocabulary.fromValues(fruit_list)

# Interface class; used to define content-type schema.
Expand Down

0 comments on commit 32159ef

Please sign in to comment.