[Zope] No question
Wim Bekker
wim@dv-rec.com
Fri, 16 May 2003 14:34:58 +0200
Hi,
I've started this mail because I had a problem. While typing I found my
solution, so basically I don't have any question.
I'm just learning to use Zope with Python and I'm progressing wel. But maybe
someone want to look at this piece of code and can give some suggestions
about it. Is it well-coded python? Can I get the same results in
smarter/better ways?
# file eme_changeScheduled.py
# external Method eme_changeScheduled
# This method is called from a DTML-method that displays a list of several
# selected objects that has the property 'scheduled' and let the user
# change all property values at once.
# This method is invoked from the root.
# REQUEST should have 'foldername' as the name of the subfolder that
# contains the objects
# REQUEST should have 'new_scheduled' that is a list of object names and new
# scheduled values
#
# I'm only able to supply a string for new_scheduled that looks like:
# ('1.1.1','IssueNr001','1.1.1','IssueNr002','1.2.1','IssueNr003') (etc)
import string
def findObject(self,foldername):
"""
find an object with the same name as foldername in object self
"""
result=None
for object in self.objectValues():
tit=object.getId()
if tit==foldername:
result=object
return result
def replaceScheduled(object,n_scheduled):
"""
replace the value of object's property scheduled with n_scheduled
"""
if object.hasProperty('scheduled'):
object._updateProperty('scheduled',n_scheduled)
object.reindex_object()
def listScheduled(self,new_scheduled):
"""
Searches all objects in self that are listed in new_scheduled
as even entries. If found the property scheduled for the object
gets a new value which is the entry just before the object's title.
Also a list with results is generated
"""
Result=[]
Append=Result.append
Alist=list(new_scheduled)
l=len(Alist)
ind=0
while ind<l:
object=findObject(self, Alist[ind+1])
if object:
scheduled=object.getProperty('scheduled')
Append(str(Alist[ind+1])+'='+str(scheduled)+str('->')+str(Alist[ind]))
replaceScheduled(object, Alist[ind])
ind=ind+2
return string.join(Result,'\n')
def eme_changeScheduled(self,REQUEST=None):
"""
change the content of property scheduled for all objects
that are found in the subfolder
"""
fname=REQUEST.get('foldername','')
nscheduled=REQUEST.get('new_scheduled','')
folder=findObject(self,fname)
listScheduled(folder,nscheduled)