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
=== modified file 'lib/lp/translations/browser/tests/test_translationmessage_view.py'
--- lib/lp/translations/browser/tests/test_translationmessage_view.py 2012-01-01 02:58:52 +0000
+++ lib/lp/translations/browser/tests/test_translationmessage_view.py 2012-10-24 15:58:22 +0000
@@ -32,6 +32,7 @@
32 CurrentTranslationMessagePageView,32 CurrentTranslationMessagePageView,
33 CurrentTranslationMessageView,33 CurrentTranslationMessageView,
34 revert_unselected_translations,34 revert_unselected_translations,
35 convert_translationmessage_to_submission,
35 )36 )
36from lp.translations.enums import TranslationPermission37from lp.translations.enums import TranslationPermission
37from lp.translations.interfaces.side import ITranslationSideTraitsSet38from lp.translations.interfaces.side import ITranslationSideTraitsSet
@@ -477,3 +478,33 @@
477 {1: u''},478 {1: u''},
478 revert_unselected_translations(479 revert_unselected_translations(
479 new_translations, current_message, []))480 new_translations, current_message, []))
481
482class TestBadSubmission(TestCaseWithFactory):
483
484 layer = DatabaseFunctionalLayer
485
486 def getSubmission(self, good=True):
487 original_translations = {0: self.getUniqueString()}
488 pofile = self.factory.makePOFile()
489 current = self.factory.makeCurrentTranslationMessage(pofile=pofile)
490 message = self.factory.makeSuggestion(pofile=pofile)
491 if good:
492 message.setPOFile(pofile)
493 submission = convert_translationmessage_to_submission(
494 message=message,
495 current_message=current,
496 plural_form=0,
497 pofile=pofile,
498 legal_warning_needed=False)
499 return submission
500
501 def test_submission_traversable_guard(self):
502 # If a submission doesn't have a sequence greater than 1, it's not
503 # traversable.
504 bad_sub = self.getSubmission(good=False)
505 self.assertEqual(0, bad_sub.translationmessage.sequence)
506 self.assertFalse(bad_sub.is_traversable)
507
508 good_sub = self.getSubmission()
509 self.assertNotEqual(0, good_sub.translationmessage.sequence)
510 self.assertTrue(good_sub.is_traversable)
480511
=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
--- lib/lp/translations/browser/tests/translationmessage-views.txt 2011-12-30 06:14:56 +0000
+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2012-10-24 15:58:22 +0000
@@ -451,6 +451,7 @@
451 id: 703451 id: 703
452 is_empty: False452 is_empty: False
453 is_local_to_pofile: False453 is_local_to_pofile: False
454 is_traversable: ...
454 language: ...455 language: ...
455 legal_warning: False456 legal_warning: False
456 origin_html_id: msgset_15_ja_suggestion_703_0_origin457 origin_html_id: msgset_15_ja_suggestion_703_0_origin
@@ -458,7 +459,7 @@
458 plural_index: 0459 plural_index: 0
459 pofile: ...460 pofile: ...
460 potmsgset: ...461 potmsgset: ...
461 row_html_id:462 row_html_id:
462 suggestion_dismissable_class: msgset_15_dismissable_button463 suggestion_dismissable_class: msgset_15_dismissable_button
463 suggestion_html_id: msgset_15_ja_suggestion_703_0464 suggestion_html_id: msgset_15_ja_suggestion_703_0
464 suggestion_text: Foo <code>%d</code>465 suggestion_text: Foo <code>%d</code>
465466
=== modified file 'lib/lp/translations/browser/translationmessage.py'
--- lib/lp/translations/browser/translationmessage.py 2012-08-09 03:41:10 +0000
+++ lib/lp/translations/browser/translationmessage.py 2012-10-24 15:58:22 +0000
@@ -11,6 +11,7 @@
11__all__ = [11__all__ = [
12 'BaseTranslationView',12 'BaseTranslationView',
13 'contains_translations',13 'contains_translations',
14 'convert_translationmessage_to_submission',
14 'CurrentTranslationMessageAppMenus',15 'CurrentTranslationMessageAppMenus',
15 'CurrentTranslationMessageFacets',16 'CurrentTranslationMessageFacets',
16 'CurrentTranslationMessageIndexView',17 'CurrentTranslationMessageIndexView',
@@ -1669,6 +1670,7 @@
1669 """1670 """
16701671
1671 submission = Submission()1672 submission = Submission()
1673 submission.is_traversable = (message.sequence != 0)
1672 submission.translationmessage = message1674 submission.translationmessage = message
1673 for attribute in ['id', 'language', 'potmsgset', 'date_created']:1675 for attribute in ['id', 'language', 'potmsgset', 'date_created']:
1674 setattr(submission, attribute, getattr(message, attribute))1676 setattr(submission, attribute, getattr(message, attribute))
16751677
=== modified file 'lib/lp/translations/templates/translations-macros.pt'
--- lib/lp/translations/templates/translations-macros.pt 2012-07-07 14:00:30 +0000
+++ lib/lp/translations/templates/translations-macros.pt 2012-10-24 15:58:22 +0000
@@ -84,10 +84,13 @@
84 <td style="overflow: auto;"84 <td style="overflow: auto;"
85 tal:condition="not:submission/is_local_to_pofile">85 tal:condition="not:submission/is_local_to_pofile">
86 <tal:source content="string:${context/title}" />86 <tal:source content="string:${context/title}" />
87 <a tal:content="submission/pofile/potemplate/displayname"87 <a tal:condition="submission/is_traversable"
88 tal:content="submission/pofile/potemplate/displayname"
88 tal:attributes="href string:${submission/translationmessage/fmt:url}/+translate">89 tal:attributes="href string:${submission/translationmessage/fmt:url}/+translate">
89 Spanish translation for evolution90 Spanish translation for evolution </a>
90 </a> by91 <tal:fallback
92 condition="not:submission/is_traversable"
93 content="submission/pofile/potemplate/displayname" /> by
91 <a tal:content="submission/person/displayname"94 <a tal:content="submission/person/displayname"
92 tal:attributes="href submission/person/fmt:url">Foo Bar</a>95 tal:attributes="href submission/person/fmt:url">Foo Bar</a>
93 <span96 <span