Q: Iterating through an arbitrary number of SUBMIT form REQUEST object files/attributes?
I've mananed to solve every single problem regarding to saving images, replacing images, referencing image sizes, etc,. Thanks to all the kind people on the list fo comments. However, I'm still unsure how to handle the form data send via post method by the browser. Consider an arbitrary submit-form that contains different variable types (text, numbers, boolean) and various file types (images, video, etc.) via file-upload buttons. Is there a way to handle a REQUEST object (from the above arbitrary submit form) in such a manner that that it: 1) Automatically reads all variable names, types and values (e.g. <input type="text" name="name1:text"> with value "John Smith" is turned into a property name1 with value 'John Smith' for the object to be handled) 2) Automatically reads through all the included files (submitted through multipart/form-data), detects their type (if possible) and saves the inside the object in question as sub-objects. (e.g. parrot.jpg is understood to be a file of type Image and saved as an image object with the id "parrot.jpg" or just "parrot") Is this too much of an Herculean undertaking or is it something done easily? I'm most interested in iterating through all of the encoded files of a form submitted REQUEST object and saving each of them with a proper id and type (image, etc) inside a folder (object). Best regards, Samu Mielonen PS I think I'm over the tipping point at which I'm starting to appreciate the power of Zope, although learning is still very slow for me and I mungle with syntax all the time :) -- "Our reflections on the order of society, as well as nature, are still dominated by the Newtonian image of massive power, exerted by sovereign agency through the operation of central force..." -Stephen Toulmin, "Cosmopolis"
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Samu Mielonen Sent: Monday, October 25, 1999 2:03 PM To: Zope Mailing List Subject: [Zope] Q: Iterating through an arbitrary number of SUBMIT form REQUEST object files/attributes?
[snip]
Is there a way to handle a REQUEST object (from the above arbitrary submit form) in such a manner that that it: [snip]
Is this too much of an Herculean undertaking or is it something done easily? I'm most interested in iterating through all of the encoded files of a form submitted REQUEST object and saving each of them with a proper id and type (image, etc) inside a folder (object).
Erhm, sorry, Samu, but this _is_ how ZPublisher works. It chucks all the raw HTTP request stuff into REQUEST and lets you easily extract it. For example, give a form such as <form action="Foo" method="post" enctype="multipart/form-data"> <input type="text" name="Name" value=""> <input type="submit"> </form> then the object Foo can consist of the following DTML: <dtml-var standard_html_header> Your name is: <dtml-var Name> <dtml-var standard_html_footer> Here, REQUEST is implied because it's part of the namespace stack. Note that REQUEST is pretty low in the namespace stack: It means that if there is a folder or object called Name along the acquisition path, then the above DTML will use that. So, a general, good rule of thumb is to always reference REQUEST; thus it becomes: <dtml-var "REQUEST.Name"> or <dtml-var "REQUEST['Name']"> Here's a tidbit I think you'll appreciate: In your form target -- in this case Foo -- or indeed in any DTML document or method, place the following DTML: <dtml-var REQUEST> This will render a HTMLized version of the current request's REQUEST object.
Best regards, Samu Mielonen
PS I think I'm over the tipping point at which I'm starting to appreciate the power of Zope, although learning is still very slow for me and I mungle with syntax all the time :)
-- "Our reflections on the order of society, as well as nature, are still dominated by the Newtonian image of massive power, exerted by sovereign agency through the operation of central force..." -Stephen Toulmin, "Cosmopolis"
Alexander Staubo mailto:alex@mop.no http://www.mop.no/~alex/
Hello, Alex:
Erhm, sorry, Samu, but this _is_ how ZPublisher works. It chucks all the raw HTTP request stuff into REQUEST and lets you easily extract it.
Hmmm, I think you misunderstood me (I was being way too confusing as usual :) My apologies. I'll try to illustrate my problem better: I know I can extract KNOWN variables/properties out of REQUEST object, but what if I don't know what's inside REQUEST? I don't know the variable names not to mention what data types they may contain. I know I can list the contents with <dtml-var REQUEST>, but that doesn't give me access to the REQUEST object parts as properties and sub-objects, it just displays the contents. How do I access all encoded files from an unknown REQUEST-object and detect their mime-types + save them as files of proper type (i.e. image, html file, etc) in ZOBD? I can't do the normal <dtml-in "objectValues('Image')"> inside the REQUEST object, because those encoded parts are not understood by Zope to be image-type objects (because they haven't been saved in ZOBD yet as image files). So, I need to: 1) Go through all of REQUEST object 2) Identify parts that are good candidates of type Image (+ Verify that they are capable objects of type Image) 3) Save the candidate parts as Zope objects of type Image in the Zope Object database with a id taken from the uploaded image name (i.e. C:\myfolder\imagename.jpg) And do all this without knowing if there are any or x number of image parts inside the REQUEST object and what names are they being referenced with. This is what I want to do in specific, but my general challenge is: Is there an non-herculean piece of dtml-code that saves every part out of the REQUEST object properly into a container object of class X with accompanying object properties and sub-objects (other images, files, etc.)? I'm thinking something in the lines of: <dtml-call "REQUEST.get_all_variable_names()"> ...REQUEST.get_all_variable_data_types() ...REQUEST.get_all_variable_values() ...REQUEST.get_all_variable_name_values_tuples() etc. I haven't figured out how to parse an unknown REQUEST object without going to Python level (and even there, I'm not sure yet how it's done, but I assume it's not trivial). Thanks for your good comments. The bit about namespace was especially helpful (it solved one nagging problem I was having :) Best regards, Samu Mielonen PS My problem stems from a very simple issue: how do I manage to save an article in KMNetNews with an unknown number of images with a simple dtml method that need not be edited every time the number of submitted images in the submit form changes.
At 5:00 pm +0300 25/10/99, Samu Mielonen wrote:
Hello,
Alex:
Erhm, sorry, Samu, but this _is_ how ZPublisher works. It chucks all the raw HTTP request stuff into REQUEST and lets you easily extract it.
Hmmm, I think you misunderstood me (I was being way too confusing as usual :) My apologies. I'll try to illustrate my problem better:
I know I can extract KNOWN variables/properties out of REQUEST object, but what if I don't know what's inside REQUEST? I don't know the variable names not to mention what data types they may contain.
You can also do <dtml-in "REQUEST.form.items()"> to get the contents of the form dictionary (ie the all FORM variables) in <dtml-var sequence-key> and <dtml-var sequence-item> (a .cookies method exists as well). I'm not sure about what or how you'll test variable types you'll get back. hth tone ------ Dr Tony McDonald, FMCC, Networked Learning Environments Project http://nle.ncl.ac.uk/ The Medical School, Newcastle University Tel: +44 191 222 5888 Fingerprint: 3450 876D FA41 B926 D3DD F8C3 F2D0 C3B9 8B38 18A2
participants (3)
-
Alexander Staubo -
Samu Mielonen -
Tony McDonald