Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 8 (modified by ksenia, 13 years ago) (diff)

remove spam


You don't want to have to keep creating new functions to create lists in just the right way when populating select-style fields on a widget-based form. You want something a little more generic, more reusable, or you want to (or need to) be able to supply arguments to your callables, without actually calling them.


We're going to create a variation on a decorator to solve the above problem. We will define a function which accepts a callable as an argument, and returns another callable. This technique is a variation on one called currying (in honor of Haskell Curry, not the food) though it is also referred to as partial application.


We are going to create two things: a generic method which returns SQLObject records in the correct format (a list of tuples), and a function which modifies that list by prepending optional "empty" item, while passing additional arguments to the generic method.

Building Usable Lists from SQLObject

This function should be defined (through copy-and-paste or assignment) within each SQLObject class we wish to use as a source of select items. (Note: in Python 2.3 replace @classmethod before the method with build_list = classmethod(build_list) after.)