[Zope-CMF] Creating Objects w/o Being in the ZODB

alan runyan alan runyan" <runyaga@runyaga.com
Sat, 11 May 2002 18:15:32 -0500


stock CMF has a bad habit of creating a object in the ZODB and then making
you edit it.  so that if a user
leaves the screen or gets side-tracked there is a potentially orphaned
object just sitting in your ZODB.
there are several ways you could go about addressing this:

* create a new_content_form which behaves differently. [most likely, but i
dont want to do this]

* use autogenerated id's, force people to change the id in the form
validation, sweep zodb for abondoned objects (there should be no
autogenerated id objects).   [this is a quick hack, and am doing this]

* slightly modify edit forms to check for a optional session_obj could be
passed into kwargs of PageTemplate.  so you would create a Object in
Session, find the edit view for that object, return it with a kwarg of
session_obj=obj_instance and then your edit form would have to only be
slightly touched up to check to see if there is a session_obj, if not then
use the default context/here.  [ideal]

Problems - acquistion context!

I can do anything that requires a acqusition context.  i.e. I cant call edit
on this new instance because
I've created the instance *outside* of the ZODB and it doesnt have a
acquistion context.  i.e.

from Products.CMFPlone import Document     #this is a Document instnace
d=Document()
SESSION.set('session_obj', d)
edit_form=types_tool.getTypeInfo(d).getActionById('edit')
return getattr(context, edit_form)(session_obj=d)

I am trying to keep this in python scripts as much as possible.  this works
for attributes on the object, but when I touch a
method, all hell breaks loose because I dont have a acquistion context.  I
believe that if *somehow* I can, in a python script
wrap the current users context on the newly created object and push that
into the PageTemplate call... this thing ideally should work.
Also will operations like this work more easily in Zope3?

Could someone enlighten me *how* to get the current users acquistion context
and wrap an object in it?  I assume I cant do this 'through the web' and I
will need to use external method.  how would I do it?
def returnObjectInContext(self, o):
    """ would this work? """
    return o.__of__(self)

and.. *why* is it a security issue for me to wrap a object in acquiston
context in a Python Script.  because someone could wrap a insecure context
somehow and get more privledges than they are allowed?  what if I make a cal
to the SecurityManager?  can it save me?

cheers,
~runyaga