BugsPatchesView violates DRY in repeating sort orderby values.

Bug #515584 reported by Karl Fogel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Low
Karl Fogel

Bug Description

In lib/lp/bugs/browser/bugtarget.py:BugsPatchesView.batchedPatchTasks(), we are validating the form input manually, thus violating DRY by repeating the valid values in the code. (See the "XXX" comment about this.)

The Right Way would be, as intellectronica says, to "use zope's form machinery, which renders the form using the definition of an interface, validates the input (reloading the page with an error message) and finally collects the correct values in self.request.form". That is, "a zope form backed by an enum with all the options".

Related branches

Karl Fogel (kfogel)
tags: added: story-patch-report
Karl Fogel (kfogel)
Changed in malone:
status: Confirmed → In Progress
milestone: none → 10.02
Revision history for this message
Karl Fogel (kfogel) wrote :

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.

Revision history for this message
Karl Fogel (kfogel) wrote :

After discussing with Abel, Tom, and Deryck, we've decided the real bug is the DRY violation, and that using a Zope form would only be worthwhile as part of a larger fix for bug #322130.

The attached branch lp:~kfogel/launchpad/515584-fix-DRY-violation fixes the DRY problem, so I'll submit that for review.

summary: - BugsPatchesView:batchedPatchTasks() should use a Zope form, instead of
- validating form values manually
+ BugsPatchesView violates DRY in repeating sort orderby values.
Revision history for this message
Diogo Matsubara (matsubara) wrote : Bug fixed by a commit
Changed in malone:
status: In Progress → Fix Committed
Deryck Hodge (deryck)
Changed in malone:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.