Now, we'll turn our attention to the main page, following a successful login. The first bit of coding that needs to be done is in the sweetscomplete.domain.product.ProductService class. We need to add a method that returns product information in a format suitable for web consumption. The objective is to be able to display product titles and prices. Once selected, the web form returns the selected product key and quantity to purchase.
Here is the new fetchAllKeysAndTitlesForSelect() method. It uses the pymongo.collection.Collection.find() method and supplies a projection argument that includes only the productKey, title, and price fields. The return value is stored as a Python dictionary in the keysAndTitles class variable:
# sweetscomplete.domain.product.ProductService
def fetchAllKeysAndTitlesForSelect(self) :
if not self.keysAndTitles :
projection = dict({"productKey":1,"title":1,"price":1...