[Zope3-Users] Re: catalog of objects' states (hurry.workflow)
Alek Kowalczyk schrieb: Hello again, I have a rather big tree of MyObjects. MyObjects are adaptable to hurry.workflow's IWorklowState. Now I'd like to create a catalog to index all MyObjects by their current states. How to do that? An option might be(?) to add to MyObject property like that: @property def currentState(self): return IWorkflowState(self).getState() and index this property. But I'm not sure whether it is elegant solution, as it requires the object to know that it has workflow and (too) strong link between object and adapter. I'll appreciate any suggestions how to index workflow states cleanly and not in too complictated way... Regards! i use the @property solution, because i got into troubles with annotations and the catalog. see the unanswered post http://mail.zope.org/pipermail/zope3-users/2007-March/005925.html cheers Dominique ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: catalog of objects' states (hurry.workflow)
Philipp von Weitershausen wrote: Alek Kowalczyk wrote: Hello again, I have a rather big tree of MyObjects. MyObjects are adaptable to hurry.workflow's IWorklowState. Now I'd like to create a catalog to index all MyObjects by their current states. How to do that? An option might be(?) to add to MyObject property like that: @property def currentState(self): return IWorkflowState(self).getState() and index this property. But I'm not sure whether it is elegant solution, as it requires the object to know that it has workflow and (too) strong link between object and adapter. Right. Fortunately, indexes know how to adapt. So, in order to index the workflow state of your objects, configure a FieldIndex (or ValueIndex from zc.catalog) to the IWorkflowState interface. Specify the 'getState' attribute and check the 'callable' option (because it's a method). When encountering an object to be indexed, the FieldIndex (or ValueIndex) will then try to adapt it to IWorkflowState. If that succeeds (and it will for your MyObjects), it will call the getState () method on that adapter and index the return value. That worked for me with zope.app.catalog: catalog = Catalog() catalog[u'workflow_state'] = FieldIndex(interface=IWorkflowState, field_name='getState', field_callable=True) ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Re: catalog of objects' states (hurry.workflow)
Alek Kowalczyk wrote: Hello again, I have a rather big tree of MyObjects. MyObjects are adaptable to hurry.workflow's IWorklowState. Now I'd like to create a catalog to index all MyObjects by their current states. How to do that? An option might be(?) to add to MyObject property like that: @property def currentState(self): return IWorkflowState(self).getState() and index this property. But I'm not sure whether it is elegant solution, as it requires the object to know that it has workflow and (too) strong link between object and adapter. Right. Fortunately, indexes know how to adapt. So, in order to index the workflow state of your objects, configure a FieldIndex (or ValueIndex from zc.catalog) to the IWorkflowState interface. Specify the 'getState' attribute and check the 'callable' option (because it's a method). When encountering an object to be indexed, the FieldIndex (or ValueIndex) will then try to adapt it to IWorkflowState. If that succeeds (and it will for your MyObjects), it will call the getState() method on that adapter and index the return value. This and more is described in my book, btw: http://worldcookery.com -- http://worldcookery.com -- Professional Zope documentation and training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users