Merge lp:~salgado/launchpad/bug-433991 into lp:launchpad

Proposed by Guilherme Salgado on 2009-09-21
Status: Merged
Approved by: Brad Crittenden on 2009-09-21
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~salgado/launchpad/bug-433991
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~salgado/launchpad/bug-433991
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical 2009-09-21 Approve on 2009-09-21
Henning Eggers (community) code 2009-09-21 Approve on 2009-09-21
Review via email:
To post a comment you must log in.
Guilherme Salgado (salgado) wrote :

= Summary =

Make sure zope.i18nmessageid.message.Message get interpolated when
building a page's title.

== Proposed fix ==

The new fmt:pagetitle formatter iterates over the breadcrumbs and join
their text in a single string, but the leaf breadcrumb may have Message
objects (from the view's .page_title) as their text, so when they're
joined they are not interpolated and we end up with things like 'Ask a
question about ${context}' in the title.

== Tests ==

./bin/test -vvm canonical.launchpad -t test_breadcrumbs

== Demo and Q/A ==

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:

Henning Eggers (henninge) wrote :

All fine as discussed on IRC. ;)


review: Approve (code)
Brad Crittenden (bac) :
review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/canonical/launchpad/browser/'
--- lib/canonical/launchpad/browser/ 2009-09-20 19:40:47 +0000
+++ lib/canonical/launchpad/browser/ 2009-09-21 16:21:50 +0000
@@ -36,10 +36,12 @@
36import urllib36import urllib
37from datetime import timedelta, datetime37from datetime import timedelta, datetime
39from zope import i18n
39from import zapi40from import zapi
40from zope.datetime import parseDatetimetz, tzinfo, DateTimeError41from zope.datetime import parseDatetimetz, tzinfo, DateTimeError
41from zope.component import getUtility, queryAdapter42from zope.component import getUtility, queryAdapter
42from zope.interface import implements43from zope.interface import implements
44from zope.i18nmessageid import Message
43from zope.publisher.interfaces import NotFound45from zope.publisher.interfaces import NotFound
44from zope.publisher.interfaces.browser import IBrowserPublisher46from zope.publisher.interfaces.browser import IBrowserPublisher
45from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest47from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
@@ -284,6 +286,8 @@
284 template_api = PageTemplateContextsAPI(286 template_api = PageTemplateContextsAPI(
285 dict(context=obj, template=template, view=view))287 dict(context=obj, template=template, view=view))
286 title = template_api.pagetitle()288 title = template_api.pagetitle()
289 if isinstance(title, Message):
290 title = i18n.translate(title, context=self.request)
287 breadcrumb = Breadcrumb(None)291 breadcrumb = Breadcrumb(None)
288 breadcrumb._url = url292 breadcrumb._url = url
289 breadcrumb.text = title293 breadcrumb.text = title
=== modified file 'lib/canonical/launchpad/webapp/tests/'
--- lib/canonical/launchpad/webapp/tests/ 2009-09-18 12:15:42 +0000
+++ lib/canonical/launchpad/webapp/tests/ 2009-09-21 16:21:50 +0000
@@ -6,10 +6,13 @@
6import unittest6import unittest
8from zope.interface import implements8from zope.interface import implements
9from zope.i18nmessageid import Message
11from canonical.launchpad.browser.launchpad import Hierarchy
10from canonical.launchpad.webapp.breadcrumb import Breadcrumb12from canonical.launchpad.webapp.breadcrumb import Breadcrumb
11from canonical.launchpad.webapp.interfaces import ICanonicalUrlData13from canonical.launchpad.webapp.interfaces import ICanonicalUrlData
12from canonical.launchpad.webapp.publisher import canonical_url14from canonical.launchpad.webapp.publisher import canonical_url
15from canonical.launchpad.webapp.servers import LaunchpadTestRequest
13from canonical.launchpad.webapp.tests.breadcrumbs import (16from canonical.launchpad.webapp.tests.breadcrumbs import (
14 BaseBreadcrumbTestCase)17 BaseBreadcrumbTestCase)
15from lp.testing import login, TestCase18from lp.testing import login, TestCase
@@ -63,6 +66,22 @@
63 self.assertEquals(texts[-1],66 self.assertEquals(texts[-1],
64 '%s project files' % self.product.displayname)67 '%s project files' % self.product.displayname)
69 def test_zope_i18n_Messages_are_interpolated(self):
70 # Views can use zope.i18nmessageid.Message as their title when they
71 # want to i18n it, but when that's the case we need to
72 # translate/interpolate the string.
73 class TestView:
74 """A test view that uses a Message as its page_title."""
75 page_title = Message(
76 '${name} test', mapping={'name': 'breadcrumb'})
77 __name__ = 'test-page'
78 test_view = TestView()
79 request = LaunchpadTestRequest()
80 request.traversed_objects = [self.product, test_view]
81 hierarchy_view = Hierarchy(self.product, request)
82 breadcrumb = hierarchy_view.makeBreadcrumbForRequestedPage()
83 self.assertEquals(breadcrumb.text, 'breadcrumb test')
67class TestExtraVHostBreadcrumbsOnHierarchyView(BaseBreadcrumbTestCase):86class TestExtraVHostBreadcrumbsOnHierarchyView(BaseBreadcrumbTestCase):
68 """How our breadcrumbs behave when using a vhost other than the main one?87 """How our breadcrumbs behave when using a vhost other than the main one?