[Zope] Override members values

Garito garito at sistes.net
Mon Jul 10 13:13:19 EDT 2006


Jonathan escribió:
>
> ----- Original Message ----- From: "Garito" <garito at 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

What do you thing about?

-- 
Mis Cosas
http://blogs.sistes.net/Garito




More information about the Zope mailing list