[Zope] Q: Iterating through an arbitrary number of SUBMIT form REQUEST object files/attributes?
Samu Mielonen
ex@uiah.fi
Mon, 25 Oct 1999 17:00:00 +0300
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.