[Zope] It Works!!!! I think I'm close, Product Creation and other threads

Daniel Rusch drusch@globalcrossing.com
Fri, 25 Aug 2000 11:42:25 -0500


Great news, I did it...!  

The trick seems to be adding the legacy line to the BasicDocument
__init__.py file (see below). This allowed the following line to work in
the  folderish (SimpleSite) product's manage_addSimpleSite function to
quit barfing:
ob.manage_addBasicDocument(id='index_html', title='')

BTW, Remember I said that I my plan of attach, while I was praying for
an epiphany, was to figure out how a Folder could create sub products.
Well, I figured this out via an epiphany, I accidentally cd'd to OFSP
instead of OFS and I looked at the __init__.py file, it was most
illuminating..... Ok it wasn't exactly an epiphany, but I'll still chalk
it up to divine intervention....

DR



This is the  __init__.py file for the folderish product which contains
the other product I created. 

                    
__doc__="""SimpleSite product initialization"""
__version__='$Revision: 0.1 $'[11:-2]


try:

    import os, SimpleSite
    from Globals import ImageFile

    def initialize(context):
        context.registerClass(
            SimpleSite.SimpleSite,
            constructors=(SimpleSite.manage_addSimpleSiteForm,
                          SimpleSite.manage_addSimpleSite),
            #icon='simpleSite.gif',
            legacy=(SimpleSite.manage_addSimpleSite,),  
            )
        context.registerBaseClass(SimpleSite.SimpleSite, 'Simple Site')

except:
    print "She's sucking mud in SimpleSite land capt'n:" 
    import traceback
    traceback.print_exc()       


This is the __init__.py file for the other product:

__doc__="""BasicDocument product initialization"""
__version__='$Revision: 0.1 $'[11:-2]

try:

    import os, BasicDocument
    from Globals import ImageFile

    
    def initialize(context):
        context.registerClass(
            BasicDocument.BasicDocument,
            constructors=(BasicDocument.manage_addBasicDocumentForm,
                          BasicDocument.manage_addBasicDocument),
            #icon='basicDoc.gif',
            legacy=(BasicDocument.manage_addBasicDocument,), 
            )
        context.registerBaseClass(BasicDocument.BasicDocument, 'Basic
Document')

except:
    print "She's sucking mud in BasicDocument land capt'n:" 
    import traceback
    traceback.print_exc()    

Chris Beaumont wrote:
> 
> Daniel,
> 
> Would you let me know if you get a good answer to your question.. I'm
> trying to do something quite similar..
> 
> Thank you.
> 
> Chris
> 
> Daniel Rusch wrote:
> >
> > Hello,
> >
> > (See bottom of this message for all the iterations I have tried)
> >
> > I've created a product called BasicDocument. I've installed it and it
> > works great.
> >
> > I've also created a folderish product (called SimpleSite). When a user
> > selects
> > the SimpleSite product from the available objects list, thus creating an
> > instance of that product,
> > they have an option to create sub folders which contain objects like
> > dtml documents, dtml
> > methods, and my BasicDocument product (very similar to what happens when
> > you instantiate a folder object, you
> > can have a dtml method created in the new folder).
> >
> > I am able to have the manage_addSimpleSite function create
> > DTMLDocument, DTMLMethod and Folder objects but I am unable to
> > have the function create BasicDocuments (which live in the Products
> > directory) additionally, I am unable to it create any Products from
> > the Products directory, such as Local File System?????
> >
> >  The code below works great, I get a dtml document, two folders each
> > with a dtml method in them....
> >
> >
> >  HOW CAN I CREATE A BascicDocument, LOCAL FILE SYSTEM OR ANY OTHER
> > OBJECT FROM THE
> >  PRODUCTS DIRECTORY IN THIS MANAGE_ADD FUNCTION???????
> >
> > Thanks,
> >
> > Dan
> >
> >  def manage_addSimpleSite(self, id, title='',
> >                       createNewFolder=0,
> >                       createEditFolder=0,
> >                       REQUEST=None):
> >      """Add a new SimpleSite object with id *id*.
> >
> >      If the 'createNewFolder' and 'createEditFolder' parameters are set
> >  to any true
> >      value, an 'New sub Folder' and an 'edit sub Folder' objects are
> >  created respectively
> >      in the new SimpleSite.
> >      """
> >      ob=SimpleSite()
> >      ob.id=id
> >      ob.title=title
> >      self._setObject(id, ob)
> >      try: user=REQUEST['AUTHENTICATED_USER']
> >      except: user=None
> >      #ob.manage_addBasicDocument(id='index_html', title='')<-- This line
> > generates: AttributeError: manage_addBasicDocument
> >      ob.manage_addDTMLDocument(id='index_html', title='')
> >      if createNewFolder:
> >          if (user is not None) and not (
> >              user.has_permission('Add User SimpleSites', self)):
> >              raise 'Unauthorized', (
> >                    'You are not authorized to add User SimpleSites.'
> >                    )
> >          ob.manage_addFolder(id='New'+id, title='', createPublic=1)
> >      if createEditFolder:
> >          if (user is not None) and not (
> >              user.has_permission('Add Documents, Images, and Files',
> >  self)):
> >              raise 'Unauthorized', (
> >                    'You are not authorized to add DTML Documents.'
> >                    )
> >          ob.manage_addFolder(id='Edit'+id, title='', createPublic=1)
> >      if REQUEST is not None:
> >          return self.manage_main(self, REQUEST, update_menu=1
> >
> > I have tried the following each generated an error:
> >
> > 1. ob.manage_addBasicDocument(id='index_html', title='')
> > AttributeError: manage_addBasicDocument
> > 2.
> > ob.manage_addProduct['SimpleSite'].manage_addBasicDocument(id='index_html',
> > title='')  AttributeError: _getProducts
> > 3.
> > self.manage_addProduct['SimpleSite'].manage_addBasicDocument(id='index_html',
> > title='')AttributeError:manage_addBasicDocument
> > 4.
> > self.manage_addProduct['BasicDocument'].manage_addBasicDocument(id='index_html',
> > title='') TypeError: not enough arguments; expected 2, got 0
> > 5.
> > ob.manage_addProduct['BasicDocument'].manage_addBasicDocument(id='index_html',
> > title='')AttributeError: _getProducts
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )