Merge lp:~jcsackett/launchpad/translations-message-links-404 into lp:launchpad

Proposed by j.c.sackett
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 16187
Proposed branch: lp:~jcsackett/launchpad/translations-message-links-404
Merge into: lp:launchpad
Diff against target: 107 lines (+41/-4)
4 files modified
lib/lp/translations/browser/tests/test_translationmessage_view.py (+31/-0)
lib/lp/translations/browser/tests/translationmessage-views.txt (+2/-1)
lib/lp/translations/browser/translationmessage.py (+2/-0)
lib/lp/translations/templates/translations-macros.pt (+6/-3)
To merge this branch: bzr merge lp:~jcsackett/launchpad/translations-message-links-404
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+131052@code.launchpad.net

Commit message

Blocks rendering of links to untraversable translation suggestions.

Description of the change

Summary
=======
Translations creates links to translations suggestions, but some of these
suggestions aren't traversable because they are no longer contained properly
in a potmsgset (which creates an index of 0 for the message).

The solution is simply to add a guard around rendering the suggestion, so the
information is not linkified if it's untraversable.

Preimp
======
Spoke with Curtis Hovey.

Implementation
==============
Submission, a stub class used to wrap translation messages, has a guard added
to check if the message index is 0.

The TAL checks for this guard, rendering the information as a link if it is
traversable, and as text if not.

Tests
=====
bin/test -vvct test_submission_traversable_guard

QA
==
Ensure that the bad data example in the bug is not rendering as a link.

LoC
===
I have approximately 400 LoC of credit.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/templates/translations-macros.pt
  lib/lp/translations/browser/tests/test_translationmessage_view.py
  lib/lp/translations/browser/translationmessage.py

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

thank you

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/translations/browser/tests/test_translationmessage_view.py'
2--- lib/lp/translations/browser/tests/test_translationmessage_view.py 2012-01-01 02:58:52 +0000
3+++ lib/lp/translations/browser/tests/test_translationmessage_view.py 2012-10-24 15:58:22 +0000
4@@ -32,6 +32,7 @@
5 CurrentTranslationMessagePageView,
6 CurrentTranslationMessageView,
7 revert_unselected_translations,
8+ convert_translationmessage_to_submission,
9 )
10 from lp.translations.enums import TranslationPermission
11 from lp.translations.interfaces.side import ITranslationSideTraitsSet
12@@ -477,3 +478,33 @@
13 {1: u''},
14 revert_unselected_translations(
15 new_translations, current_message, []))
16+
17+class TestBadSubmission(TestCaseWithFactory):
18+
19+ layer = DatabaseFunctionalLayer
20+
21+ def getSubmission(self, good=True):
22+ original_translations = {0: self.getUniqueString()}
23+ pofile = self.factory.makePOFile()
24+ current = self.factory.makeCurrentTranslationMessage(pofile=pofile)
25+ message = self.factory.makeSuggestion(pofile=pofile)
26+ if good:
27+ message.setPOFile(pofile)
28+ submission = convert_translationmessage_to_submission(
29+ message=message,
30+ current_message=current,
31+ plural_form=0,
32+ pofile=pofile,
33+ legal_warning_needed=False)
34+ return submission
35+
36+ def test_submission_traversable_guard(self):
37+ # If a submission doesn't have a sequence greater than 1, it's not
38+ # traversable.
39+ bad_sub = self.getSubmission(good=False)
40+ self.assertEqual(0, bad_sub.translationmessage.sequence)
41+ self.assertFalse(bad_sub.is_traversable)
42+
43+ good_sub = self.getSubmission()
44+ self.assertNotEqual(0, good_sub.translationmessage.sequence)
45+ self.assertTrue(good_sub.is_traversable)
46
47=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
48--- lib/lp/translations/browser/tests/translationmessage-views.txt 2011-12-30 06:14:56 +0000
49+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2012-10-24 15:58:22 +0000
50@@ -451,6 +451,7 @@
51 id: 703
52 is_empty: False
53 is_local_to_pofile: False
54+ is_traversable: ...
55 language: ...
56 legal_warning: False
57 origin_html_id: msgset_15_ja_suggestion_703_0_origin
58@@ -458,7 +459,7 @@
59 plural_index: 0
60 pofile: ...
61 potmsgset: ...
62- row_html_id:
63+ row_html_id:
64 suggestion_dismissable_class: msgset_15_dismissable_button
65 suggestion_html_id: msgset_15_ja_suggestion_703_0
66 suggestion_text: Foo <code>%d</code>
67
68=== modified file 'lib/lp/translations/browser/translationmessage.py'
69--- lib/lp/translations/browser/translationmessage.py 2012-08-09 03:41:10 +0000
70+++ lib/lp/translations/browser/translationmessage.py 2012-10-24 15:58:22 +0000
71@@ -11,6 +11,7 @@
72 __all__ = [
73 'BaseTranslationView',
74 'contains_translations',
75+ 'convert_translationmessage_to_submission',
76 'CurrentTranslationMessageAppMenus',
77 'CurrentTranslationMessageFacets',
78 'CurrentTranslationMessageIndexView',
79@@ -1669,6 +1670,7 @@
80 """
81
82 submission = Submission()
83+ submission.is_traversable = (message.sequence != 0)
84 submission.translationmessage = message
85 for attribute in ['id', 'language', 'potmsgset', 'date_created']:
86 setattr(submission, attribute, getattr(message, attribute))
87
88=== modified file 'lib/lp/translations/templates/translations-macros.pt'
89--- lib/lp/translations/templates/translations-macros.pt 2012-07-07 14:00:30 +0000
90+++ lib/lp/translations/templates/translations-macros.pt 2012-10-24 15:58:22 +0000
91@@ -84,10 +84,13 @@
92 <td style="overflow: auto;"
93 tal:condition="not:submission/is_local_to_pofile">
94 <tal:source content="string:${context/title}" />
95- <a tal:content="submission/pofile/potemplate/displayname"
96+ <a tal:condition="submission/is_traversable"
97+ tal:content="submission/pofile/potemplate/displayname"
98 tal:attributes="href string:${submission/translationmessage/fmt:url}/+translate">
99- Spanish translation for evolution
100- </a> by
101+ Spanish translation for evolution </a>
102+ <tal:fallback
103+ condition="not:submission/is_traversable"
104+ content="submission/pofile/potemplate/displayname" /> by
105 <a tal:content="submission/person/displayname"
106 tal:attributes="href submission/person/fmt:url">Foo Bar</a>
107 <span