[Zope] Image Uploading and Adding Properties?

Ross J. Reedstrom reedstrm@wallace.ece.rice.edu
Tue, 15 Jun 1999 12:10:10 -0500


On Tue, Jun 15, 1999 at 10:08:39AM -0100, Tom Schwaller wrote:
> 
> When I upload an image with the code you postet, the resulting object is
> not 
> a "normal" image object (although it has every attribute one wants,
> including
> the "addedby"). The icon although is different and there's also a thing
> called

Right, that's because I use manage_addFile for all the uploads, rather
than manage_addImage. It might be possible to do some sort of magic with
mimetypes, but if your users can be trusted to check the right box, you
could use the trick the management form does, and pass in a variable
from the form from a checklist or dropbox, like "kind" and "Kind" in
the snippet from imageAdd.html below:

----------
 You can create a new <!--#var kind--> in the system using the form below. 
 Select an <!--#var kind--> from your local computer by clicking the
 <em>Browse</em> button. The <!--#var kind--> you select will be uploaded
 to the application.

<FORM ACTION="manage_add<!--#var Kind-->" METHOD="POST"
      ENCTYPE="multipart/form-data">
<TABLE CELLSPACING="2">
----------

> 
> Precondition (which is empty..)
> 
> Any idea what that is?

Don't know, looks interesting... Here's where it gets called, in the index_html
method for the File object:

   def index_html(self, REQUEST, RESPONSE):
        """
        The default view of the contents of a File or Image.

        Returns the contents of the file or image.  Also, sets the
        Content-Type HTTP header to the objects content type.
        """

        if self.precondition and hasattr(self,self.precondition):
            # Grab whatever precondition was defined and then 
            # execute it.  The precondition will raise an exception 
            # if something violates its terms.
            c=getattr(self,self.precondition)
            if hasattr(c,'isDocTemp') and c.isDocTemp:
                c(REQUEST['PARENTS'][1],REQUEST)
            else:
                c()
        RESPONSE.setHeader('content-type', self.content_type)
        return self.data

So, it looks like you can set a precondition to be an arbitary method of
your file object, and it will be called (either in the context of this
 File object, or it's parent, depending on if your precondition includes
a 'isDocTemp' attribute itself)

Any one at DC have an example of what this is useful for? Nothing shows up
in the source outside the File creation code.

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005