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

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
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
lib/lp/app/widgets/itemswidgets.py (+5/-2)
lib/lp/app/widgets/tests/test_itemswidgets.py (+23/-11)
lib/lp/registry/vocabularies.py (+1/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/hack-itemwidget
Reviewer Review Type Date Requested Status
William Grant code Approve
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.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/app/widgets/itemswidgets.py'
--- lib/lp/app/widgets/itemswidgets.py 2012-01-17 04:44:17 +0000
+++ lib/lp/app/widgets/itemswidgets.py 2012-05-01 05:15:23 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Widgets dealing with a choice of options."""4"""Widgets dealing with a choice of options."""
@@ -159,7 +159,10 @@
159 """Render the table row for the widget depending on description."""159 """Render the table row for the widget depending on description."""
160 if form_value != self._missing:160 if form_value != self._missing:
161 vocab_term = self.vocabulary.getTermByToken(form_value)161 vocab_term = self.vocabulary.getTermByToken(form_value)
162 description = vocab_term.value.description162 # This is not needed when display_userdata_as_private is removed.
163 description = getattr(vocab_term, 'description', None)
164 if description is None:
165 description = vocab_term.value.description
163 else:166 else:
164 description = None167 description = None
165168
166169
=== modified file 'lib/lp/app/widgets/tests/test_itemswidgets.py'
--- lib/lp/app/widgets/tests/test_itemswidgets.py 2012-02-28 04:24:19 +0000
+++ lib/lp/app/widgets/tests/test_itemswidgets.py 2012-05-01 05:15:23 +0000
@@ -1,24 +1,20 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the1# Copyright 2011-2012 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
3from unittest import TestCase
4
5from lazr.enum._enum import (
6 DBEnumeratedType,
7 DBItem,
8 )
9
10from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
11from lp.services.features.testing import FeatureFixture
12
133
14__metaclass__ = type4__metaclass__ = type
155
6
16import doctest7import doctest
8from unittest import TestCase
179
18from lazr.enum import (10from lazr.enum import (
19 EnumeratedType,11 EnumeratedType,
20 Item,12 Item,
21 )13 )
14from lazr.enum._enum import (
15 DBEnumeratedType,
16 DBItem,
17 )
22from testtools.matchers import DocTestMatches18from testtools.matchers import DocTestMatches
23from zope.schema import Choice19from zope.schema import Choice
24from zope.schema.vocabulary import (20from zope.schema.vocabulary import (
@@ -26,12 +22,15 @@
26 SimpleVocabulary,22 SimpleVocabulary,
27 )23 )
2824
25from lp.app.browser.lazrjs import vocabulary_to_choice_edit_items
29from lp.app.widgets.itemswidgets import (26from lp.app.widgets.itemswidgets import (
30 LabeledMultiCheckBoxWidget,27 LabeledMultiCheckBoxWidget,
31 LaunchpadRadioWidget,28 LaunchpadRadioWidget,
32 LaunchpadRadioWidgetWithDescription,29 LaunchpadRadioWidgetWithDescription,
33 PlainMultiCheckBoxWidget,30 PlainMultiCheckBoxWidget,
34 )31 )
32from lp.registry.vocabularies import InformationTypeVocabulary
33from lp.services.features.testing import FeatureFixture
35from lp.services.webapp.menu import structured34from lp.services.webapp.menu import structured
36from lp.services.webapp.servers import LaunchpadTestRequest35from lp.services.webapp.servers import LaunchpadTestRequest
37from lp.testing import TestCaseWithFactory36from lp.testing import TestCaseWithFactory
@@ -223,6 +222,19 @@
223 hint_html = self.widget.renderExtraHint()222 hint_html = self.widget.renderExtraHint()
224 self.assertEqual(expected, hint_html)223 self.assertEqual(expected, hint_html)
225224
225 def test_renderDescription(self):
226 # If the vocabulary provides a description property, it is used over
227 # the one provided by the enum.
228 feature_flag = {
229 'disclosure.display_userdata_as_private.enabled': 'on'}
230 with FeatureFixture(feature_flag):
231 vocab = InformationTypeVocabulary()
232 widget = LaunchpadRadioWidgetWithDescription(
233 self.field, vocab, self.request)
234 self.assertRenderItem(
235 "... containing private information ...", widget.renderItem,
236 vocab.getTermByToken('USERDATA'))
237
226238
227class TestVocabularyToChoiceEditItems(TestCase):239class TestVocabularyToChoiceEditItems(TestCase):
228 """Tests for vocabulary_to_choice_edit_items.240 """Tests for vocabulary_to_choice_edit_items.
229241
=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py 2012-04-26 00:13:47 +0000
+++ lib/lp/registry/vocabularies.py 2012-05-01 05:15:23 +0000
@@ -2252,6 +2252,7 @@
2252 description = (2252 description = (
2253 description.replace('user data', 'private information'))2253 description.replace('user data', 'private information'))
2254 term = SimpleTerm(type, type.name, title)2254 term = SimpleTerm(type, type.name, title)
2255 term.name = type.name
2255 term.description = description2256 term.description = description
2256 terms.append(term)2257 terms.append(term)
2257 super(InformationTypeVocabulary, self).__init__(terms)2258 super(InformationTypeVocabulary, self).__init__(terms)