Re: Product Creation and Permission]
Which I think is directly related to what I am experiencing with getting 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 this 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 if this is possible or not: In A, in _getOb (currently encapuslated with ## Right here ##), I have been 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 is 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 = 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 not sure which ones are there nor what properties exist on A (other than A.REQUEST). How can one copy objects such that B = 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__ = 1 class objectChunk(Implicit): security = ClassSecurityInfo() security.declareObjectPublic() security.setDefaultAccess('allow') security.__allow_access_to_unprotected_subobjects__ = 1 def SQLquery(query): db = "zope" server = "192.168.1.1" port = 5432 sqluser = "zope" sqlpassword = "********" data = [] if query[0:6] == "SELECT": for output in DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult(): result = objectChunk() masterkeys = output.keys() for key in masterkeys: f = setattr(result, key, output[key]) data.append(result) else: SQLOUTPUT = DB(db,server,port,'',sqluser,sqlpassword).query(query) return (data) def manage_addA(self,id,name,description,REQUEST=None): obja = A(id,name,description) self._setObject(id, obja) if REQUEST is not None: return self.manage_main(self, REQUEST) manage_addAForm = Globals.HTMLFile('dtml/add_obja', globals()) class A( OFS.ObjectManager.ObjectManager, OFS.PropertyManager.PropertyManager, Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.SimpleItem.Item, ): a=() manage_options=( {'label':'Properties', 'action':'manage_main'}, {'label':'View', 'action':''}, ) + OFS.SimpleItem.SimpleItem.manage_options meta_type = 'Product' index_html = Globals.HTMLFile("dtml/obja", globals()) #manage_main = Globals.HTMLFile("dtml/edit_obja", globals()) def __init__(self, id, name,description): self.id = id self.name = name self.desc = description def objectItems(self): objQUERY = "SELECT * FROM B WHERE dgid = '" + self.id + "'" QUERYRESULT = [] QUERYRESULT = SQLquery(objQUERY) a = [] for objects in QUERYRESULT: tp = B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_creator, objects.obj_created,objects.obj_moddate) tpwrapper = [objects.id,tp] a.append(tpwrapper) return a def manage_beforeDelete(self,item,container): QUERYSTRING = "DELETE FROM B WHERE dgid = '" + item.id + "'" queryresult = SQLquery(QUERYSTRING) ## Right here ## def _getOb(self,id,dp=2): __allow_access_to_unprotected_subobjects__ = 1 nextobject = 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 = "DELETE FROM B WHERE id = '" + id + "'" INQUIRE = 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__ = 1 class objectChunk(Implicit): security = ClassSecurityInfo() security.declareObjectPublic() security.setDefaultAccess('allow') security.__allow_access_to_unprotected_subobjects__ = 1 def SQLquery(query): ## change these when you change servers db = "zope" server = "192.168.1.1" port = 5432 sqluser = "zope" sqlpassword = "********" data = [] if query[0:6] == "SELECT": for output in DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult(): result = objectChunk() masterkeys = output.keys() for key in masterkeys: f = setattr(result, key, output[key]) data.append(result) else: SQLOUTPUT = DB(db,server,port,'',sqluser,sqlpassword).query(query) return (data) def manage_addB(self,dg_id,id,name,desc,creater,createrdate,moddate,REQUEST=None): The argument 'self' will be bound to the parent Folder. QUERYSTRING = "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 = SQLquery(QUERYSTRING) if REQUEST is not None: return self.manage_main(self, REQUEST) manage_addTopicForm = Globals.HTMLFile('dtml/add_obj', globals()) class B( OFS.ObjectManager.ObjectManager, OFS.PropertyManager.PropertyManager, Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.SimpleItem.Item, ): a=() manage_options=( {'label':'Properties', 'action':'manage_main'}, {'label':'View', 'action':''}, ) + OFS.SimpleItem.SimpleItem.manage_options meta_type = 'Product 2' index_html = Globals.HTMLFile("dtml/obj", globals()) manage_main = Globals.HTMLFile("dtml/edit_obj", globals()) def __init__(self,dg_id,id,name,desc,creater,createrdate,moddate): self.dg_id = dg_id self.id = id self.name = name self.desc = desc self.creater = creater self.createdate = createrdate self.moddate = moddate __allow_access_to_unprotected_subobjects__ = 1 manage_workspace__roles__=('Manager','Anonymous',) def objectItems(self): objQUERY = "SELECT * FROM B WHERE dgid = '" + self.id + "'" QUERYRESULT = [] QUERYRESULT = SQLquery(objQUERY) a = [] for objects in QUERYRESULT: tp = B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_creator, objects.obj_created,objects.obj_moddate) tpwrapper = [objects.id,tp] a.append(tpwrapper) return a Globals.InitializeClass(objectChunk) ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1
Jason Joy wrote:
Which I think is directly related to what I am experiencing with getting 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 this 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 if this is possible or not:
In A, in _getOb (currently encapuslated with ## Right here ##), I have been 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 is 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 = 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 not sure which ones are there nor what properties exist on A (other than A.REQUEST). How can one copy objects such that B = self? Even this I am not sure because object B has to be created by what is defined in class B... Any thoughts?
This should be easily solvable using acquisition. I think B is not an acquisition wrapper of A looking at your code. Perhaps try: ## Right here ## def _getOb(self,id,dp=2): nextobject = B(self.id,id,"name","desc","creater","createrdate","moddate") return nextobject.__of__(self) ## Right here The __of__() method of acquistion makes one object wrap another. Zope expects subordinate objects to acquire their parents.
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__ = 1
class objectChunk(Implicit): security = ClassSecurityInfo() security.declareObjectPublic() security.setDefaultAccess('allow') security.__allow_access_to_unprotected_subobjects__ = 1
def SQLquery(query): db = "zope" server = "192.168.1.1" port = 5432 sqluser = "zope" sqlpassword = "********"
data = []
if query[0:6] == "SELECT": for output in DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult(): result = objectChunk() masterkeys = output.keys() for key in masterkeys: f = setattr(result, key, output[key]) data.append(result) else: SQLOUTPUT = DB(db,server,port,'',sqluser,sqlpassword).query(query)
return (data)
def manage_addA(self,id,name,description,REQUEST=None): obja = A(id,name,description) self._setObject(id, obja) if REQUEST is not None: return self.manage_main(self, REQUEST)
manage_addAForm = Globals.HTMLFile('dtml/add_obja', globals())
class A( OFS.ObjectManager.ObjectManager, OFS.PropertyManager.PropertyManager, Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.SimpleItem.Item, ):
a=() manage_options=( {'label':'Properties', 'action':'manage_main'}, {'label':'View', 'action':''}, ) + OFS.SimpleItem.SimpleItem.manage_options
meta_type = 'Product'
index_html = Globals.HTMLFile("dtml/obja", globals()) #manage_main = Globals.HTMLFile("dtml/edit_obja", globals())
def __init__(self, id, name,description):
self.id = id self.name = name self.desc = description
def objectItems(self):
objQUERY = "SELECT * FROM B WHERE dgid = '" + self.id + "'"
QUERYRESULT = [] QUERYRESULT = SQLquery(objQUERY) a = [] for objects in QUERYRESULT: tp = B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_creator, objects.obj_created,objects.obj_moddate) tpwrapper = [objects.id,tp] a.append(tpwrapper) return a
def manage_beforeDelete(self,item,container): QUERYSTRING = "DELETE FROM B WHERE dgid = '" + item.id + "'" queryresult = SQLquery(QUERYSTRING)
## Right here ## def _getOb(self,id,dp=2): __allow_access_to_unprotected_subobjects__ = 1 nextobject = 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 = "DELETE FROM B WHERE id = '" + id + "'" INQUIRE = 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__ = 1
class objectChunk(Implicit): security = ClassSecurityInfo() security.declareObjectPublic() security.setDefaultAccess('allow') security.__allow_access_to_unprotected_subobjects__ = 1
def SQLquery(query): ## change these when you change servers db = "zope" server = "192.168.1.1" port = 5432 sqluser = "zope" sqlpassword = "********"
data = []
if query[0:6] == "SELECT": for output in DB(db,server,port,'',sqluser,sqlpassword).query(query).dictresult(): result = objectChunk() masterkeys = output.keys() for key in masterkeys: f = setattr(result, key, output[key]) data.append(result) else: SQLOUTPUT = DB(db,server,port,'',sqluser,sqlpassword).query(query) return (data)
def manage_addB(self,dg_id,id,name,desc,creater,createrdate,moddate,REQUEST=None): The argument 'self' will be bound to the parent Folder. QUERYSTRING = "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 = SQLquery(QUERYSTRING) if REQUEST is not None: return self.manage_main(self, REQUEST)
manage_addTopicForm = Globals.HTMLFile('dtml/add_obj', globals())
class B( OFS.ObjectManager.ObjectManager, OFS.PropertyManager.PropertyManager, Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.SimpleItem.Item, ):
a=()
manage_options=( {'label':'Properties', 'action':'manage_main'}, {'label':'View', 'action':''}, ) + OFS.SimpleItem.SimpleItem.manage_options
meta_type = 'Product 2'
index_html = Globals.HTMLFile("dtml/obj", globals()) manage_main = Globals.HTMLFile("dtml/edit_obj", globals())
def __init__(self,dg_id,id,name,desc,creater,createrdate,moddate): self.dg_id = dg_id self.id = id self.name = name self.desc = desc self.creater = creater self.createdate = createrdate self.moddate = moddate __allow_access_to_unprotected_subobjects__ = 1 manage_workspace__roles__=('Manager','Anonymous',)
def objectItems(self):
objQUERY = "SELECT * FROM B WHERE dgid = '" + self.id + "'"
QUERYRESULT = [] QUERYRESULT = SQLquery(objQUERY) a = [] for objects in QUERYRESULT: tp = B(objects.id,objects.dgid,objects.obj_name,objects.obj_desc,objects.obj_creator, objects.obj_created,objects.obj_moddate) tpwrapper = [objects.id,tp] a.append(tpwrapper) return a
Globals.InitializeClass(objectChunk)
____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1
-- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
participants (2)
-
Casey Duncan -
Jason Joy