Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-05 Thread Jürgen Herrmann


[ Negroup - wrote:]
 2005/7/5, Konstantin E. Steuck [EMAIL PROTECTED]:
 Negroup - wrote:
 [cut]
 Try looking into copy/cut/paste machinery, it seems to be what you're
looking for


 This is a thing I absolutely want to avoid. I simply need to pass an
object directly from one template to another, without intermediate steps
(like, copying or creating the object with some manage_*method from a
template, read the created object from the other template and then
remove the object itself because unuseful..).

 In python it is so immediate: I pass objects between functions via
parameters; in zope the most natural way to simulate parameters
passing from one zpt and another is storing them inside the request
object, and thus, using html forms. But for some reasons that I'm
missing, it doesn't work!

passing objects from one template to another via the REQUEST variable only
works while you're in ONE request. otherwise you'll get a string
representation as you mentioned.

try using the session mechanism instead:
http://www.plope.com/Books/2_7Edition/Sessions.stx

regards, juergen herrmann
___

 XLhost.de - eXperts in Linux hosting 

Juergen Herrmann
Weiherweg 10, 93051 Regensburg, Germany
Fon:  +49 (0)700 XLHOSTDE [0700 95467833]
Fax:  +49 (0)721 151 463027

ICQ:  27139974  -  IRC: [EMAIL PROTECTED]
WEB:  http://www.XLhost.de



___

 XLhost.de - eXperts in Linux hosting 

Juergen Herrmann
Weiherweg 10, 93051 Regensburg, Germany
Fon:  +49 (0)700 XLHOSTDE [0700 95467833]
Fax:  +49 (0)721 151 463027

ICQ:  27139974  -  IRC: [EMAIL PROTECTED]
WEB:  http://www.XLhost.de
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-05 Thread Tino Wildenhain
Am Montag, den 04.07.2005, 22:53 +0200 schrieb Negroup -:
 Is there some way to pass an object from template A to template B via
 HTML forms?
 
 A
 form name=a action=b method=post
 input type=hidden name=obj tal:attributes=value here /
 input type=submit value=Press /
 /form
 
 B
 b tal:content=structure here/REQUEST/b
 
 Template B prints:
 form
 obj   'OrderedFolder instance at 42d9aec0'
 
 I need the object itself, not the string representing the object!

You cannot simply pass a ZOPE object in a form like that.
You can handle fairly complex structures (lists and dictionaries
with int, float, string in them) but whole objects would
need to be pickled and then open a huge security hole
(Whatever is in the client can and will be faked)

So best option I see is to not pass the object but rather
pass the reference to the object. You can resolve
it via restrictedTraverse('/path/from/form')

Btw. avoid much code in the Template. Its a maintenance
headache. You can do it esily in a python script and 
call this from template.



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


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-05 Thread Andrew Milton
+---[ Negroup - ]--
| 2005/7/5, Tino Wildenhain [EMAIL PROTECTED]:
| [cut]
| 
|  So best option I see is to not pass the object but rather
|  pass the reference to the object. You can resolve
|  it via restrictedTraverse('/path/from/form')
| 
| I think I can't apply your solution. restrictedTraverse asks for a
| path, and then it supposes that the object is stored inside ZODB. This
| is not my case. Let me provide a minimanl explaination about how my
| application is structured.
| 
| 1. A user can uploads a zipped file via HTML form in upload_zip ZPT.
| The action of the form points to check_zip, an External Method that
| checks for validity of each file inside the archive.
| 
| 2. check_zip returns to upload_zip a tuple containing two elements:
| True or False (based on the correctness of archive) and the object
| itself, via self parameter.
| 
| 3. after the external method has been called, upload_zip shows other 2
| forms that the user will use to abort operation or to continue the
| process. The form to continue will pass the object to another external
| method in order to compute the result. This is the step where I
| encounter the problem, I can't pass object.
| 
| This should explain why I haven't the object stored inside ZODB.
| 
| Probably the solution would be to store the uploaded object inside a
| temporary area of ZODB and then I'll be able to do all the tasks I
| need.
| 
| Any further consideration/hints?

You would be better off storing the file on the filesystem, and pass the
filename around. You'd have to do some sanity checking on the filename before
any manipulation obviously.

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


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-05 Thread Tino Wildenhain
Am Dienstag, den 05.07.2005, 11:05 +0200 schrieb Negroup -:
 2005/7/5, Tino Wildenhain [EMAIL PROTECTED]:
 [cut]
 
  So best option I see is to not pass the object but rather
  pass the reference to the object. You can resolve
  it via restrictedTraverse('/path/from/form')
 
 I think I can't apply your solution. restrictedTraverse asks for a
 path, and then it supposes that the object is stored inside ZODB. This
 is not my case. Let me provide a minimanl explaination about how my
 application is structured.
 
 1. A user can uploads a zipped file via HTML form in upload_zip ZPT.
 The action of the form points to check_zip, an External Method that
 checks for validity of each file inside the archive.
 
 2. check_zip returns to upload_zip a tuple containing two elements:
 True or False (based on the correctness of archive) and the object
 itself, via self parameter.
 
 3. after the external method has been called, upload_zip shows other 2
 forms that the user will use to abort operation or to continue the
 process. The form to continue will pass the object to another external
 method in order to compute the result. This is the step where I
 encounter the problem, I can't pass object.
 
 This should explain why I haven't the object stored inside ZODB.
 
 Probably the solution would be to store the uploaded object inside a
 temporary area of ZODB and then I'll be able to do all the tasks I
 need.
 
 Any further consideration/hints?

Well yes, thats very easy. Just store your (compressed or not)
HTML data (since its a string after all and not such a complex
object) in a hidden form field (base64 encoded for example) -

filedata=htmldata.encode(base64)

and the other parts of your form as you wish. Maybe you prepare
the data in a script and call the ZPT from it:

return context.yourZPT(filedata=filedata,somestatus=whatever)

and use: input type=hidden tal:attributes=value options/filedata
type=text / in your ZPT.

When the request returns, use: htmldata=filedata.decode(base64)

alternatively you can just store the data in REQUEST.SESSION
to keep it on server (but watch the memory usage)

-- 
Tino Wildenhain [EMAIL PROTECTED]

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


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-05 Thread Konstantin E. Steuck

Negroup - wrote:

This is a thing I absolutely want to avoid. I simply need to pass an
object directly from one template to another, without intermediate
steps (like, copying or creating the object with some manage_*method
from a template, read the created object from the other template and
then remove the object itself because unuseful..).

Sure, you don't need to use copy/paste mechanism, just look on
the implementation. AFAIR it just pickles list of absolute_url()'s and
stores base64-encoded result into cookies.
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-04 Thread Andreas Pakulat
On 04.Jul 2005 - 22:53:58, Negroup - wrote:
 Is there some way to pass an object from template A to template B via
 HTML forms?
 
 A
 form name=a action=b method=post
 input type=hidden name=obj tal:attributes=value here /
 input type=submit value=Press /
 /form
 
 B
 b tal:content=structure here/REQUEST/b
 
 Template B prints:
 form
 obj   'OrderedFolder instance at 42d9aec0'
 
 I need the object itself, not the string representing the object!

You do get the object itself when you access REQEUST['obj'], only in
HTML you get something like the above, as that's what the string
represenation of obj is.

Andreas

-- 
Try to relax and enjoy the crisis.
-- Ashleigh Brilliant
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-04 Thread Negroup -
2005/7/4, Andreas Pakulat [EMAIL PROTECTED]:
 On 04.Jul 2005 - 22:53:58, Negroup - wrote:
[cut]
  b tal:content=structure here/REQUEST/b
[cut] 
 You do get the object itself when you access REQEUST['obj'], only in
 HTML you get something like the above, as that's what the string
 represenation of obj is. 

Why then, if template b is:
b tal:define=obj python:here.REQUEST['obj'].getId()/b
(or b tal:define=obj python:here.REQUEST.form['obj'].getId()/b)

zope gives this error?

Error Type: AttributeError
Error Value: 'str' object has no attribute 'getId'
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Pass objects from template to template via HTML forms.

2005-07-04 Thread Konstantin E. Steuck

Negroup - wrote:

Why then, if template b is:
b tal:define=obj python:here.REQUEST['obj'].getId()/b
(or b tal:define=obj python:here.REQUEST.form['obj'].getId()/b)

zope gives this error?


Because REQUEST.form['obj'] is already a string representation of then 
object, not object itself, hence it has not method getId()
Try looking into copy/cut/paste machinery, it seems to be what you're 
looking for

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )