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:  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:



or





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

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-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] || 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 , 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': ,
> 'context': , 'container':  instance at 87225f0>, 'traverse_subpath': []},
> (

form

valign="top" >align="left"> valign="top" >align="left"> valign="top" >align="left"> > -- 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


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] || 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


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
> -
> 
> 
> 
> Edit a Job Board Entry
> This 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.
> 
> 
> 
> Your changes have been saved
> 
> 
> 
> 
> 
> Notes
>  notes>
> 
> Job ID
> 
> 
> Organization
> 
> 
> Position
> 
> 
> Description
>  name="description:text" rows="10" cols="60" wrap="virtual"> description>
> 
> Pay Offered
> 
> 
> Line of Authority
> 
> 
> Function
>  name="function:text" rows="4" cols="60" wrap="virtual"> function>
> 
> Qualifications
>  name="qualifications:text" rows="8" cols="60" wrap="virtual"> qualifications>
> 
> 
> 
> To create a bullet list of "duties," type each one in the box below and
> press the "ENTER" key
> between each item in the list.
> 
> 
> Duties
> 
>  duties>
> 
> 
> 
>  name="duties:list" rows="10" cols="60" wrap="virtual">
> 
> 
> Offer Expires
> ">
> 
> 
> Enter the date that the job was officially posted.
> 
> Posted Date
> ">
> 
> 
>  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -
> 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 , 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': ,
> 'context': , 'container':  instance at 885a3e0>, 'traverse_subpath': []},
> (

form

posted'01/15/2001'
duties['asdfasdf\015\012']
position'asdfadsfasd'
valign="top" >align="left"> valign="top" >align="left"> > -- I've deleted what looks like the entire contents of REQUEST -- > > File Python Script, line 2, in editFormAction > File /var/lib/zope/2.3.0a2/lib/python/Products/PythonScripts/Guarded.py, > line 276, in __getitem__ > File /var/lib/zope/2.3.0a2/lib/python/OFS/PropertySheets.py, line 647, in > __getitem__ > (Object: Traversable) > TypeError: (see above)

Re: [Zope] ZClasses meet PythonScripts, sample request


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
-



Edit a Job Board Entry
This 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.



Your changes have been saved





Notes


Job ID


Organization


Position


Description


Pay Offered


Line of Authority


Function


Qualifications




To create a bullet list of "duties," type each one in the box below and
press the "ENTER" key 
between each item in the list.


Duties








Offer Expires
">


Enter the date that the job was officially posted.

Posted Date
">


 












-
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 , 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': ,
'context': , 'container': , 'traverse_subpath': []},
(

form

posted'01/14/2001'
duties['asdfasdf\015\012']

Re: [Zope] ZClasses meet PythonScripts, sample request


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 

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:
> 
> > !
> >
> > !
> > !  
> > !  Your changes have been saved
> > !
> >
> > !
> >  
> >
> >  Title
> >   
> >  
> >
> >  Artist
> >
> >  
> >
> >  
> > ! 
> >  
> >  
> >  
> > !
> 
> 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:
> 
> Zope Error
> Zope has encountered an error while publishing this resource.
>   
> Resource not found
> Sorry, the requested Zope resource does not exist.Check the URL and try
> again.
> 
> 
> 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


This seems to almost work. :-)

On Sun, 14 Jan 2001, Jim Washington wrote:

> !
> 
> !
> !  
> !  Your changes have been saved
> !
> 
> !
>  
>  
>  Title
>   
>  
>  
>  Artist
>
>  
>  
>  
> ! 
>  
>  
>  
> !

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:

Zope Error
Zope has encountered an error while publishing this resource.
  
Resource not found
Sorry, the requested Zope resource does not exist.Check the URL and try
again.


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] || 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


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)
> 
> 
> 
> 
> Title
>   
> 
> 
> Artist
>   
> 
> 
> 
> 
> 
> 
> 
> 
> 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):

!

!
!  
!  Your changes have been saved
!

!
 
 
 Title
  
 
 
 Artist
   
 
 
 
! 
 
 
 
!

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


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)




Title
  


Artist
  








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] || 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


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] || 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


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


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 )




[Zope] ZClasses meet PythonScripts, sample request


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] || 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 )




posted'01/14/2001'
duties['asdfasdf\015\012']