def __init__(self, id, **kw): self._topictype = aq_base(kw['topic']) kw['actions'] = self._actions kw['aliases'] = self._aliases FactoryTypeInformation.__init__(self, id, **kw) self.product = '' self.factory = 'ksiktforum.documentbank' self.content_meta_type = 'Topic' self.content_icon = 'topic_icon.png' self.immediate_view = 'documentbank_view' self.title = 'documentbank' self.description = 'Specialized topic that can organize content under self chose labels'
def __init__(self, id, **kw): self._topictype = aq_base(kw['topic']) kw['actions'] = self._actions kw['aliases'] = self._aliases FactoryTypeInformation.__init__(self, id, **kw) self.product = '' self.factory = 'ksiktforum.workarea' self.content_meta_type = 'Topic' self.content_icon = 'topic_icon.png' self.immediate_view = 'workarea_view' self.title = 'workarea' self.description = 'Specialized topic that handles access control'
def manage_changeProperties(self, **kw): """Overwrite change properties to verify that default_view is in the method list """ FactoryTypeInformation.manage_changeProperties(self, **kw) default_view = self.default_view view_methods = self.view_methods if not default_view: # TODO: use view action self.default_view = default_view = self.immediate_view if not view_methods: self.view_methods = view_methods = (default_view,) if default_view and default_view not in view_methods: raise ValueError, "%s not in %s" % (default_view, view_methods)
def manage_changeProperties(self, **kw): """Overwrite change properties to verify that default_view is in the method list """ FactoryTypeInformation.manage_changeProperties(self, **kw) default_view = self.default_view view_methods = self.view_methods if not default_view: # TODO: use view action self.default_view = default_view = self.immediate_view if not view_methods: self.view_methods = view_methods = (default_view, ) if default_view and default_view not in view_methods: raise ValueError("%s not in %s" % (default_view, view_methods))
def queryMethodID(self, alias, default=None, context=None): """ Query method ID by alias. Use "(dynamic view)" as the alias target to look up as per defaultView() Use "(selected layout)" as the alias target to look up as per getViewMethod() """ methodTarget = FactoryTypeInformation.queryMethodID(self, alias, default=default, context=context) if not isinstance(methodTarget, basestring): # nothing to do, method_id is probably None return methodTarget if context is None or default == '': # the edit zpts like typesAliases don't apply a context and set the # default to ''. We do not want to resolve (dynamic view) for these # methods. return methodTarget # Our two special targets: if methodTarget.lower() == "(dynamic view)": methodTarget = self.defaultView(context) if methodTarget.lower() == "(selected layout)": fallback = self.default_view_fallback methodTarget = self.getViewMethod(context, check_exists=fallback) return methodTarget
def setupTypes(self, p, initial_types=factory_type_information): tool = getToolByName(p, 'portal_types', None) if tool is None: return for t in initial_types: fti = FactoryTypeInformation(**t) tool._setObject(t['id'], fti)
def queryMethodID(self, alias, default=None, context=None): # Query method ID by alias. # Use "(dynamic view)" as the alias target to look up as per # defaultView() # Use "(selected layout)" as the alias target to look up as per # getViewMethod() methodTarget = FactoryTypeInformation.queryMethodID(self, alias, default=default, context=context) if not isinstance(methodTarget, str): # nothing to do, method_id is probably None return methodTarget if context is None or default == '': # the edit zpts like typesAliases don't apply a context and set the # default to ''. We do not want to resolve (dynamic view) for these # methods. return methodTarget # Our two special targets: if methodTarget.lower() == "(dynamic view)": methodTarget = self.defaultView(context) if methodTarget.lower() == "(selected layout)": fallback = self.default_view_fallback methodTarget = self.getViewMethod(context, check_exists=fallback) return methodTarget
def _initSite(self, foo=0): site = Folder(id='site').__of__(self.app) ttool = TypesTool() getSiteManager().registerUtility(ttool, ITypesTool) if foo == 1: fti = _TI_LIST[0].copy() ttool._setObject(fti['id'], FactoryTypeInformation(**fti)) sti = _TI_LIST[1].copy() ttool._setObject(sti['id'], ScriptableTypeInformation(**sti)) elif foo == 2: fti = _TI_LIST_WITH_FILENAME[0].copy() ttool._setObject(fti['id'], FactoryTypeInformation(**fti)) sti = _TI_LIST_WITH_FILENAME[1].copy() ttool._setObject(sti['id'], ScriptableTypeInformation(**sti)) return site, ttool
def _initSite(self, foo=0): self.root.site = Folder(id='site') site = self.root.site ttool = site.portal_types = TypesTool() if foo == 1: fti = _TI_LIST[0].copy() ttool._setObject(fti['id'], FactoryTypeInformation(**fti)) sti = _TI_LIST[1].copy() ttool._setObject(sti['id'], ScriptableTypeInformation(**sti)) elif foo == 2: fti = _TI_LIST_WITH_FILENAME[0].copy() ttool._setObject(fti['id'], FactoryTypeInformation(**fti)) sti = _TI_LIST_WITH_FILENAME[1].copy() ttool._setObject(sti['id'], ScriptableTypeInformation(**sti)) return site
def setUp(self): from Products.CMFCore.TypesTool import FactoryTypeInformation PlacelessSetup.setUp(self) zcml.load_config('meta.zcml', Products.Five) zcml.load_config('configure.zcml', Products.CMFCore.exportimport) self._obj = FactoryTypeInformation('foo_fti') self._XML = _FTI_XML
def setUp(self): import Products.CMFCore from Products.CMFCore.TypesTool import FactoryTypeInformation BodyAdapterTestCase.setUp(self) zcml.load_config('configure.zcml', Products.CMFCore) self._obj = FactoryTypeInformation('foo_fti') self._BODY = _FTI_BODY
def getTypeInfo(self, id): info = [x for x in self._type_infos if x['id'] == id] if len(info) == 0: raise KeyError, id info = info[0] if 'product' in info.keys(): return FactoryTypeInformation(**info) else: return ScriptableTypeInformation(**info)
def test_additive_prop(self): """ This tests the additive property of the import function. When you make local changes, the import function should only add and not replace things """ # We first make some custom Composite Pack modifications self.ct.registerLayout("custom_layout_id", "custom_layout_title", "custom_layout_skin_method") self.ct.registerViewlet("custom_viewlet_id", "custom_viewlet_title", "custom_viewlet_skin_method") viewlet = self.ct.getViewletById("custom_viewlet_id") self.ct.registerViewletForType(viewlet, "custom_composable_id") layout = self.ct.getLayoutById("custom_layout_id") self.ct.registerLayoutForType(layout, "custom_composite_id") typetool = getToolByName(self.ct, 'portal_types') from Products.CMFCore.TypesTool import FactoryTypeInformation fti = FactoryTypeInformation(id="custom_composable_id") typetool._setObject(fti.id, fti) # Now we use Generic Setup to import the default self.gs.runAllImportStepsFromProfile( 'profile-Products.CompositePack:default') # Let's get the Layouts layouts = self.ct.getAllLayouts() layouts_names = [str(l) for l in layouts] layouts_for_custom = self.ct.getRegisteredLayoutsForType( "custom_composite_id") layouts_for_custom_names = [str(lf) for lf in layouts_for_custom] # And let's get the Viewlets viewlets = self.ct.getAllViewlets() viewlets_names = [str(v) for v in viewlets] viewlets_for_custom = self.ct.getRegisteredViewletsForType( "custom_composable_id") viewlets_for_custom_names = [str(lv) for lv in viewlets_for_custom] # Now, let us check if our customization still exists or if the import # replaced it all. self.failUnless('<Layout at custom_layout_id>' in layouts_names, "Custom layout was overwritten at import") self.failUnless('<Viewlet at custom_viewlet_id>' in viewlets_names, "Custom viewlet was overwritten at import") self.failUnless( '<Viewlet at custom_viewlet_id>' in viewlets_for_custom_names, "Custom viewlet for composable overwritten at import") self.failUnless( '<Layout at custom_layout_id>' in layouts_for_custom_names, "Custom layout for composite overwritten at import")
def _constructInstance(self, container, id, *args, **kw): topicmap = kw['topicmap'] = self.portal_topicmaps.getTopicMap() ob = FactoryTypeInformation._constructInstance( self , container , id , *args , **kw ) ob.addType(psis.documentbank) #ob.invokeFactory(id='filearchive', type_name='CMF BTree Folder') #ob.invokeFactory(id='discussion', type_name='CMF BTree Folder') #getattr(ob, 'filearchive').__parent__ = ob #getattr(ob, 'discussion').__parent__ = ob return ob
def _constructInstance(self, container, id, *args, **kw): topicmap = kw['topicmap'] = self.portal_topicmaps.getTopicMap() ob = FactoryTypeInformation._constructInstance( self , container , id , *args , **kw ) ob.addType(psis.workarea) ob.invokeFactory(id='filer', type_name='CMF BTree Folder') ob.invokeFactory(id='diskusjoner', type_name='CMF BTree Folder') getattr(ob, 'filer').__parent__ = ob getattr(ob, 'diskusjoner').__parent__ = ob return ob
def setUp(self): from Products.CMFCore.TypesTool import FactoryTypeInformation BodyAdapterTestCase.setUp(self) self._obj = FactoryTypeInformation('foo_fti') self._BODY = _FTI_BODY
def _populate(self, obj): from Products.CMFCore.TypesTool import FactoryTypeInformation obj._setObject('foo_type', FactoryTypeInformation('foo_type'))
def update_discussion( self, split=string.split ): """ 1. Install (if it isn't there already) a type information object for DiscussionItems, so that they can get actions, etc. Erase the "(default)" workflow bound to it, to prevent showing the "Retract" options, etc. 2. Update all DiscussionItems to use the new marking for 'in_reply_to': - Items which are replies to the containing content object have None as their 'in_reply_to'; - Items which are replies to sibling items have the sibling's ID as their 'in_reply_to'. The representation we are converting from was: - Items which are replies to the containing content object have the portal-relative pathstring of the content object as their 'in_reply_to'; - Items which are replies to sibling items have the absolute path of the sibling as their 'in_reply_to'. """ log = [] a = log.append types_tool = self.portal_types if not getattr( types_tool, 'Discussion Item', None ): fti = FactoryTypeInformation(**DiscussionItem.factory_type_information[0]) types_tool._setObject( 'Discussion Item', fti ) a( 'Added type object for DiscussionItem' ) workflow_tool = self.portal_workflow workflow_tool.setChainForPortalTypes( ( 'Discussion Item', ), () ) a( 'Erased workflow for DiscussionItem' ) items = self.portal_catalog.searchResults( meta_type='Discussion Item' ) a( 'DiscussionItems updated:' ) for item in items: object = item.getObject() talkback = object.aq_parent path = item.getPath() in_reply_to = object.in_reply_to if in_reply_to is None: # we've been here already continue irt_elements = split( in_reply_to, '/' ) if len( irt_elements ) == 1: if talkback._container.get( irt_elements[0] ): # we've been here already continue if irt_elements[0] == '': # absolute, so we are IRT a sibling sibling_id = irt_elements[ -1 ] if talkback._container.get( sibling_id, None ): in_reply_to = sibling_id else: in_reply_to = None else: in_reply_to = None object.in_reply_to = in_reply_to assert object.inReplyTo() # sanity check object.reindexObject() a( path ) return string.join( log, '\n' )
def setUp(self): BodyAdapterTestCase.setUp(self) self._obj = FactoryTypeInformation('foo_fti') self._BODY = _FTI_BODY
def _makeInstance(self, id, **kw): from Products.CMFCore.TypesTool import FactoryTypeInformation return FactoryTypeInformation(id, **kw)
__roles__ = ( 'FooAdder', ) __allow_access_to_unprotected_subobjects__ = { 'addFoo' : 1 } class DummyTypeInfo(TypeInformation): """ Dummy class of type info object """ meta_type = "Dummy Test Type Info" DummyFTI = FactoryTypeInformation( 'Dummy', meta_type=DummyContent.meta_type, product='CMFDefault', factory='addDocument', actions= ( { 'name' : 'View', 'action' : 'view', 'permissions' : ('View', ) }, { 'name' : 'View2', 'action' : 'view2', 'permissions' : ('View', ) }, { 'name' : 'Edit', 'action' : 'edit', 'permissions' : ('forbidden permission',) } ) ) class DummyFolder( Implicit ): """ Dummy Container for testing """ def __init__( self, fake_product=0, prefix='' ): self._prefix = prefix
def _populate(self, obj): obj._setObject('foo_type', FactoryTypeInformation('foo_type'))
def setUp(self): self._obj = FactoryTypeInformation('foo_fti') self._BODY = _FTI_BODY
def setUp(self): self._obj = FactoryTypeInformation('foo_fti') self._BODY = _FTI_BODY self._trap_warning_output()