Hi all! I need to override the value of some members of my product I think the correct way was __getattr__ function but I read some list's messages telling to use __getattr__ only if you don't have other way How can I override only the value of some dynamic members? I call dynamic members to the members that the user adds (with a property or an object) Why? Because I would like things like: Object.member1 -> 1 (if you are a manager) Object.member1 -> 2 (if you are a normal user) or Object.member1 -> 1 (for firefox users) Object.member1 -> 2 (for ie users) Where member1 is a property at property manager (for example) Thank so much! -- Mis Cosas http://blogs.sistes.net/Garito
--On 10. Juli 2006 08:38:15 +0200 Garito <garito@sistes.net> wrote:
Hi all! I need to override the value of some members of my product
I think the correct way was __getattr__ function but I read some list's messages telling to use __getattr__ only if you don't have other way
The standard Zope users objects don't provide an API for additional attributes. CMF/Plone provide such support through portal_memberdata.
How can I override only the value of some dynamic members
I call dynamic members to the members that the user adds (with a property or an object)
What are dynamic members? This is not a term used in the Zope world. -aj
Andreas Jung escribió:
--On 10. Juli 2006 08:38:15 +0200 Garito <garito@sistes.net> wrote:
Hi all! I need to override the value of some members of my product
I think the correct way was __getattr__ function but I read some list's messages telling to use __getattr__ only if you don't have other way
The standard Zope users objects don't provide an API for additional attributes. CMF/Plone provide such support through portal_memberdata.
How can I override only the value of some dynamic members
I call dynamic members to the members that the user adds (with a property or an object)
What are dynamic members? This is not a term used in the Zope world.
-aj
I would like to pre-process the member. A dynamic member (sorry for the term) is pre-processed member I would like to create some properties like: object.member1 = "[/some/path]" but I would like to retrive the content of /some/path when I'm asking for object.member1 -- Mis Cosas http://blogs.sistes.net/Garito
--On 10. Juli 2006 09:07:58 +0200 Garito <garito@sistes.net> wrote:
Andreas Jung escribió:
--On 10. Juli 2006 08:38:15 +0200 Garito <garito@sistes.net> wrote:
Hi all! I need to override the value of some members of my product
I think the correct way was __getattr__ function but I read some list's messages telling to use __getattr__ only if you don't have other way
The standard Zope users objects don't provide an API for additional attributes. CMF/Plone provide such support through portal_memberdata.
How can I override only the value of some dynamic members
I call dynamic members to the members that the user adds (with a property or an object)
What are dynamic members? This is not a term used in the Zope world.
-aj
I would like to pre-process the member. A dynamic member (sorry for the term) is pre-processed member
pre-process?
I would like to create some properties like:
object.member1 = "[/some/path]"
members? In the Zope context we talk of "users". "members" are a CMF term. And users aren't attributes of objects. Really no idea what you want to achive... -aj
Andreas Jung escribió:
--On 10. Juli 2006 09:07:58 +0200 Garito <garito@sistes.net> wrote:
Andreas Jung escribió:
--On 10. Juli 2006 08:38:15 +0200 Garito <garito@sistes.net> wrote:
Hi all! I need to override the value of some members of my product
I think the correct way was __getattr__ function but I read some list's messages telling to use __getattr__ only if you don't have other way
The standard Zope users objects don't provide an API for additional attributes. CMF/Plone provide such support through portal_memberdata.
How can I override only the value of some dynamic members
I call dynamic members to the members that the user adds (with a property or an object)
What are dynamic members? This is not a term used in the Zope world.
-aj
I would like to pre-process the member. A dynamic member (sorry for the term) is pre-processed member
pre-process?
I would like to create some properties like:
object.member1 = "[/some/path]"
members? In the Zope context we talk of "users". "members" are a CMF term. And users aren't attributes of objects.
Really no idea what you want to achive...
-aj
Hi again! Sorry for my vocabulary 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? Thank you and sorry for my poor english expression -- Mis Cosas http://blogs.sistes.net/Garito
----- 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
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 What do you thing about? -- Mis Cosas http://blogs.sistes.net/Garito
----- 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
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
Garito escribió:
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> ?
Perhaps like this? (the __get__ member?) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/408713 This will be the best solution? -- Mis Cosas http://blogs.sistes.net/Garito
----- Original Message ----- From: "Garito" <garito@sistes.net> To: "Lista Zope Internacional" <zope@zope.org> Sent: Monday, July 10, 2006 1:48 PM Subject: Re: [Zope] Override members values
Garito escribió:
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> ?
Perhaps like this? (the __get__ member?) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/408713
This will be the best solution?
Try it and see if it works for you!
On 7/10/06, Garito <garito@sistes.net> wrote:
__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 think there's no "official" (as in "provided by the framework") support for what you want. If you are too scared to implement some proof-of-concept which involves good testing covering your use case, you should think about another way to implement what you need. you could also use __getattribute__(), this way you can also have "dynamic" methods. http://docs.python.org/ref/new-style-attribute-access.html don't know how ZODB copes with this. or whether one needs to worry about that. --knitti
knitti escribió:
On 7/10/06, Garito <garito@sistes.net> wrote:
__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 think there's no "official" (as in "provided by the framework") support for what you want. If you are too scared to implement some proof-of-concept which involves good testing covering your use case, you should think about another way to implement what you need.
you could also use __getattribute__(), this way you can also have "dynamic" methods. http://docs.python.org/ref/new-style-attribute-access.html
don't know how ZODB copes with this. or whether one needs to worry about that.
--knitti Hi knitti!
__getattribute__ could be good (I test it and I like the way if there are anyone with a better one) Now my question is: There are any way to distinguish when the property is called by ZMI or FTP or another "system" call (about Zope) from the property when is called outside ZMI? Now I have a property like: object.Property1 = '[/some/path]' with the __getattribute__ override I can do print object.Property1 and the result is ok (the result of /some/path) but now if I go to property tab of the object I can't see ['/some/path'] or raise an error telling Property1 is not a member What I would like to create is an object that in the ZMI has some property values but when this properties are called the returns the execution of the path (like macro expansion or similar) Is this possible to do? -- Mis Cosas http://blogs.sistes.net/Garito
On 7/10/06, Garito <garito@sistes.net> wrote:
knitti escribió: There are any way to distinguish when the property is called by ZMI or FTP or another "system" call (about Zope) from the property when is called outside ZMI?
not that I'm aware of.
Now I have a property like:
object.Property1 = '[/some/path]'
with the __getattribute__ override I can do
print object.Property1
and the result is ok (the result of /some/path) but now if I go to property tab of the object I can't see ['/some/path'] or raise an error telling Property1 is not a member
because a property of a 'Zope object' (for the lack of better terms) is actually an entry in a PropertySheet instance. You _really_ want to use manage_addProperty() / manage_changeProperties() for those.
What I would like to create is an object that in the ZMI has some property values but when this properties are called the returns the execution of the path (like macro expansion or similar)
Is this possible to do?
I don't understand this question --knitti
----- Original Message ----- From: "knitti" <knitti@gmail.com> To: "Garito" <garito@sistes.net> Cc: <zope@zope.org> Sent: Tuesday, July 11, 2006 7:38 AM Subject: Re: [Zope] Override members values
On 7/10/06, Garito <garito@sistes.net> wrote:
knitti escribió: There are any way to distinguish when the property is called by ZMI or FTP or another "system" call (about Zope) from the property when is called outside ZMI?
not that I'm aware of.
You could check to see if HTTP_REFERER exists, and if it does exist does it contain 'manage' - this will get most of the ZMI interactions, but to be sure you could force all of your ZMI usage thru a different port. Jonathan
knitti escribió:
On 7/10/06, Garito <garito@sistes.net> wrote:
knitti escribió: There are any way to distinguish when the property is called by ZMI or FTP or another "system" call (about Zope) from the property when is called outside ZMI?
not that I'm aware of.
Now I have a property like:
object.Property1 = '[/some/path]'
with the __getattribute__ override I can do
print object.Property1
and the result is ok (the result of /some/path) but now if I go to property tab of the object I can't see ['/some/path'] or raise an error telling Property1 is not a member
because a property of a 'Zope object' (for the lack of better terms) is actually an entry in a PropertySheet instance. You _really_ want to use manage_addProperty() / manage_changeProperties() for those.
What I would like to create is an object that in the ZMI has some property values but when this properties are called the returns the execution of the path (like macro expansion or similar)
Is this possible to do?
I don't understand this question
--knitti Sure. At the spanish list someone has a private (his costumer don't want to share it) PropertyManagerWithTALES
In this class the properties are TALES expressions I need something like it I put the TALES expression in the Property Sheet tab but the data retrieved is the execution of the TALES expression Any idea? -- Mis Cosas http://blogs.sistes.net/Garito
participants (4)
-
Andreas Jung -
Garito -
Jonathan -
knitti