[Zope] Re: More product writing problems
Tille, Andreas
TilleA@rki.de
Wed, 5 Dec 2001 09:07:30 +0100 (CET)
On Tue, 4 Dec 2001, Seb Bacon wrote:
> Means just want it says: the modules were compiled with a different python
> from the one you're using. Normally shouldn't matter.
>
> > ob.keywords={}
> > for kw in keywords:
> > kw=kw.strip()
>
> You can't iterate over a dictionary. It doesn't have a order, and it is
> made up of key, value pairs. You want
> for kw in keywords.keys():
> # do stuff
> value = keywords[key] # for example
>
> Actually, I think python 2.1 or perhaps 2.2 adds some new methods to
Sorry, I did not described my problem exactly. My problem is perhaps
that I do not know *which* is the correct type of my variable keywords.
(Sorry, I'm a little bit C-centered where I had to declare each variable.)
I think I post my complete method to clarify:
def manage_addMyFolder(self, id, title='',
keywords='', #### not sure if this is correct but
#### it worked so far
createPublic=1,
createSelection=1,
createHome=1,
createUserF=0,
REQUEST=None):
"""Add a new MyFolder object with id *id* and
global keywords *keywords* and author *author*.
If the 'createPublic' and 'createUserF' parameters are set to any true
value, an 'index_html' and a 'UserFolder' objects are created respectively
in the new folder.
You can specify certain keywords which are inserted into each Document inside
this folder.
"""
ob=MyFolder()
ob.id=str(id)
ob.title=title
ob.keywords=keywords #### this works but I want to remove whitespaces
#### and empty lines
# for kw in keywords: #### this does not work :-( see below
# kw=kw.strip()
# if kw != '' :
# ob.keywords = ob.keywords + '\n' + kw
self._setObject(id, ob)
ob=self._getOb(id)
checkPermission=getSecurityManager().checkPermission
if createUserF:
if not checkPermission('Add User MyFolders', ob):
raise 'Unauthorized', (
'You are not authorized to add User MyFolders.'
)
ob.manage_addUserFolder()
if createPublic:
if not checkPermission('Add Documents, Images, and Files', ob):
raise 'Unauthorized', (
'You are not authorized to add DTML Documents.'
)
ob.manage_addDTMLDocument(id='index.htm', title=ob.id+' main frame')
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
The problem obviousely is, that I do not know what Python type is appropriate
to store the *lines* which are obtained in a
<tr valign="top">
<th class="form-optional">Keywords<br>(One per line)</th>
<td><textarea name="keywords:lines" cols="50" rows="10">
</textarea>
</td>
</tr>
textarea and how I should strip the whitespaces and empty lines from it.
a string variable separated by '\n' does not work either as I tested
because if I want to edit them I get:
Error Type: InError
Error Value: Strings are not allowed as input to the in tag.
So the question is: How to strip the whitespace from the keywords correctly.
Thanks for your patience
Andreas.