Merge lp:~wallyworld/launchpad/optional-extended-choice-popup-933743 into lp:launchpad

Proposed by Ian Booth
Status: Merged
Approved by: Ian Booth
Approved revision: no longer in the source branch.
Merged at revision: 14828
Proposed branch: lp:~wallyworld/launchpad/optional-extended-choice-popup-933743
Merge into: lp:launchpad
Prerequisite: lp:~wallyworld/launchpad/choice-popup-descriptions-932424
Diff against target: 102 lines (+22/-10)
3 files modified
lib/lp/app/browser/lazrjs.py (+8/-5)
lib/lp/app/widgets/tests/test_itemswidgets.py (+12/-1)
lib/lp/bugs/browser/bugtask.py (+2/-4)
To merge this branch: bzr merge lp:~wallyworld/launchpad/optional-extended-choice-popup-933743
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+93518@code.launchpad.net

Commit message

[r=stevenk][bug=933743] Add configuration option to enum popup widget to control whether item descriptions are displayed. Default is no.

Description of the change

== Implementation ==

We want to only show the item description in the enum popup widget when asked for.
Add include_description parameter to lazrjs vocabulary_to_choice_edit_items() method.

== Tests ==

Add new test to ensure description is only there when asked for.

== Lint ==

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/app/browser/lazrjs.py
  lib/lp/app/widgets/tests/test_itemswidgets.py
  lib/lp/bugs/browser/bugtask.py

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) wrote :

Looks excellent, thank you. And I always approve of lint fixes.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/lazrjs.py'
2--- lib/lp/app/browser/lazrjs.py 2012-02-17 02:56:19 +0000
3+++ lib/lp/app/browser/lazrjs.py 2012-02-17 02:56:19 +0000
4@@ -526,8 +526,9 @@
5
6
7 def vocabulary_to_choice_edit_items(
8- vocab, css_class_prefix=None, disabled_items=None, as_json=False,
9- name_fn=None, value_fn=None, description_fn=None):
10+ vocab, include_description=False, css_class_prefix=None,
11+ disabled_items=None, as_json=False, name_fn=None, value_fn=None,
12+ description_fn=None):
13 """Convert an enumerable to JSON for a ChoiceEdit.
14
15 :vocab: The enumeration to iterate over.
16@@ -558,7 +559,7 @@
17 description = ''
18 feature_flag = getFeatureFlag(
19 'disclosure.enhanced_choice_popup.enabled')
20- if feature_flag:
21+ if include_description and feature_flag:
22 description = description_fn(item)
23 new_item = {
24 'name': name,
25@@ -660,7 +661,7 @@
26 def __init__(self, context, exported_field, header,
27 content_box_id=None, enum=None,
28 edit_view="+edit", edit_url=None, edit_title='',
29- css_class_prefix=''):
30+ css_class_prefix='', include_description=False):
31 """Create a widget wrapper.
32
33 :param context: The object that is being edited.
34@@ -689,7 +690,9 @@
35 enum = exported_field.vocabulary
36 if IEnumeratedType(enum, None) is None:
37 raise ValueError('%r does not provide IEnumeratedType' % enum)
38- self.items = vocabulary_to_choice_edit_items(enum, css_class_prefix)
39+ self.items = vocabulary_to_choice_edit_items(
40+ enum, include_description=include_description,
41+ css_class_prefix=css_class_prefix)
42
43 @property
44 def config(self):
45
46=== modified file 'lib/lp/app/widgets/tests/test_itemswidgets.py'
47--- lib/lp/app/widgets/tests/test_itemswidgets.py 2012-02-17 02:56:19 +0000
48+++ lib/lp/app/widgets/tests/test_itemswidgets.py 2012-02-17 02:56:19 +0000
49@@ -262,10 +262,21 @@
50 for e in self.ChoiceEnum]
51 self.assertEqual(expected, items)
52
53+ def test_vocabulary_to_choice_edit_items_no_description(self):
54+ # Even if feature flag is on, there are no descriptions unless wanted.
55+ feature_flag = {'disclosure.enhanced_choice_popup.enabled': 'on'}
56+ with FeatureFixture(feature_flag):
57+ overrides = {'description': ''}
58+ items = vocabulary_to_choice_edit_items(self.ChoiceEnum)
59+ expected = [self._makeItemDict(e.value, overrides)
60+ for e in self.ChoiceEnum]
61+ self.assertEqual(expected, items)
62+
63 def test_vocabulary_to_choice_edit_items_with_description(self):
64 # The items list is as expected with the feature flag.
65 feature_flag = {'disclosure.enhanced_choice_popup.enabled': 'on'}
66 with FeatureFixture(feature_flag):
67- items = vocabulary_to_choice_edit_items(self.ChoiceEnum)
68+ items = vocabulary_to_choice_edit_items(
69+ self.ChoiceEnum, include_description=True)
70 expected = [self._makeItemDict(e.value) for e in self.ChoiceEnum]
71 self.assertEqual(expected, items)
72
73=== modified file 'lib/lp/bugs/browser/bugtask.py'
74--- lib/lp/bugs/browser/bugtask.py 2012-02-08 10:43:29 +0000
75+++ lib/lp/bugs/browser/bugtask.py 2012-02-17 02:56:19 +0000
76@@ -46,10 +46,6 @@
77 timedelta,
78 )
79 from itertools import groupby
80-from math import (
81- floor,
82- log,
83- )
84 from operator import attrgetter
85 import os.path
86 import re
87@@ -4015,6 +4011,7 @@
88
89 items = vocabulary_to_choice_edit_items(
90 SimpleVocabulary.fromItems(status_items),
91+ include_description=True,
92 css_class_prefix='status',
93 disabled_items=disabled_items)
94 else:
95@@ -4037,6 +4034,7 @@
96
97 items = vocabulary_to_choice_edit_items(
98 SimpleVocabulary.fromItems(importance_items),
99+ include_description=True,
100 css_class_prefix='importance')
101 else:
102 items = '[]'