Skip to content

Commit

Permalink
added heck to query for fti when adding content
Browse files Browse the repository at this point in the history
  • Loading branch information
kagesenshi committed Dec 26, 2011
1 parent 6828ade commit f641f55
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
*.pyc
*.pyo
*~
*.bak
*.swp
*.egg
*.egg-info
17 changes: 15 additions & 2 deletions collective/localbehavior/vocabulary.py
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,28 @@
from zope.interface import directlyProvides from zope.interface import directlyProvides
from zope.component import getUtilitiesFor, getUtility from zope.component import getUtilitiesFor, getUtility, queryUtility


from zope.schema.interfaces import IVocabularyFactory from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleVocabulary from zope.schema.vocabulary import SimpleVocabulary
from plone.dexterity.interfaces import IDexterityFTI from plone.dexterity.interfaces import IDexterityFTI


from plone.behavior.interfaces import IBehavior from plone.behavior.interfaces import IBehavior
from zope.globalrequest import getRequest


def LocalBehaviorsVocabularyFactory(context): def LocalBehaviorsVocabularyFactory(context):
behaviors = getUtilitiesFor(IBehavior) behaviors = getUtilitiesFor(IBehavior)
fti = getUtility(IDexterityFTI, name=context.portal_type) fti = queryUtility(IDexterityFTI, name=context.portal_type)
if fti is None:
# hack to get fti when adding content
req = getRequest()
path = req.physicalPathFromURL(req.getURL())
if not '++add++' in path[-1]:
return SimpleVocabulary.fromItems([])
ft = path[-1].replace('++add++', '')
fti = getattr(context.portal_types, ft, None)
if fti is None:
return SimpleVocabulary.fromItems([])

# query behaviors, exclude the content-level behaviors
items = [ items = [
(reg.title, reg.interface.__identifier__) for ( (reg.title, reg.interface.__identifier__) for (
title, reg) in behaviors if ( title, reg) in behaviors if (
Expand Down

0 comments on commit f641f55

Please sign in to comment.