Specialists and __bobo_traverse__
Recent sightings of the use of __bobo_traverse__ in SkinScript gave me hope of giving users a more useable breadcrumbs trail in the case where I have nested specialists. My TaskTemplates specialist is nested inside my RequestTypes specialist. When I retrieve a dataskin from the RequestTypes specialist I have a tab that lists TaskTemplates for that RequestType specialist. Following a link from the TaskTemplate list takes you to that instance. Thus results in a url like this: /RequestTypes/<request type instance>/Task Templates/<task template instance>, and what I ideally want is: /RequestTypes/<request type instance>/<task template instance>. I read all the comments about __bobo_traverse__ and created a python method, "traversal_method" inside the "RequestTypes" specialists. I must admit that I don't really understand Zope's traversal machinery yet and would appreciate some guidance. My SkinScript for RequestTypes: WITH SELF COMPUTE __bobo_traverse_=traversal_method My traversal_method: ob = getattr(self, name) if ob is not None: return ob else: ob = self.TaskTemplates.getItem(name) if ob is not None: return ob raise 'NotFound' Any help would be greatly appreciated. Roché
Roch'e Compaan wrote:
Recent sightings of the use of __bobo_traverse__ in SkinScript gave me hope of giving users a more useable breadcrumbs trail in the case where I have nested specialists.
My TaskTemplates specialist is nested inside my RequestTypes specialist. When I retrieve a dataskin from the RequestTypes specialist I have a tab that lists TaskTemplates for that RequestType specialist. Following a link from the TaskTemplate list takes you to that instance.
Thus results in a url like this: /RequestTypes/<request type instance>/Task Templates/<task template instance>, and what I ideally want is: /RequestTypes/<request type instance>/<task template instance>.
I read all the comments about __bobo_traverse__ and created a python method, "traversal_method" inside the "RequestTypes" specialists. I must admit that I don't really understand Zope's traversal machinery yet and would appreciate some guidance.
With your code below, and with a concrete example, can you say what you want to happen, and what actually does happen?
My SkinScript for RequestTypes:
WITH SELF COMPUTE __bobo_traverse_=traversal_method
You'll want another underscore in there: __bobo_traverse__
My traversal_method:
ob = getattr(self, name) if ob is not None: return ob
If ob is not found, you'll get an error raised. You need to have some sort of marker for the default value. marker=[] ob=getattr(self, name, marker) if ob is not marker: return ob # continue your method Of course, you only need one marker in your class. You can do that if you implement your method as an external method, or perhaps with a default value for an argument on you python method. Or, you could not worry about creating a new empty list on each request. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Chris Withers wrote:
Steve Alexander wrote:
If ob is not found, you'll get an error raised. You need to have some sort of marker for the default value.
Is there any reason why no-one uses None as a marker?
Yes. An attribute that exists can have the value None. class foo: bar=None You need to distinguish between this case, and the case where the attribute does not exist. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
With your code below, and with a concrete example, can you say what you want to happen, and what actually does happen?
Thus results in a url like this: /RequestTypes/<request type instance>/Task Templates/<task template instance>, and what I ideally want is: /RequestTypes/<request type instance>/<task template instance>.
Let's say I have a RequestType called "Evaluation of Product". For this request type I create Task Templates called "Record Customer Details" and "Ship Product to Customer". If I go to the Request Type "Evaluation of Product" the url is: path.to.requestypes/evaluation_of_product. This gives me the detail of the request type as well as the list of task templates relating to this request type. If I now follow the link to the task template "Record Customer Details", I simply want to click on a url that says path.to.requesttypes/evaluation_of_product/record_customer_details and do not explicitly want to go the TaskTemplates with path.to.requesttypes/evaluation_of_product/TaskTemplates/record_customer_det ails. In other words, my traversal_method for the RequestTypes specialist should first seek the object on it's own rack and if it can not find it is should ask the nested TaskTemplates specialist for the object. Roché
With your code below, and with a concrete example, can you say what you want to happen, and what actually does happen?
In my traversal_method I have one line that simply changes a property on the specialist to see if the method is actually called but it does not seem like the traversal_method is called at all. The skinscript I use (as said in my previous mail) is: WITH SELF COMPUTE __bobo_traverse__=traversal_method Roché
participants (3)
-
Chris Withers -
Roch'e Compaan -
Steve Alexander