Getting aquisition values from object attribute
I have a product which has an object attribute that is an object. Just like HTMLFile() or similar. I need to get the aquisition values from the parent object. How on earth do I do that? Pseudocode class MyAttr: def title(self) "I need to get ie. title value from 'MyProduct'" return # ????? class MyProduct: my_attr = MyAttr() regards Max M
On Monday 24 March 2003 11:01 am, Max M wrote:
I have a product which has an object attribute that is an object. Just like HTMLFile() or similar.
I need to get the aquisition values from the parent object. How on earth do I do that?
Pseudocode
import Acquisition class MyAttr(Acqusition.Implicit):
def title(self) "I need to get ie. title value from 'MyProduct'" return # ?????
class MyProduct(Acqusition.Implicit):
my_attr = MyAttr()
-- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
Toby Dickenson wrote:
On Monday 24 March 2003 11:01 am, Max M wrote:
I have a product which has an object attribute that is an object. Just like HTMLFile() or similar.
I need to get the aquisition values from the parent object. How on earth do I do that?
Pseudocode
import Acquisition
class MyAttr(Acqusition.Implicit):
Doh! slap! Off course ,,, thank you. regards Max M
Toby Dickenson wrote:
import Acquisition
class MyAttr(Acqusition.Implicit):
Ok ... I have changed my class to the code below (only relevant code shown): But it gives me a recursion error. I have no ide as to why: regards Max M from Acquisition import Implicit class I18nBase(Implicit): textBundle = {} __allow_access_to_unprotected_subobjects__=1 def __getitem__(self, textId): """ Takes a short text id and returns a string in the selected language """ default_language = 'dk' error_msg = '<font color="red"><b>TRANSLATION MISSING</b></font>' language = getattr(self, 'language', default_language) return self.textBundle.get( language, default_language).get(textId, error_msg) class Test_i18n(I18nBase): "i18n for the test page" t = {} t['dk'] = {} t['uk'] = {} t['dk']['hello'] = 'Hej verden' t['uk']['hello'] = 'Hello World' ###################### class ots_Department(TheUsualZopeClasses): "A normal working Zope product" test = PageTemplateFile('zpt/test', globals()) test_i18n = Test_i18n() ###################### ## test.zpt <span tal:define="i18n here/test_i18n"> <span tal:replace="i18n/hello">Hej verden</span> </span>
At 12:01 2003-03-24 +0100, Max M said:
I have a product which has an object attribute that is an object. Just like HTMLFile() or similar.
I need to get the aquisition values from the parent object. How on earth do I do that?
Pseudocode
class MyAttr:
def title(self) "I need to get ie. title value from 'MyProduct'" return # ?????
class MyProduct:
my_attr = MyAttr()
I addition to You may need using Acquisition.Implicit you might need to use aq_parent. Or remove the title method alltogether. from Acquisition import Implicit, aq_parent class MyAttr(Implicit): def title(self) "I need to get ie. title value from 'MyProduct'" return aq_parent(self).title class MyProduct: my_attr = MyAttr() Regards, Johan Carlsson -- Easy Publisher Developers Team Johan Carlsson johanc@easypublisher.com Mail: Birkagatan 9 SE-113 36 Stockholm Sweden Phone +46-(0)8-32 31 23 Fax +46-(0)8-32 31 83 Mobil +46-(0)70-558 25 24 http://www.easypublisher.com
Johan Carlsson [EasyPublisher] wrote:
I addition to You may need using Acquisition.Implicit you might need to use aq_parent. Or remove the title method alltogether.
Yes ... thanks. But it isn't really the title attribute I am after, so it will not be a problem regards Max M
participants (3)
-
Johan Carlsson [EasyPublisher] -
Max M -
Toby Dickenson