[Zope] Re: Product Creation and Permission]
Jason Joy
kyroraz@usa.net
7 May 2001 11:54:15 MST
> > Which I think is directly related to what I am experiencing with gett=
ing
the
> > manage_main.
> > =
> > Jason
> > =
> =
> Very interesting. Can you post the revised Python code of your product?=
Sure, I will put up what I current have, but I have also thought about th=
is
over the weekend and came up with some ideas on how to perhaps make this =
work,
although I do not know how practical it will be, so, please let me know i=
f
this is possible or not:
In A, in _getOb (currently encapuslated with ## Right here ##), I have be=
en
tinkering on how it has been working. I tried to return the instance of =
A
instead of creating another B, and it works fine. I have a hunch there i=
s
elements in A when Zope creates the object that just is not passed onto B=
that
contains information about the Zope session that it would like to have.
Only problem is if you do a B =3D A, it is a reference. B and A at this =
point
would have the same memory location and would not be useful. Also, since=
B
has some differences to A, structurally, it won't help out there evil. I=
think the way to fix this is to copy properties from A and B, but I am no=
t
sure which ones are there nor what properties exist on A (other than
A.REQUEST). How can one copy objects such that B =3D self? Even this I =
am not
sure because object B has to be created by what is defined in class B... =
Any
thoughts?
Jason
## Code Is Here ##
A:
import Globals
from Globals import Persistent, Acquisition
import AccessControl
import OFS
from B import *
from pg import DB
from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
__allow_access_to_unprotected_subobjects__ =3D 1
class objectChunk(Implicit):
security =3D ClassSecurityInfo()
security.declareObjectPublic()
security.setDefaultAccess('allow')
security.__allow_access_to_unprotected_subobjects__ =3D 1
def SQLquery(query):
db =3D "zope"
server =3D "192.168.1.1"
port =3D 5432
sqluser =3D "zope"
sqlpassword =3D "********"
data =3D []
if query[0:6] =3D=3D "SELECT":
for output in
DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult():
result =3D objectChunk()
masterkeys =3D output.keys()
for key in masterkeys:
f =3D setattr(result, key, output[key])
data.append(result)
else:
SQLOUTPUT =3D DB(db,server,port,'',sqluser,sqlpassword).query(query)
return (data)
def manage_addA(self,id,name,description,REQUEST=3DNone):
obja =3D A(id,name,description)
self._setObject(id, obja)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
manage_addAForm =3D Globals.HTMLFile('dtml/add_obja', globals())
class A(
OFS.ObjectManager.ObjectManager,
OFS.PropertyManager.PropertyManager,
Acquisition.Implicit,
Persistent,
AccessControl.Role.RoleManager,
OFS.SimpleItem.Item,
):
a=3D()
manage_options=3D(
{'label':'Properties', 'action':'manage_main'},
{'label':'View', 'action':''},
) + OFS.SimpleItem.SimpleItem.manage_options
meta_type =3D 'Product'
index_html =3D Globals.HTMLFile("dtml/obja", globals())
#manage_main =3D Globals.HTMLFile("dtml/edit_obja", globals())
def __init__(self, id, name,description):
self.id =3D id
self.name =3D name
self.desc =3D description
def objectItems(self):
objQUERY =3D "SELECT * FROM B WHERE dgid =3D '" + self.id + "'"
QUERYRESULT =3D []
QUERYRESULT =3D SQLquery(objQUERY) =
a =3D []
for objects in QUERYRESULT:
tp =3D
B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_c=
reator,
objects.obj_created,objects.obj_moddate)
tpwrapper =3D [objects.id,tp]
a.append(tpwrapper)
return a =
def manage_beforeDelete(self,item,container):
QUERYSTRING =3D "DELETE FROM B WHERE dgid =3D '" + item.id + "'"
queryresult =3D SQLquery(QUERYSTRING)
## Right here ##
def _getOb(self,id,dp=3D2):
__allow_access_to_unprotected_subobjects__ =3D 1
nextobject =3D
B(self.id,id,"name","desc","creater","createrdate","moddate") =
return nextobject
## Right here
def _delObjects(self,id):
"This deletes the objects specified" =
print "In the _delObjects" =
def _delOb(self,id):
"This deletes the objects specified" =
SQLQUERY =3D "DELETE FROM B WHERE id =3D '" + id + "'"
INQUIRE =3D SQLquery(SQLQUERY)
Globals.default__class_init__(A)
Globals.default__class_init__(B)
Globals.InitializeClass(objectChunk)
B:
import Globals
from Globals import Persistent, Acquisition
import AccessControl
import OFS
from pg import DB
from AccessControl import ClassSecurityInfo
from Acquisition import Implicit
__allow_access_to_unprotected_subobjects__ =3D 1
class objectChunk(Implicit):
security =3D ClassSecurityInfo()
security.declareObjectPublic()
security.setDefaultAccess('allow')
security.__allow_access_to_unprotected_subobjects__ =3D 1
def SQLquery(query):
## change these when you change servers
db =3D "zope"
server =3D "192.168.1.1"
port =3D 5432
sqluser =3D "zope"
sqlpassword =3D "********"
data =3D []
if query[0:6] =3D=3D "SELECT":
for output in
DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult():
result =3D objectChunk()
masterkeys =3D output.keys()
for key in masterkeys:
f =3D setattr(result, key, output[key])
data.append(result)
else:
SQLOUTPUT =3D DB(db,server,port,'',sqluser,sqlpassword).query(query)
return (data)
def
manage_addB(self,dg_id,id,name,desc,creater,createrdate,moddate,REQUEST=3D=
None):
The argument 'self' will be bound to the parent Folder.
QUERYSTRING =3D "INSERT INTO C
(id,dgid,obj_name,obj_desc,obj_creator,obj_created,obj_moddate) VALUES
('"+id+"','"+dg_id+"','"+name+"','"+desc+"','"+creater+"','"+createrdate+=
"','"+m
oddate+"')"
print QUERYSTRING
SQLRETURN =3D SQLquery(QUERYSTRING)
if REQUEST is not None:
return self.manage_main(self, REQUEST)
manage_addTopicForm =3D Globals.HTMLFile('dtml/add_obj', globals())
class B(
OFS.ObjectManager.ObjectManager,
OFS.PropertyManager.PropertyManager, =
Acquisition.Implicit,
Persistent,
AccessControl.Role.RoleManager,
OFS.SimpleItem.Item,
):
a=3D()
manage_options=3D(
{'label':'Properties', 'action':'manage_main'},
{'label':'View', 'action':''},
) + OFS.SimpleItem.SimpleItem.manage_options
meta_type =3D 'Product 2'
index_html =3D Globals.HTMLFile("dtml/obj", globals())
manage_main =3D Globals.HTMLFile("dtml/edit_obj", globals())
def __init__(self,dg_id,id,name,desc,creater,createrdate,moddate):
self.dg_id =3D dg_id =
self.id =3D id
self.name =3D name
self.desc =3D desc
self.creater =3D creater
self.createdate =3D createrdate
self.moddate =3D moddate
__allow_access_to_unprotected_subobjects__ =3D 1
manage_workspace__roles__=3D('Manager','Anonymous',)
def objectItems(self):
objQUERY =3D "SELECT * FROM B WHERE dgid =3D '" + self.id + "'"
QUERYRESULT =3D []
QUERYRESULT =3D SQLquery(objQUERY)
a =3D []
for objects in QUERYRESULT:
tp =3D
B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_c=
reator,
objects.obj_created,objects.obj_moddate)
tpwrapper =3D [objects.id,tp]
a.append(tpwrapper)
return a
Globals.InitializeClass(objectChunk)
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=3D=
1