Hi, Can anybody explain why my dynamically created attributes can't find their acquired attributes up the hierarchy? I have the following code ---8<------8<------8<------8<------8<------8<------8<--- class AcquTest(Acquisition.Implicit): "the implicitluy aquired one" __roles__ = None def __init__(self,color=None): if color: self.color = color def __getitem__(self,attr): if self.__class__.__dict__.has_key(attr): return self.__class__.__dict__[attr] if self.__dict__.has_key(attr): return self.__dict__[attr] try: return self.aq_acquire(attr) except: self.__dict__[attr] = AcquTest(attr) return self.__dict__[attr] local_html = HTML("<html>Local <!--#var color--></html>") index_html = HTML(""" <!--#var page_header--> <!--#var color--><br> <!--#var page_footer-->""") aq = AcquTest('orange') aq.page_header = HTML('<html><font color="<!--#var color-->" size=+3><b>') aq.page_footer = '</font></html>' aq.name = 'AQ root object' aq.a = AcquTest() aq.a.b = AcquTest('blue') aq.a.color= 'green' ---8<------8<------8<------8<------8<------8<------8<--- and when I access it through web as /aq , /aq/a or /aq/a/b it works as expected (prints orange, green and blue in respective coluor) but when i want to access a new attribute (retrieved from a database by attr in my real application), then it can't acquire the other attributes up the hierarchy. ie /aq/black does _not_ print black, instead it produces a traceback: Traceback (innermost last): File /usr/lib/python1.5/cgi_module_publisher.py, line 1457, in publish_module File /usr/lib/python1.5/cgi_module_publisher.py, line 933, in publish File /usr/lib/python1.5/DocumentTemplate/DT_String.py, line 471, in __call__ (Object: <string>) File /usr/lib/python1.5/DocumentTemplate/pDocumentTemplate.py, line 201, in render_blocks File /usr/lib/python1.5/DocumentTemplate/pDocumentTemplate.py, line 166, in __getitem__ File /usr/lib/python1.5/DocumentTemplate/pDocumentTemplate.py, line 135, in __getitem__ KeyError: page_header So obviously acquisition is not working for me here ;( Can anyone tell me what I'm doing wrong ? Or more importantly, how should I proceed to get the dynamically generated attributes into the acquisition mechanism? FWIW, the method local_html works fine. ---------------------- Hannu
participants (1)
-
Hannu Krosing