[Zope-CMF] comprehensible ids
seb bacon
seb@jamkit.com
Thu, 14 Jun 2001 10:34:12 +0100
When using the CMF / zope in 'real-world' situations, I always find
people don't really get the zope id thing. They want to put spaces in
it, and they don't see why they have to give an object an id and a
title. My solution is the following additions to PortalFolder, which
allow users to type anything they want in the id box. This becomes
the title and a munged version becomes the id. Less typing, a simpler
process and more intuitive. At least that's what I think :-) I've
been using this for a while; I wanted to get feedback on it as a
policy.
cheers,
seb
--------
import re
def cookId(self, title):
"make a Zope friendly id out of a title"
rgx = re.compile(r'(^_|[^a-zA-Z0-9-_~\,\.])')
cooked = re.sub(rgx,"",str(title))
return cooked
security.declareProtected(AddPortalContent, 'invokeFactory')
def invokeFactory( self
, type_name
, id
, RESPONSE=None
, *args
, **kw
):
'''
Invokes the portal_types tool.
'''
title = id
id = self.cookId(title)
kw['title'] = title
pt = getToolByName( self, 'portal_types' )
apply( pt.constructContent
, (type_name, self, id, RESPONSE) + args
, kw
)