1.244. ListContext

Full Name: herschel.ia.pal.ListContext
Type: Java Class - Java Class
Import: from herschel.ia.pal import ListContext
Category

Data access

Description

Groups products (or other Contexts that in turn group products) in a list-like structure.

Products grouped in a ListContext can be subsequently retrieved by an index (with index=0 corresponding to the first product in the list), through the 'refs' method. Note: users may be confused as to why there is a need to have to go though a 'refs' method to add or access products from a ListContext. This is due to a technical limitation in the design which will be addressed in due course.

Examples

Example 1: Adding a product to a ListContext
product = Product()
ref = storage.save(product) # the ref is a ProductRef object
listcontext = ListContext()
listcontext.refs.add(ref)
Example 2: Getting the first product from a ListContext
ref_first = listcontext.refs.get(0)
product = ref_first.product
Example 3: Saving a ListContext to ProductStorage (same way as any other product)
ref_context = storage.save(listcontext)

API Summary

Method
List getRefs

get the list of ProductRefs stored. From this list, you can put

API Details

Method

List getRefs

get the list of ProductRefs stored. From this list, you can put

products into the ListContext, or retrieve products by index.

Return
List

A list of product refs.

Examples
Putting a product into the the ListContext
ref = storage.save(product) # the ref is a ProductRef object
listcontext.refs.add(ref)
Getting the first product from the ListContext
ref_first = listcontext.refs.get(0)

See also