Re: [Zope3-Users] Design question (object or interface for category implementation?)
Christophe Combelles a écrit : Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? I've finally mixed 3) and 4) : I have defined ICompany(Interface), IClient(ICompany), IProvider(ICompany) And I have an ICompanyType(IInterface) interface type I've set the type of IClient and IProvider as ICompanyType in zcml. ICompany has a types attribute, for which I've redefined __getattr__ and __setattr_: __getattr__ retrieve the ICompanyType interfaces from the object __setattr__ calls noLongerProvides then alsoProvides to change the interfaces. then I have a Vocabulary which creates terms from all the interfaces whose type is ICompanyType, and I use this vocabulary with a list+choice field and a MultiCheckBoxWidget. This way, the admin users can directly change the interfaces provided by company objects, so that the menu and UI can automatically adapt to it. However, I wonder the following: if an interface that defines some attributes is first assigned to an object, then this attributes are written, then the interface is removed and replaced by another one (eg: client that becomes a provider), what will the first attributes become? Christophe BTW, there is a problem with custom_widget and MultiCheckBoxWidget: MultiCheckBoxWidget has to be wrapped in a custom widget to correctly set the number of arguments. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
Christophe Combelles wrote: Christophe Combelles a écrit : Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? I've finally mixed 3) and 4) : I have defined ICompany(Interface), IClient(ICompany), IProvider(ICompany) And I have an ICompanyType(IInterface) interface type I've set the type of IClient and IProvider as ICompanyType in zcml. ICompany has a types attribute, for which I've redefined __getattr__ and __setattr_: __getattr__ retrieve the ICompanyType interfaces from the object __setattr__ calls noLongerProvides then alsoProvides to change the interfaces. I think that it's not work: alsoProvides and directlyProvides change interfaces only in memory, it's not persistent changes (after restart Zope yours object will be only basic interface) . (sorry my honor english). ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re[2]: [Zope3-Users] Design question (object or interface for category implementation?)
Hello, directlyProvides is surely persistent. Make a site works like this. zope.interface.directlyProvides( self, interfaces.ISite, zope.interface.directlyProvidedBy(self)) Friday, March 9, 2007, 3:30:46 PM, you wrote: GM Christophe Combelles wrote: Christophe Combelles a écrit : Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? I've finally mixed 3) and 4) : I have defined ICompany(Interface), IClient(ICompany), IProvider(ICompany) And I have an ICompanyType(IInterface) interface type I've set the type of IClient and IProvider as ICompanyType in zcml. ICompany has a types attribute, for which I've redefined __getattr__ and __setattr_: __getattr__ retrieve the ICompanyType interfaces from the object __setattr__ calls noLongerProvides then alsoProvides to change the interfaces. GM I think that it's not work: alsoProvides and directlyProvides change GM interfaces only in memory, it's not persistent changes (after restart GM Zope yours object will be only basic interface) . GM (sorry my honor english). GM ___ GM Zope3-users mailing list GM Zope3-users@zope.org GM http://mail.zope.org/mailman/listinfo/zope3-users -- Best regards, Groszer Adam -- Quote of the day: Never does the human soul appear so strong and noble as when it forgoes revenge and dares to forgive an injury. - Edwin Hubbell Chapin ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
Garanin Michael a écrit : Christophe Combelles wrote: Christophe Combelles a écrit : Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? I've finally mixed 3) and 4) : I have defined ICompany(Interface), IClient(ICompany), IProvider(ICompany) And I have an ICompanyType(IInterface) interface type I've set the type of IClient and IProvider as ICompanyType in zcml. ICompany has a types attribute, for which I've redefined __getattr__ and __setattr_: __getattr__ retrieve the ICompanyType interfaces from the object __setattr__ calls noLongerProvides then alsoProvides to change the interfaces. I think that it's not work: alsoProvides and directlyProvides change interfaces only in memory, it's not persistent changes (after restart Zope yours object will be only basic interface) . (sorry my honor english). You've just frightened me, but I've just tried and it just work. Interfaces are kept between server restart. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
Bernd Dorn a écrit : But with 4), I guess I won't be able to assign two categories onto an object, An object can have only one ContentType this is not true an object can implement many interfaces so why shouldnt it be possible to assign many subclasses of IInterface (or did i m iss something?), use alsoProvides, not directlyProvides ah yes right, I thought this because queryType only returns the first interface, but I could have several of them. This is simple, but now how do I assign a name to these interface, so that the user will choose between Client and Provider, and not between IClient and IProvider? Is it feasible with Tagged Value ? Or with the name attribute in the zope:interface ZCML declaration? use the name attribute, skins in zope work the same way How do you retrieve the name attribute? I've watched the dir() of the interface I couldn't find anything. Maybe I could find it somewhere in the registry? ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
Christophe Combelles wrote: . I want to define objects that represent Companies. A company can be either a client, or a provider, or both, or in the future it could be of another type. When the user creates a company, it must choose client, provider, or both. The choice would assign a different interface to the object: IClient, or IProvider, and this would lead to different views for these objects. So client and provider are categories of companies. So I would tend to have: class ICompany(Interface) class IClient(ICompany) class IProvider(ICompany) This is simple, but now how do I assign a name to these interface, so that the user will choose between Client and Provider, and not between IClient and IProvider? Is it feasible with Tagged Value ? Or with the name attribute in the zope:interface ZCML declaration? simple way: 1) in interfaces.py: class IMyApplicationSite(Interface): pass class ICompany(Interface): pass class IClientMarker(Interface): pass class IProviderMarker(Interface): pass 2): in model.py class MyApplicationSite(Folder): def get(self, key, default): obj = Folder.get(key, default) if ICompany.providedBy(obj): if 'client' in obj.tags: directlyProvide(IClientMarker, obj) elif 'provider' in obj.tags: directlyProvide(IProviderMarker, obj) return obj class BaseCompany(Persistent): implements(ICompany) tags = client provider # or provider 3) in configure.zcml view for=.interfaces.IMyApplicationSite type=zope.publisher.interfaces.browser.IBrowserRequest provides=zope.publisher.interfaces.browser.IBrowserPublisher factory=zope.app.container.traversal.ContainerTraverser permission=zope.View allowed_interface=zope.publisher.interfaces.browser.IBrowserPublisher / ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Design question (object or interface for category implementation?)
Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? Do you have some advice on the subject? Am I asking the wrong questions? Is there an obvious solution I've not seen? Am I going too far and should I rather keep it simple and stupid? regards, Christophe ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
On 06.03.2007, at 18:54, Christophe Combelles wrote: Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? imho 4) is the best solution, just take a look at zope.app.content to see how to get the vocabulary and the inspection implementation of objects you can then set the interface on objects by using zope.interface.alsoProvides regards, Bernd Do you have some advice on the subject? Am I asking the wrong questions? Is there an obvious solution I've not seen? Am I going too far and should I rather keep it simple and stupid? regards, Christophe ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
Bernd Dorn a écrit : On 06.03.2007, at 18:54, Christophe Combelles wrote: Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? imho 4) is the best solution, just take a look at zope.app.content to see how to get the vocabulary and the inspection implementation of objects you can then set the interface on objects by using zope.interface.alsoProvides But with 4), I guess I won't be able to assign two categories onto an object, An object can have only one ContentType I feel that 3) is easier, but I don't know how to assign an retrieve a display name to interfaces. A real example is the following: --- I want to define objects that represent Companies. A company can be either a client, or a provider, or both, or in the future it could be of another type. When the user creates a company, it must choose client, provider, or both. The choice would assign a different interface to the object: IClient, or IProvider, and this would lead to different views for these objects. So client and provider are categories of companies. So I would tend to have: class ICompany(Interface) class IClient(ICompany) class IProvider(ICompany) This is simple, but now how do I assign a name to these interface, so that the user will choose between Client and Provider, and not between IClient and IProvider? Is it feasible with Tagged Value ? Or with the name attribute in the zope:interface ZCML declaration? regards, Bernd Do you have some advice on the subject? Am I asking the wrong questions? Is there an obvious solution I've not seen? Am I going too far and should I rather keep it simple and stupid? regards, Christophe ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Design question (object or interface for category implementation?)
On 07.03.2007, at 01:32, Christophe Combelles wrote: Bernd Dorn a écrit : On 06.03.2007, at 18:54, Christophe Combelles wrote: Hi, I'm playing again with the notion of categories of objects. I have two main goals: - 1) I must let the user choose the category of an object added to the zodb. For this, I must be able to retrieve the list of categories and present them in a form field managed by a vocabulary (or in a different manner). 2) I must have different behaviours for categorized objects: objects of different categories would have different views, different addMenuItems (if they are containers), etc. the first requirement would tell me to define categories as objects, while the second one would tell me to define them as interfaces. The possible solutions I see: 1) The simplest solution is to store the categories as text strings into the annotations of the object. So categories actually are just tags. 2) The second solution is to do the same, but replace text strings with category objects, that implement ICategory. And categories can be stored separately in a category container, or in a registered utility that gives the list of available categories. This is a bit better, but this way I don't know how to easily let my categorized objects behave differently according to their categories. 3) The third solution is to define categories as interfaces extending ICategory. I can retrieve the list of categories with ICategory.dependents But to present them in a form, I must have a pretty name for each interface. Should I store them in a Tagged Value? 4) The fourth solution I see, is to define an interface type, ICategoryType, extending IInterface just like IContentType. Then my categories would be interfaces whose type is ICategoryType. But with IContentType, is there a way to retrieve the list of all available content types? imho 4) is the best solution, just take a look at zope.app.content to see how to get the vocabulary and the inspection implementation of objects you can then set the interface on objects by using zope.interface.alsoProvides But with 4), I guess I won't be able to assign two categories onto an object, An object can have only one ContentType this is not true an object can implement many interfaces so why shouldnt it be possible to assign many subclasses of IInterface (or did i m iss something?), use alsoProvides, not directlyProvides I feel that 3) is easier, but I don't know how to assign an retrieve a display name to interfaces. A real example is the following: --- I want to define objects that represent Companies. A company can be either a client, or a provider, or both, or in the future it could be of another type. When the user creates a company, it must choose client, provider, or both. The choice would assign a different interface to the object: IClient, or IProvider, and this would lead to different views for these objects. So client and provider are categories of companies. So I would tend to have: class ICompany(Interface) class IClient(ICompany) class IProvider(ICompany) This is simple, but now how do I assign a name to these interface, so that the user will choose between Client and Provider, and not between IClient and IProvider? Is it feasible with Tagged Value ? Or with the name attribute in the zope:interface ZCML declaration? use the name attribute, skins in zope work the same way regards, Bernd Do you have some advice on the subject? Am I asking the wrong questions? Is there an obvious solution I've not seen? Am I going too far and should I rather keep it simple and stupid? regards, Christophe ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users