[Zope] Thanks! .... and a util to look at a property of a mirror branch from the original branch.

ÀÌ°ü¼ö kslee@plaza1.snu.ac.kr
Tue, 17 Aug 1999 20:33:45 +0900


Really thanks a lot for your hints & suggestions, although this bonehead failed 
to follow the suggestions. 

Strangely, michel's, John's and Anthony's suggestion did not work on
my Zope site. Now I wonder whether this is due to the difference between Zope 1.10.3  and Zope2.0x. Zope 1.10.3 gave me lots of tracebacks excepted from careful_getitem in DT_Util.py
;--(

But, unable to distinguish the bug in my head and the feature in Zope, I fell upon 
the external method, instead of going th Collector.

For a newbie or a more-boner head than mine, its code is at the bottom (hence nobody might use them, hughhh).

Thanks again for your concerns,

LEE Kwan Soo.

*****
An external method to inspect TR property of the corresponding DTML Document or Folder in the mirror branch. 

Usage: <!--#var "isTRed(REQUEST)"-->

If you call this method in the DTML Document  /korean/aaa/bbb/ccc/ddd, it inspect the TR property of /english/aaa/bbb/ccc/ddd and returns its value. If there is no TR property then it is set to '0'.
When called in the DTML Method /korean/aaa/bbb/ccc/mmm, It returns and, if needed, set the TR value of the Folder /english/aaa/bbb/ccc. 

/ (root) is the Zope root folder.
*****

from string import split

def isTRed(self, REQUEST):
        ulist = split(REQUEST.URL0, '/')[4:]  # if your Zope root folder is /Zope, replace 4 with 5.
        if ulist[-1] in self.objectIds(['DTML Document']): pass #see whether called in DDoc or DMet.
        else: ulist = ulist[:-1]
        obj = REQUEST.PARENTS[-1].english  #obj is the *mirror* branch. use your folder id
                                                                  # instead of 'english'. 
                                        # Is there a guru's way to refer to the root object in an external method?
        for i in range(len(ulist)):             #walked down in the *mirror* branch.
           xobj = getattr(obj, ulist[i])
           obj = xobj
        if hasattr(obj, 'TR'): pass           #chech if the obj(DDoc or Folder) has TR. use your property
        else:                                        # ID here.
                obj.manage_addProperty('TR', '0', 'string') #if not, set TR property. use your property
        return  obj.TR                                                    #ID & default value, type here.
*****
If any body use this external method, please improve this to prove mine is the bonest head in Zopeland.