Merge lp:~stevenk/launchpad/hack-itemwidget into lp:launchpad

Proposed by Steve Kowalik on 2012-05-01
Status: Merged
Approved by: William Grant on 2012-05-01
Approved revision: 15182
Merged at revision: 15183
Proposed branch: lp:~stevenk/launchpad/hack-itemwidget
Merge into: lp:launchpad
Diff against target: 105 lines (+29/-13) 3 files modified
To merge this branch: bzr merge lp:~stevenk/launchpad/hack-itemwidget
Reviewer Review Type Date Requested Status
William Grant code 2012-05-01 Approve on 2012-05-01
Review via email: mp+104202@code.launchpad.net

Commit Message

Use term.description if it exists in LaunchpadRadioWidgetWithDescription.

Description of the Change

Currently, if both show_information_type_in_ui and display_userdata_as_private are enabled, the two pages that make use of LaunchpadRadioWidgetWithDescription (Bug:+secrecy and Bug:+filebug) correctly show one of the radio buttons as 'Private', but the description contains 'user data', not 'private information' as it expected.

I have tracked this down to the widget itself, and the slightly funky behaviour we have due to the vocab being backed by an enum, and as such, the widget will use term.description if it is set, otherwise falls back to term.value.description.

I have done a drive-by of fixing the imports in test_itemswidgets.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

1=== modified file 'lib/lp/app/widgets/itemswidgets.py'
2--- lib/lp/app/widgets/itemswidgets.py 2012-01-17 04:44:17 +0000
3+++ lib/lp/app/widgets/itemswidgets.py 2012-05-01 05:15:23 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Widgets dealing with a choice of options."""
10@@ -159,7 +159,10 @@
11 """Render the table row for the widget depending on description."""
12 if form_value != self._missing:
13 vocab_term = self.vocabulary.getTermByToken(form_value)
14- description = vocab_term.value.description
15+ # This is not needed when display_userdata_as_private is removed.
16+ description = getattr(vocab_term, 'description', None)
17+ if description is None:
18+ description = vocab_term.value.description
19 else:
20 description = None
21
22
23=== modified file 'lib/lp/app/widgets/tests/test_itemswidgets.py'
24--- lib/lp/app/widgets/tests/test_itemswidgets.py 2012-02-28 04:24:19 +0000
25+++ lib/lp/app/widgets/tests/test_itemswidgets.py 2012-05-01 05:15:23 +0000
26@@ -1,24 +1,20 @@
27-# Copyright 2011 Canonical Ltd. This software is licensed under the
28+# Copyright 2011-2012 Canonical Ltd. This software is licensed under the
29 # GNU Affero General Public License version 3 (see the file LICENSE).
30-from unittest import TestCase
31-
32-from lazr.enum._enum import (
33- DBEnumeratedType,
34- DBItem,
35- )
36-
37-from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
38-from lp.services.features.testing import FeatureFixture
39-
40
41 __metaclass__ = type
42
43+
44 import doctest
45+from unittest import TestCase
46
47 from lazr.enum import (
48 EnumeratedType,
49 Item,
50 )
51+from lazr.enum._enum import (
52+ DBEnumeratedType,
53+ DBItem,
54+ )
55 from testtools.matchers import DocTestMatches
56 from zope.schema import Choice
57 from zope.schema.vocabulary import (
58@@ -26,12 +22,15 @@
59 SimpleVocabulary,
60 )
61
62+from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
63 from lp.app.widgets.itemswidgets import (
64 LabeledMultiCheckBoxWidget,
65 LaunchpadRadioWidget,
66 LaunchpadRadioWidgetWithDescription,
67 PlainMultiCheckBoxWidget,
68 )
69+from lp.registry.vocabularies import InformationTypeVocabulary
70+from lp.services.features.testing import FeatureFixture
71 from lp.services.webapp.menu import structured
72 from lp.services.webapp.servers import LaunchpadTestRequest
73 from lp.testing import TestCaseWithFactory
74@@ -223,6 +222,19 @@
75 hint_html = self.widget.renderExtraHint()
76 self.assertEqual(expected, hint_html)
77
78+ def test_renderDescription(self):
79+ # If the vocabulary provides a description property, it is used over
80+ # the one provided by the enum.
81+ feature_flag = {
82+ 'disclosure.display_userdata_as_private.enabled': 'on'}
83+ with FeatureFixture(feature_flag):
84+ vocab = InformationTypeVocabulary()
85+ widget = LaunchpadRadioWidgetWithDescription(
86+ self.field, vocab, self.request)
87+ self.assertRenderItem(
88+ "... containing private information ...", widget.renderItem,
89+ vocab.getTermByToken('USERDATA'))
90+
91
92 class TestVocabularyToChoiceEditItems(TestCase):
93 """Tests for vocabulary_to_choice_edit_items.
94
95=== modified file 'lib/lp/registry/vocabularies.py'
96--- lib/lp/registry/vocabularies.py 2012-04-26 00:13:47 +0000
97+++ lib/lp/registry/vocabularies.py 2012-05-01 05:15:23 +0000
98@@ -2252,6 +2252,7 @@
99 description = (
100 description.replace('user data', 'private information'))
101 term = SimpleTerm(type, type.name, title)
102+ term.name = type.name
103 term.description = description
104 terms.append(term)
105 super(InformationTypeVocabulary, self).__init__(terms)