Merge lp:~thumper/launchpad/bugtask-tales-addition into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 12679
Proposed branch: lp:~thumper/launchpad/bugtask-tales-addition
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/bugtask-repr
Diff against target: 108 lines (+43/-7)
3 files modified
lib/lp/app/browser/tales.py (+38/-1)
lib/lp/app/doc/tales.txt (+4/-4)
lib/lp/code/stories/branches/xx-bug-branch-links.txt (+1/-2)
To merge this branch: bzr merge lp:~thumper/launchpad/bugtask-tales-addition
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+53732@code.launchpad.net

Description of the change

In order to specify a title for the fmt:link of a bug task,
the generic base class had to be tweaked.

This is then used to provide a title for the anchor of a bug task.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

This looks good to land, with the changes to the base class _title_values we discussed in IRC.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/tales.py'
2--- lib/lp/app/browser/tales.py 2011-03-09 20:39:15 +0000
3+++ lib/lp/app/browser/tales.py 2011-03-27 22:55:58 +0000
4@@ -1312,6 +1312,31 @@
5 values[key] = cgi.escape(value)
6 return self._link_summary_template % values
7
8+ def _title_values(self):
9+ """Return a dict of values to use for template substitution.
10+
11+ These values should not be escaped, as this will be performed later.
12+ For this reason, only string values should be supplied.
13+ """
14+ return {}
15+
16+ def _make_title(self):
17+ """Create a title from _title_template and _title_values().
18+
19+ This title is for use in fmt:link, which is meant to be used in
20+ contexts like lists of items.
21+ """
22+ title_template = getattr(self, '_title_template', None)
23+ if title_template is None:
24+ return None
25+ values = {}
26+ for key, value in self._title_values().iteritems():
27+ if value is None:
28+ values[key] = ''
29+ else:
30+ values[key] = cgi.escape(value)
31+ return title_template % values
32+
33 def sprite_css(self):
34 """Retrieve the icon for the _context, if any.
35
36@@ -1334,12 +1359,18 @@
37 css = ' class="' + sprite + '"'
38
39 summary = self._make_link_summary()
40+ title = self._make_title()
41+ if title is None:
42+ title = ''
43+ else:
44+ title = ' title="%s"' % title
45+
46 if check_permission(self._link_permission, self._context):
47 url = self.url(view_name, rootsite)
48 else:
49 url = ''
50 if url:
51- return '<a href="%s"%s>%s</a>' % (url, css, summary)
52+ return '<a href="%s"%s%s>%s</a>' % (url, css, title, summary)
53 else:
54 return summary
55
56@@ -1563,6 +1594,12 @@
57 class BugTaskFormatterAPI(CustomizableFormatter):
58 """Adapter for IBugTask objects to a formatted string."""
59
60+ _title_template = '%(importance)s - %(status)s'
61+
62+ def _title_values(self):
63+ return {'importance': self._context.importance.title,
64+ 'status': self._context.status.title}
65+
66 def _make_link_summary(self):
67 return BugFormatterAPI(self._context.bug)._make_link_summary()
68
69
70=== modified file 'lib/lp/app/doc/tales.txt'
71--- lib/lp/app/doc/tales.txt 2011-03-03 01:13:47 +0000
72+++ lib/lp/app/doc/tales.txt 2011-03-27 22:55:58 +0000
73@@ -519,8 +519,8 @@
74
75 >>> bugtask = bug.bugtasks[0]
76 >>> test_tales("bugtask/fmt:link", bugtask=bugtask)
77- u'<a href=".../firefox/+bug/1" class="sprite bug-low">Bug #1:
78- Firefox does not support SVG</a>'
79+ u'<a href=".../firefox/+bug/1" class="sprite bug-low"
80+ title="Low - New">Bug #1: Firefox does not support SVG</a>'
81
82 Bug titles may contain markup (when describing issue regarding markup).
83 Their titles are escaped so that they display correctly. This also
84@@ -530,11 +530,11 @@
85 >>> login('test@canonical.com')
86 >>> bug.title = "Opps<br/><script>alert('XSS')</script>"
87 >>> test_tales("bug/fmt:link", bug=getUtility(IBugSet).get(1))
88- u'<a href=".../bugs/1" class="sprite bug">Bug #1:
89+ u'<a href=".../bugs/1" ...>Bug #1:
90 Opps&lt;br/&gt;&lt;script&gt;alert(\'XSS\')&lt;/script&gt;</a>'
91
92 >>> test_tales("bugtask/fmt:link", bugtask=bugtask)
93- u'<a href=".../firefox/+bug/1" class="sprite bug-low">Bug #1:
94+ u'<a href=".../firefox/+bug/1" ...>Bug #1:
95 Opps&lt;br/&gt;&lt;script&gt;alert(\'XSS\')&lt;/script&gt;</a>'
96
97
98
99=== modified file 'lib/lp/code/stories/branches/xx-bug-branch-links.txt'
100--- lib/lp/code/stories/branches/xx-bug-branch-links.txt 2011-02-27 21:00:44 +0000
101+++ lib/lp/code/stories/branches/xx-bug-branch-links.txt 2011-03-27 22:55:58 +0000
102@@ -215,6 +215,5 @@
103
104 >>> print find_tag_by_id(admin_browser.contents, 'deletion-items')
105 <ul ...
106- <a href="http://bugs.launchpad.dev/product-name.../+bug/..."
107- class="sprite bug-undecided">Bug #...: generic-string...</a>...
108+ <a href...>Bug #...: generic-string...</a>...
109