RE: [Zope] ZClasses meet PythonScripts, sample request

2001-01-16 Thread Max Møller Rasmussen

From: Timothy Wilson [mailto:[EMAIL PROTECTED]]

 You have id as a form variable.  You will be disappointed by its
 behavior.

Care to elaborate on the problems with using id as a form variable.

You can be easily bitten by acquisition on this.

If you call a dtml-method that wants to use your "id" variable from the form
and you do: dtml-var id it will return the id of the zClass that the
method is in. If you use the form from a dtml-document you will get the id
of that. Under no circumstances will you get the variable from the form.

To get the id from the form you will have to use this idiom:

dtml-var "REQUEST['id']"

or

dtml-with REQUEST
dtml-var id
/dtml-with

Regards Max M

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Jim Washington

Hi, Tim

You do not need to mess with the Python Script bindings.  It looks like
you are trying to get URL:

www.isd197.k12.mn.us/hr/jobs/postings/1234/editJobAction(REQUEST)

Which of course does not exist.  I would change your form action="..
line to 

form action="editJobAction" method="post"

assuming the DTML Method that has the form is called editJobAction. 
Don't worry about passing REQUEST there; Zope takes care of that.

-- Jim Washington

Timothy Wilson wrote:
 
 This seems to almost work. :-)
 
 On Sun, 14 Jan 2001, Jim Washington wrote:
 
  !dtml-var standard_html_header
 
  !dtml-if "REQUEST.form.has_key('editCD')"
  !  dtml-call "manage_changeCDProperties(REQUEST)"
  !  pfont color="red"Your changes have been saved/font/p
  !/dtml-if
 
  !form action="replace_this_with_id_of_this_method"
   table border="0"
 
   trthTitle/th
tdinput type="text" name="title" value="dtml-var title"/td
   /tr
 
   trthArtist/th
 tdinput type="text" name="artist" value="dtml-var artist"/td
   /tr
 
   trtd
  ! input type="submit" name="editCD" value=" Submit Edits "
   /td/tr
   /table
   /form
  !dtml-var standard_html_footer
 
 That's quite clever. I wouldn't have thought of doing it that way.
 
 After translating the CD example to my own ZClass, I get the following error
 after hitting "Submit Edits" on the edit form:
 
 h2Zope Error/h2
 pZope has encountered an error while publishing this resource.
   /p
 pstrongResource not found/strong/p
 Sorry, the requested Zope resource does not exist.pCheck the URL and try
 again.p
 !--
 http://www.isd197.k12.mn.us/hr/jobs/postings/1234/editJobAction%28REQUEST%29
 --
 
 and the traceback:
 
 Traceback (innermost last):
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 222, in
 publish_module
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 187, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/Zope/__init__.py, line 221, in
 zpublisher_exception_hook
 (Object: Traversable)
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 162, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/BaseRequest.py, line 369,
 in traverse
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/HTTPResponse.py, line
 528, in notFoundError
 NotFound: (see above)
 
 It looks like REQUEST isn't getting passed correctly. I've got REQUEST
 listed as a parameter for my PythonScript. I don't need to mess with
 bindings do I?

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Timothy Wilson

Jim (or anyone else who's feeling charitable this morning),

Thanks for all your help. I really appreciate it. I wonder if you'd have
time to look one more time at the two methods I've got that aren't
working. I've included the actual code for my job posting product. Perhaps
someone will find it instructive. I have a feeling that the remaining
problem is not directly related to the processing of the form by the
PythonScript. I also included the traceback at the end of this message.

Here are the two methods. I have a table that displays the currently
available jobs and displays two little icons which call the edit or delete
methods on the corresponding instance of the 'Job Posting' class. The edit
icon links to the 'editJobForm' method which in turn calls the
'editFormAction' method that actually processing the change.

--
editJobForm
-

dtml-var standard_html_header

h2Edit a Job Board Entry/h2
pThis form allows you to make changes to current postings on the online
job board. You don't needed to fill in every 
field on the form. Click on the "Submit Edits" button at the bottom of the
screen to save your changes to the database./p

dtml-if "REQUEST.form.has_key('editJob')"
dtml-call "editFormAction(REQUEST)"
pfont color="red"Your changes have been saved/font/p
/dtml-if

form action="editJobForm"
table border="0"

trthNotes/th
tdtextarea name="notes:text" rows="10" cols="60" wrap="virtual"dtml-var
notes/textarea/td
/tr
trthJob ID/th
tdinput type="text" name="id" size="20" value="dtml-var id"/td
/tr
trthOrganization/th
tdinput type="text" name="organization" size="60" value="dtml-var
org_name"/td
/tr
trthPosition/th
tdinput type="text" name="position" size="60" value="dtml-var
name"/td
/tr
trthDescription/th
tdtextarea
name="description:text" rows="10" cols="60" wrap="virtual"dtml-var
description/textarea/td
/tr
trthPay Offered/th
tdinput type="text" name="pay" size="60" value="dtml-var pay"/td
/tr
trthLine of Authority/th
tdinput type="text" name="loa" size="60" value="dtml-var loa"/td
/tr
trthFunction/th
tdtextarea
name="function:text" rows="4" cols="60" wrap="virtual"dtml-var
function/textarea/td
/tr
trthQualifications/th
tdtextarea
name="qualifications:text" rows="8" cols="60" wrap="virtual"dtml-var
qualifications/textarea/td
/tr
tr
td colspan=2
pTo create a bullet list of "duties," type each one in the box below and
press the "ENTER" key 
between each item in the list./p
/td
/tr
trthDuties/th
dtml-if duties
tdtextarea name="duties:list" rows="10" cols="60" wrap="virtual"dtml-in
dutiesdtml-let item=sequence-itemdtml-if item
dtml-var item
/dtml-if/dtml-let/dtml-in/textarea/td
dtml-else
tdtextarea
name="duties:list" rows="10" cols="60" wrap="virtual"/textarea/td
/dtml-if
/tr
trthOffer Expires/th
tdinput type="text" name="expires" size="20" value="dtml-var
offer_expires fmt="%m/%d/%Y""/td
/tr
tr
td colspan=2pEnter the date that the job was officially posted./p/td
/tr
trthPosted Date/th
tdinput type="text" name="posted" size="20" value="dtml-var date_posted
fmt="%m/%d/%Y""/td
/tr
tr
tdnbsp;/td
td
input type="submit" name="editJob" value=" Submit Edits "
/form
form action="admin_html"
input type="submit" value=" Cancel "
/form
/td
/tr
/table

dtml-var standard_html_footer

-
editFormAction (with REQUEST as a parameter)
-

container.propertysheets['job_info'].manage_changeProperties(REQUEST)


The error I get is:

 Error Type: TypeError
Error Value: sequence index must be integer

Traceback:

Traceback (innermost last):
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 222, in
publish_module
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 187, in
publish
  File /var/lib/zope/2.3.0a2/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
(Object: Traversable)
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 171, in
publish
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/mapply.py, line 160, in
mapply
(Object: editJobForm)
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 112, in
call_object
(Object: editJobForm)
  File /var/lib/zope/2.3.0a2/lib/python/OFS/DTMLMethod.py, line 189, in
__call__
(Object: editJobForm)
  File /var/lib/zope/2.3.0a2/lib/python/DocumentTemplate/DT_String.py, line
538, in __call__
(Object: editJobForm)
  File /var/lib/zope/2.3.0a2/lib/python/DocumentTemplate/DT_Util.py, line
336, in eval
(Object: editFormAction(REQUEST))
(Info: REQUEST)
  File lt;stringgt;, line 0, in ?
  File /var/lib/zope/2.3.0a2/lib/python/Shared/DC/Scripts/Bindings.py, line
325, in __call__
(Object: editFormAction)
  File /var/lib/zope/2.3.0a2/lib/python/Shared/DC/Scripts/Bindings.py, line
354, in _bindAndExec
(Object: editFormAction)
  File
/var/lib/zope/2.3.0a2/lib/python/Products/PythonScripts/PythonScript.py,
line 321, in _exec
(Object: editFormAction)
(Info: ({'script': lt;PythonScript instance at 8826790gt;,

Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Jim Washington

Hi, Tim

I have it.
The Python Script I sent you:

container.propertysheets['job_info'].manage_changeProperties(REQUEST)

needs to be rewritten:

container.propertysheets.job_info.manage_changeProperties(REQUEST)

Perhaps someone could explain why the first does not work.

One point about your form:

You have id as a form variable.  You will be disappointed by its
behavior.

Regards,

-- Jim Washington

Timothy Wilson wrote:
 
 Jim (or anyone else who's feeling charitable this morning),
 
 Thanks for all your help. I really appreciate it. I wonder if you'd have
 time to look one more time at the two methods I've got that aren't
 working. I've included the actual code for my job posting product. Perhaps
 someone will find it instructive. I have a feeling that the remaining
 problem is not directly related to the processing of the form by the
 PythonScript. I also included the traceback at the end of this message.
 
 Here are the two methods. I have a table that displays the currently
 available jobs and displays two little icons which call the edit or delete
 methods on the corresponding instance of the 'Job Posting' class. The edit
 icon links to the 'editJobForm' method which in turn calls the
 'editFormAction' method that actually processing the change.
 
 --
 editJobForm
 -
 
 dtml-var standard_html_header
 
 h2Edit a Job Board Entry/h2
 pThis form allows you to make changes to current postings on the online
 job board. You don't needed to fill in every
 field on the form. Click on the "Submit Edits" button at the bottom of the
 screen to save your changes to the database./p
 
 dtml-if "REQUEST.form.has_key('editJob')"
 dtml-call "editFormAction(REQUEST)"
 pfont color="red"Your changes have been saved/font/p
 /dtml-if
 
 form action="editJobForm"
 table border="0"
 
 trthNotes/th
 tdtextarea name="notes:text" rows="10" cols="60" wrap="virtual"dtml-var
 notes/textarea/td
 /tr
 trthJob ID/th
 tdinput type="text" name="id" size="20" value="dtml-var id"/td
 /tr
 trthOrganization/th
 tdinput type="text" name="organization" size="60" value="dtml-var
 org_name"/td
 /tr
 trthPosition/th
 tdinput type="text" name="position" size="60" value="dtml-var
 name"/td
 /tr
 trthDescription/th
 tdtextarea
 name="description:text" rows="10" cols="60" wrap="virtual"dtml-var
 description/textarea/td
 /tr
 trthPay Offered/th
 tdinput type="text" name="pay" size="60" value="dtml-var pay"/td
 /tr
 trthLine of Authority/th
 tdinput type="text" name="loa" size="60" value="dtml-var loa"/td
 /tr
 trthFunction/th
 tdtextarea
 name="function:text" rows="4" cols="60" wrap="virtual"dtml-var
 function/textarea/td
 /tr
 trthQualifications/th
 tdtextarea
 name="qualifications:text" rows="8" cols="60" wrap="virtual"dtml-var
 qualifications/textarea/td
 /tr
 tr
 td colspan=2
 pTo create a bullet list of "duties," type each one in the box below and
 press the "ENTER" key
 between each item in the list./p
 /td
 /tr
 trthDuties/th
 dtml-if duties
 tdtextarea name="duties:list" rows="10" cols="60" wrap="virtual"dtml-in
 dutiesdtml-let item=sequence-itemdtml-if item
 dtml-var item
 /dtml-if/dtml-let/dtml-in/textarea/td
 dtml-else
 tdtextarea
 name="duties:list" rows="10" cols="60" wrap="virtual"/textarea/td
 /dtml-if
 /tr
 trthOffer Expires/th
 tdinput type="text" name="expires" size="20" value="dtml-var
 offer_expires fmt="%m/%d/%Y""/td
 /tr
 tr
 td colspan=2pEnter the date that the job was officially posted./p/td
 /tr
 trthPosted Date/th
 tdinput type="text" name="posted" size="20" value="dtml-var date_posted
 fmt="%m/%d/%Y""/td
 /tr
 tr
 tdnbsp;/td
 td
 input type="submit" name="editJob" value=" Submit Edits "
 /form
 form action="admin_html"
 input type="submit" value=" Cancel "
 /form
 /td
 /tr
 /table
 
 dtml-var standard_html_footer
 
 -
 editFormAction (with REQUEST as a parameter)
 -
 
 container.propertysheets['job_info'].manage_changeProperties(REQUEST)
 
 The error I get is:
 
  Error Type: TypeError
 Error Value: sequence index must be integer
 
 Traceback:
 
 Traceback (innermost last):
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 222, in
 publish_module
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 187, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/Zope/__init__.py, line 221, in
 zpublisher_exception_hook
 (Object: Traversable)
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 171, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/mapply.py, line 160, in
 mapply
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 112, in
 call_object
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/OFS/DTMLMethod.py, line 189, in
 __call__
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/DocumentTemplate/DT_String.py, line
 538, in __call__
 (Object: editJobForm)
   File 

Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Timothy Wilson

On Mon, 15 Jan 2001, Jim Washington wrote:

 One point about your form:
 
 You have id as a form variable.  You will be disappointed by its
 behavior.

Thanks Jim.

Care to elaborate on the problems with using id as a form variable.

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Jim Washington

Hi, Tim

What is the name of the propertysheet in your ZClass that these values
are on?  Is it 'job_info'?

Where is the editFormAction Python Script? It should be in your ZClass's
/methods.  If you are instead acquiring it from a Folder somewhere, you
will need to use 'context' instead of 'container' inside the Python
Script.

-- Jim Washington


Timothy Wilson wrote:
 
 On Mon, 15 Jan 2001, Jim Washington wrote:
 
  I have it.
  The Python Script I sent you:
 
  container.propertysheets['job_info'].manage_changeProperties(REQUEST)
 
  needs to be rewritten:
 
  container.propertysheets.job_info.manage_changeProperties(REQUEST)
 
 Hey Jim,
 
 I'm getting closer. Now I get the following error and traceback:
 
  Error Type: AttributeError
 Error Value: job_info
 
 Traceback (innermost last):
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 222, in
 publish_module
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 187, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/Zope/__init__.py, line 221, in
 zpublisher_exception_hook
 (Object: Traversable)
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 171, in
 publish
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/mapply.py, line 160, in
 mapply
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 112, in
 call_object
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/OFS/DTMLMethod.py, line 189, in
 __call__
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/DocumentTemplate/DT_String.py, line
 538, in __call__
 (Object: editJobForm)
   File /var/lib/zope/2.3.0a2/lib/python/DocumentTemplate/DT_Util.py, line
 336, in eval
 (Object: editFormAction(REQUEST))
 (Info: REQUEST)
   File lt;stringgt;, line 0, in ?
   File /var/lib/zope/2.3.0a2/lib/python/Shared/DC/Scripts/Bindings.py, line
 325, in __call__
 (Object: editFormAction)
   File /var/lib/zope/2.3.0a2/lib/python/Shared/DC/Scripts/Bindings.py, line
 354, in _bindAndExec
 (Object: editFormAction)
   File
 /var/lib/zope/2.3.0a2/lib/python/Products/PythonScripts/PythonScript.py,
 line 321, in _exec
 (Object: editFormAction)
 (Info: ({'script': lt;PythonScript instance at 873fbd8gt;,
 'context': lt;JobPosting instance at 86b7dc0gt;, 'container': lt;Folder
 instance at 87225f0gt;, 'traverse_subpath': []},
 (lt;h3gt;formlt;/h3gt;lt;tablegt;lt;tr
 valign=quot;topquot; 
align=quot;leftquot;gt;lt;thgt;postedlt;/thgt;lt;tdgt;'01/15/2001'lt;/tdgt;lt;/trgt;lt;tr
 valign=quot;topquot; 
align=quot;leftquot;gt;lt;thgt;dutieslt;/thgt;lt;tdgt;['asdfasdf\015\012']lt;/tdgt;lt;/trgt;lt;tr
 valign=quot;topquot; 
align=quot;leftquot;gt;lt;thgt;positionlt;/thgt;lt;tdgt;'asdfadsfasd'lt;/tdgt;lt;/trgt;lt;tr
 
 -- again snipping the rest of REQUEST --
 
   File Python Script, line 2, in editFormAction
   File /var/lib/zope/2.3.0a2/lib/python/Products/PythonScripts/Guarded.py,
 line 272, in __getattr__
   File /var/lib/zope/2.3.0a2/lib/python/Products/PythonScripts/Guarded.py,
 line 143, in __careful_getattr__
 (Object: Traversable)
 AttributeError: (see above)
 
 Any ideas?

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Timothy Wilson

On Mon, 15 Jan 2001, Jim Washington wrote:

 What is the name of the propertysheet in your ZClass that these values
 are on?  Is it 'job_info'?

Yes.

 Where is the editFormAction Python Script? It should be in your ZClass's
 /methods.  If you are instead acquiring it from a Folder somewhere, you
 will need to use 'context' instead of 'container' inside the Python
 Script.

I had them originally in the ZClass's /methods, but moved them out.

That brings up another good question that I haven't really seen
addressed. Hopefully others are still reading this thread. :-)

When is it proper to make your methods part of the ZClass itself and when
should I put them out in a folder somewhere to be acquired? I've seen it
done both ways in various products, but the difference between the two
approaches has never been completely clear to me.

Can anyone suggest a "rule-of-thumb" here?

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-15 Thread Jim Washington

Timothy Wilson wrote:
 
 On Mon, 15 Jan 2001, Jim Washington wrote:
 
  Where is the editFormAction Python Script? It should be in your ZClass's
  /methods.  If you are instead acquiring it from a Folder somewhere, you
  will need to use 'context' instead of 'container' inside the Python
  Script.
 
 I'm not getting any errors now that I've changed the editFormAction to refer
 to 'context'. My guy feeling is that these methods should be methods of the
 ZClass so I'll probably change that, but for now no errors.
 
 Unfortunately, however, the instance isn't getting updated either. After
 hitting submit I get the red "Your changes have been saved" and the edit
 form is visible, but the same old values are there. When I view the instance
 after updating I also see the same of values. Apparently either REQUEST
 doesn't contain the data it's supposed to or the instance isn't being
 properly modified with REQUEST's contents. Any thoughts?

I would put the Python Script in the ZClass's /methods and see what
happens.

-- Jim

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Jim Washington

Hi, Tim

I am not working through that example, but the below is a start on what
you seem to need. Let me know what you think.

good luck!

-- Jim Washington

***

You probably want the work to be done in the context of an instance of
the class, so assure you have "context" bound to the Python Script on
the "bindings" tab.  It's bound by default.

You might want to name the Script in a Zopish way to distinguish it from
other scripts that may do other things.  I would probably call it
manage_changeCDProperties.

You will want to pass REQUEST to it so you can use it like the Zope
builtins:

containerName.CDInfoName.manage_changeCDProperties(REQUEST)

So, put REQUEST in the parameters list.

(BTW, REQUEST is available as context.REQUEST if you choose not to pass
REQUEST.)

Inside the script, you would use Zope's manage_changeProperties method:

context.propertysheets['cd_info'].manage_changeProperties(REQUEST)
-or-
context.propertysheets.cd_info.manage_changeProperties(REQUEST)

You're done, unless you want to get fancy and process the items
separately.

If you want to get fancy, REQUEST.form['title'], REQUEST.form['artist'],
and REQUEST.form['date_purchased'] are available to you.

For example, if you want to assure title case for title and artist (try
this in DTML first, just to get the scope of how much easier it is in a
Python Script):

import string
dontCapitalize = ['a','in','of', 'for']
localPropertiesDict = {}
for aproperty in ['title','artist']:
  theProperty = string.strip(REQUEST.form[aproperty])
  splitWords = string.split(theProperty)
  newlist = []
  for aWord in splitWords:
if aWord in dontCapitalize and aWord != splitWords[0]:
  newlist.append(string.lower(aWord))
else:
  newlist.append(string.capitalize(aWord))
  newValue = string.join(newlist,' ')
  localPropertiesDict[aproperty] = newValue
context.propertysheets['cd_info'].manage_changeProperties(localPropertiesDict)  





To delete something from the ZODB, pass a list of ids to
manage_delObjects in your container.

To delete them all:

thelist = context.containerName.objectIds('CD_Info')
context.containerName.manage_delObjects(thelist)

Let's say you lent out all your Britney Spears CDs and don't expect to
get them back.  How do you update your collection?

Make a form that allows you to select 'Britney Spears' into a variable
called 'deleteThisArtist'

Make a Python Script that is called by the action for the form.  This
goes into your class for CD collection, whatever you have named it.

import string
#we make this case-insensitive by converting all to uppercase
deleteMe = string.upper(context.REQUEST.form['deleteThisArtist'])
listToDel = []
for CD in context.objectValues('CD_Info'):
  if string.upper(CD.artist) == deleteMe:
listToDel.append(CD.id)  #in Zope-2.3.0+, you should use .getId()
instead of .id
context.manage_delObjects(listToDel)


Timothy Wilson wrote:
 
 Hi everyone,
 
 I'm looking forward to using some PythonScripts as methods of some ZClasses
 because it seems like a much cleaner way to do things. I wonder if one of
 the PythonScript gurus out there would be willing to show an example of two
 presumably common PythonScript/ZClass tasks: processing changes to a
 property sheet using form input and deleting a ZClass instance.
 
 Let's say we've got a ZClass for keeping track of a CD collection. (I recall
 seeing that example in a ZClass How-To.) Let's say the ZClass has a property
 sheet called 'cd_info' with the following properties:
 
 title (string)
 artist (string)
 date_purchased (date)
 
 (for extra credit, add a 'songs' property of type 'lines' :-)
 
 Is that enough info? Anybody want to take a crack at this? (This would
 surely be good info to put at zope.org somewhere.)
 
 -Tim

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Evan Simpson

From: "Jim Washington" [EMAIL PROTECTED]
 I am not working through that example, but the below is a start on what
 you seem to need. Let me know what you think.

Thanks for the fine examples!  I have only one nit to pick; When using
Scripts in ZClasses, you will typically want to use 'container', not
'context', since 'context' may not be the ZClass instance, but 'container'
always is.  Of course, a Script may operate on both the instance and on
whatever object it was called on, in which case both 'container' and
'context' will be used.

Cheers,

Evan @ digicool  4-am


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Timothy Wilson

On Sun, 14 Jan 2001, Jim Washington wrote:

 I am not working through that example, but the below is a start on what
 you seem to need. Let me know what you think.

Thanks Jim. I will study the examples you provided. Do you suppose that the
Zope Book would benefit from some examples of this type?

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Timothy Wilson

On Sun, 14 Jan 2001, Jim Washington wrote:

 You probably want the work to be done in the context of an instance of
 the class, so assure you have "context" bound to the Python Script on
 the "bindings" tab.  It's bound by default.
 
 You might want to name the Script in a Zopish way to distinguish it from
 other scripts that may do other things.  I would probably call it
 manage_changeCDProperties.
 
 You will want to pass REQUEST to it so you can use it like the Zope
 builtins:
 
 containerName.CDInfoName.manage_changeCDProperties(REQUEST)
 
 So, put REQUEST in the parameters list.

I'm afraid I'm a bit confused here. Is 'CDInfoName' the id of an instance of
this CD class? If so, what would 'containerName' be?

In the particular example I'm thinking about (not a CD collection), I've
created a form that displays the current properties of the class (a job
opening for the H.R. deparment in my case), allows the user to modify any of
the properties in the form, and submit those changes. I suppose for the CD
example it would something like: (ignoring everything but the form)

form action="manage_changeCDProperties(REQUEST)"
table border="0"

trthTitle/th
  tdinput type="text" name="title" value="dtml-var title"/td
/tr

trthArtist/th
  tdinput type="text" name="artist" value="dtml-var artist"/td
/tr

trtd
input type="submit" value=" Submit Edits "
/td/tr
/table
/form

I don't think I'm calling the PythonScript correctly. In fact, I suspect I'm
quite a bit off.

 Inside the script, you would use Zope's manage_changeProperties method:
 
 context.propertysheets['cd_info'].manage_changeProperties(REQUEST)
 -or-
 context.propertysheets.cd_info.manage_changeProperties(REQUEST)

Following Evan's advice, would this then be:

container.propertysheets['cd_info'].manage_changeProperties(REQUEST)

So that's a one-liner? Hmmm. Cool if true. :-)

Let's say that I wanted to redirect the user back to the Web page where they
had begun this process. How would that be accomplished?

-Tim

 Timothy Wilson wrote:
  
  Hi everyone,
  
  I'm looking forward to using some PythonScripts as methods of some ZClasses
  because it seems like a much cleaner way to do things. I wonder if one of
  the PythonScript gurus out there would be willing to show an example of two
  presumably common PythonScript/ZClass tasks: processing changes to a
  property sheet using form input and deleting a ZClass instance.
  
  Let's say we've got a ZClass for keeping track of a CD collection. (I recall
  seeing that example in a ZClass How-To.) Let's say the ZClass has a property
  sheet called 'cd_info' with the following properties:
  
  title (string)
  artist (string)
  date_purchased (date)
  
  (for extra credit, add a 'songs' property of type 'lines' :-)
  
  Is that enough info? Anybody want to take a crack at this? (This would
  surely be good info to put at zope.org somewhere.)
  
  -Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Jim Washington

Hi, Tim

 
  You will want to pass REQUEST to it so you can use it like the Zope
  builtins:
 
  containerName.CDInfoName.manage_changeCDProperties(REQUEST)
 
  So, put REQUEST in the parameters list.
 
 I'm afraid I'm a bit confused here. Is 'CDInfoName' the id of an instance of
 this CD class? If so, what would 'containerName' be?

Yes.  CDInfoName here would be an instance of your CD Class. 
containerName is the name of the container, whether it be a folder or a
folderish ZClass made for handling a collection of CD Class objects.  It
doesn't have to be there in the statement unless something else is
asking the folderish object to ask the CD Class object to change the
properties, which at the moment seems kind of silly.  I must have gotten
off on containers with your second question about deletion. Apologies
for the confusion.
 
 In the particular example I'm thinking about (not a CD collection), I've
 created a form that displays the current properties of the class (a job
 opening for the H.R. deparment in my case), allows the user to modify any of
 the properties in the form, and submit those changes. I suppose for the CD
 example it would something like: (ignoring everything but the form)
 
 form action="manage_changeCDProperties(REQUEST)"
 table border="0"
 
 trthTitle/th
   tdinput type="text" name="title" value="dtml-var title"/td
 /tr
 
 trthArtist/th
   tdinput type="text" name="artist" value="dtml-var artist"/td
 /tr
 
 trtd
 input type="submit" value=" Submit Edits "
 /td/tr
 /table
 /form
 
 I don't think I'm calling the PythonScript correctly. In fact, I suspect I'm
 quite a bit off.

I think it would work, at least as far as updating the properties, but
it would not  return anything. See below my attempt at an alternative.

  Inside the script, you would use Zope's manage_changeProperties method:
 
  context.propertysheets['cd_info'].manage_changeProperties(REQUEST)
  -or-
  context.propertysheets.cd_info.manage_changeProperties(REQUEST)
 
 Following Evan's advice, would this then be:
 
 container.propertysheets['cd_info'].manage_changeProperties(REQUEST)
 
 So that's a one-liner? Hmmm. Cool if true. :-)

Always has been, even in DTML. 
 
 Let's say that I wanted to redirect the user back to the Web page where they
 had begun this process. How would that be accomplished?

There are many ways.  I like to make it all happen at the beginning of
the DTML Method.
Hacking up the form you provided above (lines with ! have been added or
changed):

!dtml-var standard_html_header

!dtml-if "REQUEST.form.has_key('editCD')"
!  dtml-call "manage_changeCDProperties(REQUEST)"
!  pfont color="red"Your changes have been saved/font/p
!/dtml-if

!form action="replace_this_with_id_of_this_method"
 table border="0"
 
 trthTitle/th
  tdinput type="text" name="title" value="dtml-var title"/td
 /tr
 
 trthArtist/th
   tdinput type="text" name="artist" value="dtml-var artist"/td
 /tr
 
 trtd
! input type="submit" name="editCD" value=" Submit Edits "
 /td/tr
 /table
 /form
!dtml-var standard_html_footer

Hoping I have not confused further,

-- Jim Washington

  Timothy Wilson wrote:
  
   Hi everyone,
  
   I'm looking forward to using some PythonScripts as methods of some ZClasses
   because it seems like a much cleaner way to do things. I wonder if one of
   the PythonScript gurus out there would be willing to show an example of two
   presumably common PythonScript/ZClass tasks: processing changes to a
   property sheet using form input and deleting a ZClass instance.
  
   Let's say we've got a ZClass for keeping track of a CD collection. (I recall
   seeing that example in a ZClass How-To.) Let's say the ZClass has a property
   sheet called 'cd_info' with the following properties:
  
   title (string)
   artist (string)
   date_purchased (date)
  
   (for extra credit, add a 'songs' property of type 'lines' :-)
  
   Is that enough info? Anybody want to take a crack at this? (This would
   surely be good info to put at zope.org somewhere.)
  
   -Tim

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] ZClasses meet PythonScripts, sample request

2001-01-14 Thread Timothy Wilson

This seems to almost work. :-)

On Sun, 14 Jan 2001, Jim Washington wrote:

 !dtml-var standard_html_header
 
 !dtml-if "REQUEST.form.has_key('editCD')"
 !  dtml-call "manage_changeCDProperties(REQUEST)"
 !  pfont color="red"Your changes have been saved/font/p
 !/dtml-if
 
 !form action="replace_this_with_id_of_this_method"
  table border="0"
  
  trthTitle/th
   tdinput type="text" name="title" value="dtml-var title"/td
  /tr
  
  trthArtist/th
tdinput type="text" name="artist" value="dtml-var artist"/td
  /tr
  
  trtd
 ! input type="submit" name="editCD" value=" Submit Edits "
  /td/tr
  /table
  /form
 !dtml-var standard_html_footer

That's quite clever. I wouldn't have thought of doing it that way.

After translating the CD example to my own ZClass, I get the following error
after hitting "Submit Edits" on the edit form:

h2Zope Error/h2
pZope has encountered an error while publishing this resource.
  /p
pstrongResource not found/strong/p
Sorry, the requested Zope resource does not exist.pCheck the URL and try
again.p
!--
http://www.isd197.k12.mn.us/hr/jobs/postings/1234/editJobAction%28REQUEST%29
--

and the traceback:

Traceback (innermost last):
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 222, in
publish_module
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 187, in
publish
  File /var/lib/zope/2.3.0a2/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
(Object: Traversable)
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/Publish.py, line 162, in
publish
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/BaseRequest.py, line 369,
in traverse
  File /var/lib/zope/2.3.0a2/lib/python/ZPublisher/HTTPResponse.py, line
528, in notFoundError
NotFound: (see above)

It looks like REQUEST isn't getting passed correctly. I've got REQUEST
listed as a parameter for my PythonScript. I don't need to mess with
bindings do I?

-Tim

--
Tim Wilson  | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |  | http://slashdot.org/
[EMAIL PROTECTED] |   dtml-var pithy_quote | http://linux.com/


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )