Permalink
Browse files

added heck to query for fti when adding content

  • Loading branch information...
1 parent 6828ade commit f641f55e9fa9728d4ad08ae43c6ff211eea7df40 @kagesenshi kagesenshi committed Dec 26, 2011
Showing with 22 additions and 2 deletions.
  1. +7 −0 .gitignore
  2. +15 −2 collective/localbehavior/vocabulary.py
View
7 .gitignore
@@ -0,0 +1,7 @@
+*.pyc
+*.pyo
+*~
+*.bak
+*.swp
+*.egg
+*.egg-info
View
17 collective/localbehavior/vocabulary.py
@@ -1,15 +1,28 @@
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.vocabulary import SimpleVocabulary
from plone.dexterity.interfaces import IDexterityFTI
from plone.behavior.interfaces import IBehavior
+from zope.globalrequest import getRequest
def LocalBehaviorsVocabularyFactory(context):
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 = [
(reg.title, reg.interface.__identifier__) for (
title, reg) in behaviors if (

0 comments on commit f641f55

Please sign in to comment.