ERP5 KM

TechnicalNoteOnDomainSelection

What is DomainSelection ?

DomainSelection is a class which is used by ListBox in domain and report mode to filter documents. DomainSelection can be used from PythonScripts within the ZMI. Here is an example:

   1 from Products.ERP5Form.Selection import DomainSelection
   2 section = context.portal_categories.resolveCategory('publication_section/marketing/erp5/industry')
   3 domain = DomainSelection(domain_dict = {'publication_section': section})
   4 return str(len(context.portal_catalog(selection_domain = domain, portal_type="Web Page")))

In this example, a DomainSelection object is created by associating the domain Id 'publication_section' to the section 'publication_section/marketing/erp5/industry' which happens to be a category. Then, the total number of web pages which are part of that category is returned as a string.

Any number of categories can be defined in a DomainSelection. By defining multiple categories, it is possible to implement a boolean AND operation and filter, for example, all Web Pages which are part of a given product line family and of a given publication section.

Sometimes, it is more convenient to capture in so-called Predicate objects all the criteria for filtering objects. This is the purpose for example of Domain objects in ERP5. An example of Domain object which configuration defines a predicate on all documents of the 'publication_section/marketing/erp5/industry' category is illustrated bellow:

--

Domain objects can be used directly by DomainSelection as illustrated bellow:

   1 from Products.ERP5Form.Selection import DomainSelection
   2 domain = DomainSelection(domain_dict = {'erp5_domain': context})
   3 return str(len(context.portal_catalog(selection_domain = domain, portal_type="Web Page")))

In this example, a DomainSelection object is created by associating the domain Id 'erp5_domain' to the current object which is a Domain document and defines a predicate. Then, the total number of web pages which satisfy the predicate is returned as a string.

TechnicalNoteOnDomainSelection (last edited 2008-02-26 10:37:37 by ŁukaszNowak)

Page
  • Immutable Page
  • Info
  • Attachments
User
Learn about new ERP5 releases,technical articles, events and more.

Subscribe to the monthly ERP5 Newsletter!