Comment 1 for bug 515584

Revision history for this message
Karl Fogel (kfogel) wrote : Re: BugsPatchesView:batchedPatchTasks() should use a Zope form, instead of validating form values manually

From a conversation with Tom Berger about how the Zope form fix would look:

The Zope form facility allows you to generate a form directly from an interface. So for example if you have a multiple choice field with an enum value, it will generate a combo with all the values.

1) Create an enum class (inherit from EnumeratedType), listing all the values you can sort by, in the browser .py file. For example, see 'class BranchListingSort' in lib/lp/code/browser/branchlisting.py.

2) Define an interface that describes the form. It will have one attribute, "orderby", whose value is the new enumerated type from (1). Do this in the browser .py file too (even though that might seem counterintuitive). For example, see 'class IBranchListingFilter' in lib/lp/code/browser/branchlisting.py (though note that the relevant variable there is 'sort_by' instead of 'orderby').

3) Define the form class itself, which inherits from LaunchpadFormView and uses the interface as its schema. To do that, just assign a variable named 'schema' to the interface. For example, see 'class BranchListingView' in lib/lp/code/browser/branchlisting.py.