Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'
Hello, in a product I try to make a file object persistent with the _setObject() method. However I get the error: Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd' The following is the code where the error occurs: cpu_load = self.getCpuLoad(id,location_sar,f_time,l_time) system.cpu_load_file=File(data=cpu_load[0], contentType='text/plain') self.tgt_folder[id]._setObject('cpu_load',system.cpu_load_file) This is done in the __init__ method of the class. The class subclasses from Folder and SimpleItem. self.tgt_folder[id] has been created a few lines above by: self.tgt_folder[id]=Folder() self._setObject(id,self.tgt_folder[id]) The container that holds self.tgt_folder[id] is a BTreesFolder2. I know that the file Object is pretty simple, but how can one create and persist it if not with the _setObject() method? Thanks in advance Roman
Hello, Roman Klesel schrieb:
Hello,
in a product I try to make a file object persistent with the _setObject() method.
However I get the error: Error Value: 'File' object has no attribute 'manage_fixupOwnershipAfterAdd'
I managed to fix this by crating my own _File class and subclassing from (SipleItem,File) however now the objects I persited show up as Type=SipmleItem and not File. Consequently they don't have the nice ZMI Interface of File objects :-( I'm really struggeling to get this working. Anyone wants to let me know how you create File objects from a product? Greetings Roman
Roman Klesel wrote:
Hello,
Roman Klesel schrieb:
Hello,
in a product I try to make a file object persistent with the _setObject() method.
What's wrong with: container.manage_addProduct['OFSP'].manage_addFile(id, file='', title='', precondition='', content_type='', REQUEST=None) -- bruno desthuilliers développeur bruno@modulix.org http://www.modulix.com
Hello Bruno, bruno desthuilliers schrieb:
What's wrong with:
container.manage_addProduct['OFSP'].manage_addFile(id, file='', title='', precondition='', content_type='', REQUEST=None)
Well, in a fs product I don't have container nor self.manage_addProduct or something (AFAIK). Therefore I use the ._setObject() method. Works fine with folderish objects (when i subclass from ObjectManager or Folder or ...) however this fails when I subclass from zope.app.file.File. Maybe zope.app.file.File is not the right class to subclass from. I greped through ?/lib/python many times and didn't find anything else. I would also be happy to do container.manage_addProduct[ ... what do I have to import to have this available? Thanks for your continuous effort to help me. Roman
On 16 Feb 2006, at 09:33, Roman Klesel wrote:
Hello Bruno,
bruno desthuilliers schrieb:
What's wrong with:
container.manage_addProduct['OFSP'].manage_addFile(id, file='', title='', precondition='', content_type='', REQUEST=None)
Well, in a fs product I don't have container nor self.manage_addProduct or something (AFAIK).
Therefore I use the ._setObject() method.
Instead of "container" you substitute the object that you called _setObject on before. No rocket science here. If that object subclasses from the normal Zope Folder class (or is a Zope Folder) you *will* have manage_addProduct. jens
Hello, Jens Vagelpohl schrieb:
If that object subclasses from the normal Zope Folder class (or is a Zope Folder) you *will* have manage_addProduct.
Yes, actually you guys a right! self.manage_addProduct is available... Hmmm ... wonder what made me think it's not ... Still I can't get what I want. when I now do: system.manage_addProduct['OFSP'].manage_addFile(fid, title='', file=cpu_load, content_type='text/plain', precondition='') I get: AttributeError: _getProducts So I poked around and rose an exception like this: raise KeyError, 'id: %s object: %s self: %s' % (id, system, self) KeyError: 'id: gr_sys object: <Folder at > self: <Lasttest at lasttest55004>' Where - id is the id of the folder where I want to create the file in. - object is the object reference of the same folder - and self ist ... self: a folderish object. So there seems to be something wrong with "object". It's recognized that it is a folder but for some reason it seems that it has no real object reference. It is created like this: self.tgt_folder[id]=Folder() self._setObject(id,self.tgt_folder[id]) Of course I should create it with the managed_addProduct[ ... method, but it doesn't work. I again get: AttributeError: _getProducts I'm getting more and more confused ... I mean the whole thing can't be totally wrong since everything worked exept for, that the objects that I wanted to have where of type "SimpleItem" and not "File". So there seems to be something wrong with by parent obejct ... But again this is also not possible since i can add a File product manually with the ZMI .. Any light s.o.? Roman
Please learn to read and to provide the *complete* traceback. The error text alone is not enough most of the time. Your error *may* mean that 'system' is not yet wrapped. Are your positive that 'system' is a folder that already exists in the ZODB, i.e. has already been _setObject'ed? Stefan On 16. Feb 2006, at 13:33, Roman Klesel wrote:
when I now do:
system.manage_addProduct['OFSP'].manage_addFile(fid, title='', file=cpu_load, content_type='text/plain', precondition='')
I get:
AttributeError: _getProducts
-- Anything that happens, happens. --Douglas Adams
Stefan H. Holek schrieb:
Please learn to read and to provide the *complete* traceback. The error text alone is not enough most of the time.
Ok, shure, I can do that, I just thought I'll clean out the parts that are not neccesary...
Your error *may* mean that 'system' is not yet wrapped. Are your positive that 'system' is a folder that already exists in the ZODB, i.e. has already been _setObject'ed?
As far as I can tell: Yes! First I have a loop that creates and _setObject the folders, then the next loop is supposed to loop over the folders and create files in them. The code looks like this: for id in self.manage_targets.keys(): title = self.manage_targets[id]['name'] self.tgt_folder=Folder() self._setObject(id,self.tgt_folder) grinder_home = self.manage_targets['gr_sys']['grinder_home'] host_name = self.getHostname(grinder_home) self.lt_time=self.getLttime('%s/script/log/out_%s-0.log' % (grinder_home,host_name)) self.title = self.lt_time[0].split(' ')[0] self.order = ''.join(self.title.split('/')) self.version = "unknown" f_time=self.lt_time[0].split(' ')[1] l_time=self.lt_time[1].split(' ')[1] for id in self.objectIds('Folder'): location_sar = self.manage_targets[id]['location_sar'] phy_mem = self.manage_targets[id]['phy_mem'] system = self.__getitem__(id) cpu_load = self.getCpuLoad(id,location_sar,f_time,l_time) fid='cpu_load' try: system.manage_addProduct['OFSP'].manage_addFile(fid, title='', file=cpu_load[0], content_type='text/plain', precondition='') except: raise KeyError, 'id: %s object: %s self: %s' % (id, system, self) And the error: 2006-02-16 14:11:16 ERROR Zope.SiteErrorLog http://last1.wz.qsu.nb:8080/asdf/test3/cnt/newLasttest Traceback (most recent call last): File "/opt/zope-2.9/lib/python/ZPublisher/Publish.py", line 113, in publish request, bind=1) File "/opt/zope-2.9/lib/python/ZPublisher/mapply.py", line 88, in mapply if debug is not None: return debug(object,args,context) File "/opt/zope-2.9/lib/python/ZPublisher/Publish.py", line 40, in call_object result=apply(object,args) # Type s<cr> to step into published object. File "/usr/local/share/zope/zlast/Products/ZLTMS/Controller.py", line 43, in newLasttest lt.importData() File "/usr/local/share/zope/zlast/Products/ZLTMS/LTimport.py", line 63, in importData raise KeyError, 'id: %s object: %s self: %s' % (id, system, self) KeyError: 'id: gr_sys object: <Folder at > self: <Lasttest at lasttest7816>' Greetings Roman
Hello, one more thing ... Roman Klesel schrieb:
Your error *may* mean that 'system' is not yet wrapped. Are your positive that 'system' is a folder that already exists in the ZODB, i.e. has already been _setObject'ed?
As far as I can tell: Yes!
Actually I'm pretty shure, because as I said: the whole thing ran successfully with _setObject() but in order to get a File Produkt I took the advice to use manage_addProduct[... and that's where I'm stuck ... Roman
Roman Klesel wrote:
for id in self.manage_targets.keys(): title = self.manage_targets[id]['name'] self.tgt_folder=Folder()
This is dangerous...
self._setObject(id,self.tgt_folder)
This is silly... Why not just: self.manage_addFolder(id,title)
grinder_home = self.manage_targets['gr_sys']['grinder_home'] host_name = self.getHostname(grinder_home)
Okay, what type of object is 'self' here, where did you take this code from?
for id in self.objectIds('Folder'): location_sar = self.manage_targets[id]['location_sar'] phy_mem = self.manage_targets[id]['phy_mem'] system = self.__getitem__(id)
why not just: system=self[id] ? Also, this will result in system not being acquisition wrapped in some circumstances, what you really want is: system = getattr(self,id) ...but it really depends on what 'self' is, I'm not sure you have that right. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris Withers schrieb:
for id in self.manage_targets.keys(): title = self.manage_targets[id]['name'] self.tgt_folder=Folder()
This is dangerous...
Why is that?
self._setObject(id,self.tgt_folder)
This is silly...
What's silly about persisting the object I just created?
Why not just:
self.manage_addFolder(id,title)
Well, the suggestion I got was to do: self.manage_addProduct['OFSP'].manage_addFolder(... and this runs in the "Error Value: _getProducts" Error.
grinder_home = self.manage_targets['gr_sys']['grinder_home'] host_name = self.getHostname(grinder_home)
Okay, what type of object is 'self' here, where did you take this code from?
I'm proud to say: I wrote this myself. :-) self is supposed to be a foldeish object that is supposed to be the container for all objects I'm about to create in this routine.
system = self.__getitem__(id)
why not just:
system=self[id]
Great! Didn't know that!
Also, this will result in system not being acquisition wrapped in some circumstances, what you really want is:
system = getattr(self,id)
...but it really depends on what 'self' is, I'm not sure you have that right.
This also works. However to me it looks like, it produces the exact same result as __getitem__ and self[id] ... This "being acquisition wrapped" is driving me nuts! I just don't get it. And I belive it's the cause for the problems I'm facing ... Thanks for taking the time analyzing my code! Greetings Roman
Roman Klesel wrote:
Chris Withers schrieb:
for id in self.manage_targets.keys(): title = self.manage_targets[id]['name'] self.tgt_folder=Folder()
This is dangerous...
Why is that?
'cos arbitarilly assigning objects to attributes without understanding acquisition of the pseudo-interfaces you need to adhere to in Zope will mean this _will_ bite you later...
Why not just:
self.manage_addFolder(id,title)
Well, the suggestion I got was to do:
self.manage_addProduct['OFSP'].manage_addFolder(...
They're the same thing really...
and this runs in the "Error Value: _getProducts" Error.
Yes, because, almost certainly, 'self' above was not acquisition wrapped.
Okay, what type of object is 'self' here, where did you take this code from?
I'm proud to say: I wrote this myself. :-)
Well, you did it wrong... show us soem code and we can fix it.
system = getattr(self,id)
...but it really depends on what 'self' is, I'm not sure you have that right.
This also works. However to me it looks like, it produces the exact same result as __getitem__ and self[id] ...
_don't_ count on it...
This "being acquisition wrapped" is driving me nuts! I just don't get it.
Then go use PHP ;-)
And I belive it's the cause for the problems I'm facing ...
Yes, stop fighting the framework ;-) Take some existing examples and try and adapt them rather than starting from scratch with everything... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Hello again, I works! I just managed to get everything as I expected it to be. How I did it: form OFS.Image import File - I build a class _File(File): - pimped it up a little bit. - instatiated it - _setObject'ed it ... et voila I have nice File-objects with nice CMI interface... Thanks for holding my hand. Greetings Roman
Roman Klesel wrote:
form OFS.Image import File
- I build a class _File(File):
I really doubt you need to do that...
- pimped it up a little bit.
What, specifically, did you add?
- _setObject'ed it
You shouldn't be calling that directly... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (5)
-
bruno desthuilliers -
Chris Withers -
Jens Vagelpohl -
Roman Klesel -
Stefan H. Holek