Jonathan escribió:
----- Original Message ----- From: "Garito" <garito@sistes.net> To: "Lista Zope Internacional" <zope@zope.org> Sent: Monday, July 10, 2006 1:13 PM Subject: Re: [Zope] Override members values
Jonathan escribió:
----- Original Message ----- From: "Garito" <garito@sistes.net>
I try again:
I have a property on the property manager called member1 with a value of "[/some/path]"
User1 ask for this property. We calculate the real value for /some/path for these user: 1 User2 ask for this property. We calculate the real value for /some/path for these user: 2
I have a property on the property manager called member2 with a value of "[a reference to the calculator]"
A user ask for this property from his firefox. We calculate the real value for the reference for this browser: <result1> Another user ask for this property from his ie. We calculate the real value for the reference for this browser: <result2>
I would like to change the "accessor" for any property in my Zope product
How can I?
If I understand what you are trying to accomplish (of which I am not completely sure)...then you could create a script that accesses the object and returns a value based on the user agent string:
eg.
import string REQUEST = container.REQUEST
targetObject = context.restrictedTraverse('/some/path/objId')
if string.find(REQUEST['HTTP_USER_AGENT'], 'Firefox') != -1: <do something with targetObject.attribute for Firefox users) elif string.find(REQUEST['HTTP_USER_AGENT'], 'MSIE') != -1: <do something with targetObject.attribute for Internet Explorer users) else: <do something with targetObject.attribute for xxx users)
Note: 'attribute' is whatever property you have defined for the object.
hth
Jonathan
Good Jonathan, something like this is on my mind but where I need to put a piece of code like this?
__getattr__? __bobo_traverse__? another place?
I work with __bobo_traverse__ for some purposes but I would like a place like __getattr__ because is where I go when I need an object's member (__hasattr__ too) and __bobo_traverse__ need to returns an object not a value
__getattr__ some of you (I don't remember how exactly, sorry) have said is a member to use only if there are no other way and I'm a little scared for that
I have no idea how your application is designed/structured, but one possible solution is to create a python script and place it in the path to the object you want to access. For example, if the python script is called pScript then:
/some/path/pScript/objectId
the python script 'pScript' will get executed and can access a variable in REQUEST called 'traverse_subpath' - which is a list, and in the above case has only 1 element which is a string containing 'objectId'. You can then use this string in the restrictedTraverse command to get access to the object:
REQUEST = container.REQUEST targetObject = context.restrictedTraverse('/some/path/some/folder/'+ REQUEST['traverse_subpath'][0])
Jonathan
Sure, but I would like to put it to act like print Object.member and the value is the result of your code Where I put the code? If I want to override the () member of a object I override __call__, if I want to override the str(object) I override __str__, right? How can I override the object.<member> ? -- Mis Cosas http://blogs.sistes.net/Garito