[Zope] ZClass subclassing a File

Bruce C. Dillahunty bdillahu@mindspring.com
Wed, 28 Jul 1999 19:04:59 -0400


I'm going to put this on the list to see if anybody else has any ideas (I note 
that I just sent it back to Brian, not the list).

The short summary is I have a ZClass (MSFile) that is based on the File 
class provided with Zope. I add some properties to it. If I add an instance of 
this type, it acts just like a File type, not showing any of the properties 
that I have defined... 

Is this a bug, or am I not doing something right? I am using some code to 
import the file that I borrowed from a posting by Ross Reedstrom (Thanks!!) 
which I'm including below to see if that helps:

Bruce

----------------

 <dtml-comment>
Taken from e-mail from:

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
Date: Mon, 14 Jun 1999 10:29:25 -0500 (11:29 EDT)
on the Zope mailing list
</dtml-comment>

<!--#var standard_html_header-->
<!--#comment--> 
We need to set the 'id' to the filename if it's not set. The second line
strips the last component from the filename passed in the REQUEST.file
object, in a platform neutral hack. It fails if someone uses the
path seperator component from one platforn in the filename on another
platform. E.g. slashed dates in filenames on Macs. I stole it from cookId
in Image.py

<!--#/comment-->
<!--#unless REQUEST['id']-->
   <!--#call "REQUEST.set('filename',REQUEST['file'].filename)"-->
   <!--#call  "REQUEST.set('id',filename[_.max(
                        _.string.rfind(filename, '/'),
                        _.string.rfind(filename, '\\'),
                        _.string.rfind(filename, ':'),
                        )+1:])"-->
<!--#/unless-->

<!--#if "REQUEST['id'] in objectIds()"-->
<H4>Sorry! That name exists, try again (use your browser's back button)</H4>
<!--#comment--> fix this up
Would you like to:
New Name:
rename existing file
replace existing file
Upload with new name
<!--#/comment-->
<!--#else-->
<!--#call "manage_addFile(id=_.str(MSMasterCounter) + _.str(_.whrandom.random()),file=REQUEST['file'])"-->

<dtml-comment>
<!--#call "_.getitem(REQUEST['id']).manage_addProperty(
                   'addedby',REQUEST.get('AUTHENTICATED_USER'),
                   'string')"-->
</dtml-comment>

<FORM ACTION=<!--#var "URL1"--> METHOD="GET">
<H3>File Added</H3>
<INPUT type=submit value="OK">
</FORM>

<!--#/if-->

<!--#var standard_html_footer-->


---------------
> > > I have a ZClass that has some properties, etc. I
> > want it to 
> > > be a subclass of 
> > > other ZClasses that I have defined, and the "File"
> > type 
> > > provided by Zope.
> > > 
> > > What I want is a "File" that Zope recognizes, so
> > that I can 
> > > load a file in, 
> > > etc., but have the various properties/methods
> > available 
> > > also... can this be 
> > > done?
> > > 
> > > If I define my ZClass (say MSFile) as a subclass
> > of 
> > > MSFileHolder (which 
> > > provides some generic file/image handling that I
> > want to do), 
> > > and a subclass 
> > > of File, then it works as a File (I can never seem
> > to see the 
> > > Properties 
> > > pages, etc. that I set... if I open the
> > instantiation of the 
> > > object in the 
> > > management interface, I just see it as a "File"...
> > its as if 
> > > the other stuff 
> > > doesn't exist.
> > > 
> > > Am I way off base here?
> > 
> > No - you just need to create "views" for the
> > property sheets
> > that you want to be able to manipulate for your
> > MSFile instances.
> > 
> 
> I am pretty sure I have... (I'm not at home with the
> machine right this minute).
> 
> > A quick example: go to your MSFile ZClass and click
> > on "Property
> > Sheets", and create a property sheet called
> > "ExtraProperties" with
> > a few defined properties.
> > Next, click on the "Views" tab of your MSFile class
> > and add a new
> > "view" that points to that property sheet (type
> > "Extra" in the New
> > text box, and select
> > "propertysheets/ExtraProperties/manage" from
> > the select list and click the "Add" button.
> > 
> 
> OK, one difference I have (at least during my
> testing), is that I had a PropertySheet View defined
> for the superclass (MSFileHolder) of which MSFile is a
> subclass (inherits from/based on - not defined on the
> method's page of MSFileHolder, but rather is a
> separate ZClass with MSFileHolder chosen during create
> time).
> 
> In my other classes formed this way, I get a different
> tab for each superclasses Properties page (just like I
> want - that's great!), but for this "File" type, they
> don't appear.
> 
> Any guesses?
> 
> Thanks,
> Bruce
> 
> > Now your MSFile instances should have an "Extra" tab
> > in their mgmt
> > interface, which will take you to the form for
> > managing the extra
> > properties on that instance.
> > 
> > Hope this helps!
> > 
> > 
> > Brian Lloyd        brian@digicool.com
> > Software Engineer  540.371.6909              
> > Digital Creations  http://www.digicool.com 
> > 
> > 
> > 
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://www.zope.org/mailman/listinfo/zope
> > 
> > (To receive general Zope announcements, see:
> > http://www.zope.org/mailman/listinfo/zope-announce
> > 
> > For developer-specific issues, zope-dev@zope.org -
> > http://www.zope.org/mailman/listinfo/zope-dev )
> > 
> > 
> 
> ===
> -- 
> Bruce C. Dillahunty
> Peachbush Enterprises
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 

-- 
Bruce C. Dillahunty
Peachbush Enterprises
bdillahu@mindspring.com