[Zope-CMF] Error trying to add FTI
Thomas Olsen
tol@tanghus.dk
Mon, 22 Apr 2002 23:25:28 +0200
I've had a lot of problems with this too:
in the module define you fti as a tuple of dictionaries:
factory_type_information =3D ({
'id': 'Contact',
'meta_type': 'Contact Object',
'description': 'Contains contacts',
'product': 'MyProduct',
'icon': 'folder_icon.gif',
'factory': 'addContact',
'filter_content_types': 0,
'immediate_view': 'contact_view',
'actions':
(
{
'id': 'view'
,'name': 'View'
,'action': 'contact_view'
,'permissions': (CMFCorePermissions.View,)
,'category': 'object'
},
)
},)
This way you an have fti's for several classes in the same module.
Then in __init__.py:
utils.ContentInit(
'Medzope Content',
content_types =3D ( MedzopeFolder.MedzopeFolder
,MedzopeOrg.MedzopeOrg
,Contact.Contact),
permission =3D ADD_FOLDERS_PERMISSION,
extra_constructors =3D (MedzopeFolder.addMedzopeFolder
,MedzopeOrg.addMedzopeOrg
,Contact.addContact),
fti=3D(MedzopeFolder.factory_type_information
+ MedzopeOrg.factory_type_information
+ Contact.factory_type_information)
).initialize(context)
Notice that you have to add the fti's with a '+' sign.
Having the fti's in a tuple also makes it quite easy to create install=20
scripts:
---[snip]----------------------
from Products.CMFCore.TypesTool import ContentFactoryMetadata
from Products.CMFCore.utils import getToolByName
import MedzopeFolder, MedzopeOrg, Contact
def registerType(self, fti):
"""
Register type defined in fti in the types tool
"""
typestool =3D getToolByName(self, 'portal_types')
if fti['id'] not in typestool.objectIds():
cfm =3D apply(ContentFactoryMetadata, (), fti)
typestool._setObject(fti['id'], cfm)
out.write('Registered %s with the types tool\n' % fti['id'])
else:
out.write('Object "%s" already existed in the types tool\n' %=20
(fti['id']))
def install(self):
"""Register all components with the necessary tools"""
# register the portal types
type_classes =3D (MedzopeFolder, MedzopeOrg, Contact)
for c in type_classes:
t =3D c.factory_type_information
if type(t) =3D=3D type(()): # double check
for fti in t:
registerType(self, fti)
else:
registerType(self, t)
On Monday 22 April 2002 18:18, Jon Edwards wrote:
> I created a product "Medzope" which had a couple of subproducts - all
> worked OK. But now I've added another sub-product (Contact), it doesn't
> seem to be registering itself properly, can someone pleeeeease point ou=
t my
> dumb mistake?
>
> I think the mistake might be in my init.py, where I do the ContentInit =
-
>
> utils.ContentInit(
> 'Medzope Content',
> content_types =3D (MedzopeFolder.MedzopeFolder,
> MedzopeOrg.MedzopeOrg, Contact.Contact),
> permission =3D ADD_FOLDERS_PERMISSION,
> extra_constructors =3D (MedzopeFolder.addMedzopeFolder,
> MedzopeOrg.addMedzopeOrg, Contact.addContact),
> fti=3D(MedzopeFolder.factory_type_information,
> MedzopeOrg.factory_type_information, Contact.factory_type_information)
> ).initialize(context)
>
> Everything seems to initialise without errors, and I can add my new
> "Contact" objects through the ZMI. But "Contact" is not listed in the
> TypesTool, so I tried to add a new Factory-based Type Information, and
> immediately got the following error -
>
> AttributeError
>
> Sorry, a site error occurred.
>
> Traceback (innermost last):
> File C:\Program Files\testzope250\lib\python\ZPublisher\Publish.py, l=
ine
> 150, in publish_module
> File C:\Program Files\testzope250\lib\python\ZPublisher\Publish.py, l=
ine
> 114, in publish
> File C:\Program Files\testzope250\lib\python\Zope\__init__.py, line 1=
58,
> in zpublisher_exception_hook
> (Object: portal_types)
> File C:\Program Files\testzope250\lib\python\ZPublisher\Publish.py, l=
ine
> 98, in publish
> File C:\Program Files\testzope250\lib\python\ZPublisher\mapply.py, li=
ne
> 88, in mapply
> (Object: manage_addFactoryTIForm)
> File C:\Program Files\testzope250\lib\python\ZPublisher\Publish.py, l=
ine
> 39, in call_object
> (Object: manage_addFactoryTIForm)
> File C:\Program
> Files\testzope250\lib\python\Products\CMFCore\TypesTool.py, line 578, i=
n
> manage_addFactoryTIForm
> (Object: portal_types)
> File C:\Program
> Files\testzope250\lib\python\Products\CMFCore\TypesTool.py, line 567, i=
n
> listDefaultTypeInformation
> (Object: portal_types)
> AttributeError: 'tuple' object has no attribute 'get'
>
> Looking at TypesTool, I think it's trying to get the meta_type of the F=
TI?
> But it seems that something in the way I initialised it has caused that=
not
> to be stored, or to be stored wrongly? (I've declared both meta_type an=
d
> portal_type as Contact in Contact.py)
>
> Any clues gratefully accepted!
>
> Cheers, Jon
>
>
>
> _______________________________________________
> Zope-CMF maillist - Zope-CMF@zope.org
> http://lists.zope.org/mailman/listinfo/zope-cmf
>
> See http://www.zope.org/Products/PTK/Tracker for bug reports and featur=
e
> requests
--=20
Regards,
=09Thomas Olsen