Merge lp:~danilo/launchpad/bug-401618 into lp:launchpad

Proposed by Данило Шеган
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: 14110
Proposed branch: lp:~danilo/launchpad/bug-401618
Merge into: lp:launchpad
Diff against target: 300 lines (+39/-55)
11 files modified
lib/lp/translations/browser/configure.zcml (+1/-1)
lib/lp/translations/browser/tests/translationmessage-views.txt (+2/-4)
lib/lp/translations/doc/pofile.txt (+10/-7)
lib/lp/translations/doc/vpotexport.txt (+5/-3)
lib/lp/translations/interfaces/potmsgset.py (+4/-6)
lib/lp/translations/interfaces/translationmessage.py (+4/-0)
lib/lp/translations/model/pofile.py (+1/-1)
lib/lp/translations/model/potmsgset.py (+0/-3)
lib/lp/translations/model/translationmessage.py (+8/-0)
lib/lp/translations/templates/pofile-filter.pt (+4/-4)
lib/lp/translations/tests/test_pofile.py (+0/-26)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-401618
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+78273@code.launchpad.net

Commit message

[r=abentley][bug=401618] Finally remove all use of POTMsgSet.sequence in our code, to fix an odd bug or two, and allow for column removal from the database.

Description of the change

= Bug 401618 =

This is a bug about remaining use of POTMsgSet.sequence that stopped us from killing this column in the database: nature of POTMsgSet has changed in the meantime so it can participate in multiple different translation templates, and sequence in each of those templates is stored on TranslationTemplateItem.sequence instead of on POTMsgSet directly.

Biggest issue was the fact that we constructed URLs for TranslationMessages using potmsgset.sequence. To aid with that, we instead introduce TranslationMessage.sequence which uses self.browser_pofile when it's defined, because that's modified according to the current view.

As for all the other uses, I replace potmsgset.sequence with potmsgset.getSequence(proper_template).

The tests previously used to pass because they didn't heavily depend on this change (eg. the fact that potmsgset.setSequence also set potmsgset.sequence was enough for them to pass), so I am not introducing any new tests because plenty would start failing if I did this wrong.

== Tests ==

"bin/test -vvm lp.translations" still passes

== Demo and Q/A ==

Browse around +translate and +filter pages on translations.l.n, especially clicking on the "zoom" icon for each of the messages. Also look for translation suggestions saying "used in" and "suggested in" and follow those links to ensure they point to right pages.

= Launchpad lint =

NOTE: I'll fix lint after the review, to simplify the review.

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/doc/vpotexport.txt
  lib/lp/translations/browser/configure.zcml
  lib/lp/translations/interfaces/translationmessage.py
  lib/lp/translations/interfaces/potmsgset.py
  lib/lp/translations/tests/test_pofile.py
  lib/lp/translations/model/pofile.py
  lib/lp/translations/doc/pofile.txt
  lib/lp/translations/browser/tests/translationmessage-views.txt
  lib/lp/translations/model/potmsgset.py
  lib/lp/translations/model/translationmessage.py
  lib/lp/translations/templates/pofile-filter.pt

./lib/lp/translations/doc/vpotexport.txt
       1: narrative uses a moin header.
      18: narrative uses a moin header.
./lib/lp/translations/interfaces/potmsgset.py
     196: Line exceeds 78 characters.
     198: Line exceeds 78 characters.
     343: E251 no spaces around keyword / parameter equals
./lib/lp/translations/model/potmsgset.py
      19: 'IntCol' imported but unused
./lib/lp/translations/templates/pofile-filter.pt
      32: Line has trailing whitespace.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/browser/configure.zcml'
--- lib/lp/translations/browser/configure.zcml 2011-08-25 19:48:19 +0000
+++ lib/lp/translations/browser/configure.zcml 2011-10-06 09:01:25 +0000
@@ -528,7 +528,7 @@
528 layer="lp.translations.publisher.TranslationsLayer"/>528 layer="lp.translations.publisher.TranslationsLayer"/>
529 <browser:url529 <browser:url
530 for="lp.translations.interfaces.translationmessage.ITranslationMessage"530 for="lp.translations.interfaces.translationmessage.ITranslationMessage"
531 path_expression="string:${potmsgset/sequence}"531 path_expression="string:${sequence}"
532 attribute_to_parent="browser_pofile"532 attribute_to_parent="browser_pofile"
533 rootsite="translations"/>533 rootsite="translations"/>
534 <browser:menus534 <browser:menus
535535
=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
--- lib/lp/translations/browser/tests/translationmessage-views.txt 2011-01-05 19:32:32 +0000
+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2011-10-06 09:01:25 +0000
@@ -99,8 +99,8 @@
99We are at the beginning because this subview is being used for the first99We are at the beginning because this subview is being used for the first
100item.100item.
101101
102 >>> subview.context.potmsgset.sequence == 1102 >>> subview.context.potmsgset.getSequence(pofile.potemplate)
103 True103 1
104104
105It does not have a plural message105It does not have a plural message
106106
@@ -530,8 +530,6 @@
530 >>> pofile = factory.makePOFile('sr')530 >>> pofile = factory.makePOFile('sr')
531 >>> potemplate = pofile.potemplate531 >>> potemplate = pofile.potemplate
532 >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)532 >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)
533 >>> potmsgset.sequence
534 1
535 >>> potmsgset.getSequence(potemplate)533 >>> potmsgset.getSequence(potemplate)
536 1534 1
537 >>> translationmessage = factory.makeCurrentTranslationMessage(535 >>> translationmessage = factory.makeCurrentTranslationMessage(
538536
=== modified file 'lib/lp/translations/doc/pofile.txt'
--- lib/lp/translations/doc/pofile.txt 2011-05-27 19:53:20 +0000
+++ lib/lp/translations/doc/pofile.txt 2011-10-06 09:01:25 +0000
@@ -73,7 +73,7 @@
7373
74We need a helper method to better display test results.74We need a helper method to better display test results.
7575
76 >>> def print_potmsgsets(potmsgsets, pofile=None):76 >>> def print_potmsgsets(potmsgsets, pofile):
77 ... for potmsgset in potmsgsets:77 ... for potmsgset in potmsgsets:
78 ... singular = plural = None78 ... singular = plural = None
79 ... translation = ""79 ... translation = ""
@@ -86,13 +86,16 @@
86 ... if len(plural) > 20:86 ... if len(plural) > 20:
87 ... plural = plural[:17] + "..."87 ... plural = plural[:17] + "..."
88 ... if pofile is not None:88 ... if pofile is not None:
89 ... translation = potmsgset.getCurrentTranslation(89 ... message = potmsgset.getCurrentTranslation(
90 ... pofile.potemplate, pofile.language,90 ... pofile.potemplate, pofile.language,
91 ... pofile.potemplate.translation_side).translations[0]91 ... pofile.potemplate.translation_side)
92 ... if message is not None:
93 ... translation = message.translations[0]
92 ... if len(translation) > 20:94 ... if len(translation) > 20:
93 ... translation = translation[:17] + "..."95 ... translation = translation[:17] + "..."
94 ... print "%2d. %-20s %-20s %-20s" % (96 ... print "%2d. %-20s %-20s %-20s" % (
95 ... potmsgset.sequence, singular, plural, translation)97 ... potmsgset.getSequence(pofile.potemplate),
98 ... singular, plural, translation)
9699
97100
98getFullLanguageCode101getFullLanguageCode
@@ -131,7 +134,7 @@
131 >>> found_potmsgsets.count()134 >>> found_potmsgsets.count()
132 4135 4
133136
134 >>> print_potmsgsets(found_potmsgsets)137 >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
135 7. contact's header: None138 7. contact's header: None
136 14. The location and ... None139 14. The location and ... None
137 15. %d contact %d contacts140 15. %d contact %d contacts
@@ -144,7 +147,7 @@
144 >>> found_potmsgsets.count()147 >>> found_potmsgsets.count()
145 4148 4
146149
147 >>> print_potmsgsets(found_potmsgsets)150 >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
148 7. contact's header: None151 7. contact's header: None
149 14. The location and ... None152 14. The location and ... None
150 15. %d contact %d contacts153 15. %d contact %d contacts
@@ -157,7 +160,7 @@
157 >>> found_potmsgsets.count()160 >>> found_potmsgsets.count()
158 2161 2
159162
160 >>> print_potmsgsets(found_potmsgsets)163 >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
161 15. %d contact %d contacts164 15. %d contact %d contacts
162 16. Opening %d contac... Opening %d contac...165 16. Opening %d contac... Opening %d contac...
163166
164167
=== modified file 'lib/lp/translations/doc/vpotexport.txt'
--- lib/lp/translations/doc/vpotexport.txt 2009-07-29 18:53:50 +0000
+++ lib/lp/translations/doc/vpotexport.txt 2011-10-06 09:01:25 +0000
@@ -1,4 +1,5 @@
1= Template export sets =1Template export sets
2====================
23
3POTemplate.getTranslationRows serialises a template's rows for export.4POTemplate.getTranslationRows serialises a template's rows for export.
45
@@ -15,7 +16,8 @@
15 True16 True
1617
1718
18= Template export set entry =19Template export set entry
20=========================
1921
20VPOTExport represent a row for an entry in the POTemplate. Each row has22VPOTExport represent a row for an entry in the POTemplate. Each row has
21the following information, among other things:23the following information, among other things:
@@ -61,7 +63,7 @@
6163
62 >>> first.sequence64 >>> first.sequence
63 065 0
64 >>> potmsgset.sequence66 >>> potmsgset.getSequence(first.potemplate)
65 067 0
6668
67The POT file header is a template of common information that will get filled69The POT file header is a template of common information that will get filled
6870
=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
--- lib/lp/translations/interfaces/potmsgset.py 2011-03-07 07:17:59 +0000
+++ lib/lp/translations/interfaces/potmsgset.py 2011-10-06 09:01:25 +0000
@@ -95,8 +95,6 @@
95 readonly=True,95 readonly=True,
96 schema=IPOMsgID)96 schema=IPOMsgID)
9797
98 sequence = Attribute("The ordering of this set within its file.")
99
100 commenttext = Attribute("The manual comments this set has.")98 commenttext = Attribute("The manual comments this set has.")
10199
102 filereferences = Attribute("The files where this set appears.")100 filereferences = Attribute("The files where this set appears.")
@@ -195,9 +193,9 @@
195 :param language: language we want translations for.193 :param language: language we want translations for.
196 """194 """
197195
198 def getExternallySuggestedOrUsedTranslationMessages(suggested_languages=(),196 def getExternallySuggestedOrUsedTranslationMessages(
199 used_languages=()):197 suggested_languages=(), used_languages=()):
200 """Find externally suggested or used translations for the same message.198 """Find externally suggested/used translations for the same message.
201199
202 This returns a mapping: language -> namedtuple (suggested, used)200 This returns a mapping: language -> namedtuple (suggested, used)
203 containing the results of201 containing the results of
@@ -342,7 +340,7 @@
342 translation_credits_type = Choice(340 translation_credits_type = Choice(
343 title=u"The type of translation credit of this message.",341 title=u"The type of translation credit of this message.",
344 required=True,342 required=True,
345 vocabulary = TranslationCreditsType)343 vocabulary=TranslationCreditsType)
346344
347 def makeHTMLID(suffix=None):345 def makeHTMLID(suffix=None):
348 """Unique name for this `POTMsgSet` for use in HTML element ids.346 """Unique name for this `POTMsgSet` for use in HTML element ids.
349347
=== modified file 'lib/lp/translations/interfaces/translationmessage.py'
--- lib/lp/translations/interfaces/translationmessage.py 2011-02-23 16:22:52 +0000
+++ lib/lp/translations/interfaces/translationmessage.py 2011-10-06 09:01:25 +0000
@@ -113,6 +113,10 @@
113 title=_("The translation file from where this translation comes"),113 title=_("The translation file from where this translation comes"),
114 readonly=False, required=False, schema=IPOFile)114 readonly=False, required=False, schema=IPOFile)
115115
116 sequence = Int(
117 title=_("Sequence of a message in the PO file browser_pofile."),
118 readonly=True, required=False)
119
116 potemplate = Object(120 potemplate = Object(
117 title=_("The template this translation is in"),121 title=_("The template this translation is in"),
118 readonly=False, required=False, schema=IPOTemplate)122 readonly=False, required=False, schema=IPOTemplate)
119123
=== modified file 'lib/lp/translations/model/pofile.py'
--- lib/lp/translations/model/pofile.py 2011-06-22 09:59:13 +0000
+++ lib/lp/translations/model/pofile.py 2011-10-06 09:01:25 +0000
@@ -1118,7 +1118,7 @@
1118 error_message = error['error-message']1118 error_message = error['error-message']
1119 errorsdetails = '%s%d. "%s":\n\n%s\n\n' % (1119 errorsdetails = '%s%d. "%s":\n\n%s\n\n' % (
1120 errorsdetails,1120 errorsdetails,
1121 potmsgset.sequence,1121 potmsgset.getSequence(self.potemplate),
1122 error_message,1122 error_message,
1123 pomessage)1123 pomessage)
11241124
11251125
=== modified file 'lib/lp/translations/model/potmsgset.py'
--- lib/lp/translations/model/potmsgset.py 2011-07-26 11:53:25 +0000
+++ lib/lp/translations/model/potmsgset.py 2011-10-06 09:01:25 +0000
@@ -18,7 +18,6 @@
1818
19from sqlobject import (19from sqlobject import (
20 ForeignKey,20 ForeignKey,
21 IntCol,
22 SQLObjectNotFound,21 SQLObjectNotFound,
23 StringCol,22 StringCol,
24 )23 )
@@ -139,7 +138,6 @@
139 notNull=True)138 notNull=True)
140 msgid_plural = ForeignKey(foreignKey='POMsgID', dbName='msgid_plural',139 msgid_plural = ForeignKey(foreignKey='POMsgID', dbName='msgid_plural',
141 notNull=False, default=DEFAULT)140 notNull=False, default=DEFAULT)
142 sequence = IntCol(dbName='sequence')
143 commenttext = StringCol(dbName='commenttext', notNull=False)141 commenttext = StringCol(dbName='commenttext', notNull=False)
144 filereferences = StringCol(dbName='filereferences', notNull=False)142 filereferences = StringCol(dbName='filereferences', notNull=False)
145 sourcecomment = StringCol(dbName='sourcecomment', notNull=False)143 sourcecomment = StringCol(dbName='sourcecomment', notNull=False)
@@ -1217,7 +1215,6 @@
12171215
1218 def setSequence(self, potemplate, sequence):1216 def setSequence(self, potemplate, sequence):
1219 """See `IPOTMsgSet`."""1217 """See `IPOTMsgSet`."""
1220 self.sequence = sequence
1221 translation_template_item = TranslationTemplateItem.selectOneBy(1218 translation_template_item = TranslationTemplateItem.selectOneBy(
1222 potmsgset=self, potemplate=potemplate)1219 potmsgset=self, potemplate=potemplate)
1223 if translation_template_item is not None:1220 if translation_template_item is not None:
12241221
=== modified file 'lib/lp/translations/model/translationmessage.py'
--- lib/lp/translations/model/translationmessage.py 2011-02-24 14:31:46 +0000
+++ lib/lp/translations/model/translationmessage.py 2011-10-06 09:01:25 +0000
@@ -114,6 +114,14 @@
114 """See `ITranslationMessage`."""114 """See `ITranslationMessage`."""
115 self.browser_pofile = pofile115 self.browser_pofile = pofile
116116
117 @property
118 def sequence(self):
119 if self.browser_pofile:
120 pofile = self.browser_pofile
121 return self.potmsgset.getSequence(pofile.potemplate)
122 else:
123 return 0
124
117 def markReviewed(self, reviewer, timestamp=None):125 def markReviewed(self, reviewer, timestamp=None):
118 """See `ITranslationMessage`."""126 """See `ITranslationMessage`."""
119 if timestamp is None:127 if timestamp is None:
120128
=== modified file 'lib/lp/translations/templates/pofile-filter.pt'
--- lib/lp/translations/templates/pofile-filter.pt 2009-09-14 10:35:23 +0000
+++ lib/lp/translations/templates/pofile-filter.pt 2011-10-06 09:01:25 +0000
@@ -29,7 +29,7 @@
29 <tal:translations condition="messages">29 <tal:translations condition="messages">
30 <p tal:condition="view/person">30 <p tal:condition="view/person">
31 <a tal:replace="structure view/person/fmt:link"/> has31 <a tal:replace="structure view/person/fmt:link"/> has
32 submitted the following strings to 32 submitted the following strings to
33 <a tal:attributes="href view/context/fmt:url">this translation</a>.33 <a tal:attributes="href view/context/fmt:url">this translation</a>.
34 Contributions are visually coded:34 Contributions are visually coded:
35 <span class="usedtranslation">currently used translations</span>,35 <span class="usedtranslation">currently used translations</span>,
@@ -46,10 +46,10 @@
46 <tal:message repeat="message messages">46 <tal:message repeat="message messages">
47 <tr>47 <tr>
48 <td class="englishstring" style="text-align:right;">48 <td class="englishstring" style="text-align:right;">
49 <tal:obsolete condition="not:message/potmsgset/sequence">49 <tal:obsolete condition="not:message/context/sequence">
50 ~</tal:obsolete>50 ~</tal:obsolete>
51 <tal:nonobsolete condition="message/potmsgset/sequence">51 <tal:nonobsolete condition="message/context/sequence">
52 <a tal:content="string:${message/potmsgset/sequence}."52 <a tal:content="string:${message/context/sequence}."
53 tal:attributes="href message/context/fmt:url" />53 tal:attributes="href message/context/fmt:url" />
54 </tal:nonobsolete>54 </tal:nonobsolete>
55 </td>55 </td>
5656
=== modified file 'lib/lp/translations/tests/test_pofile.py'
--- lib/lp/translations/tests/test_pofile.py 2011-08-03 11:00:11 +0000
+++ lib/lp/translations/tests/test_pofile.py 2011-10-06 09:01:25 +0000
@@ -1356,32 +1356,6 @@
1356 self.assertEquals(1356 self.assertEquals(
1357 [self.potmsgset1, self.potmsgset2], potmsgsets)1357 [self.potmsgset1, self.potmsgset2], potmsgsets)
13581358
1359 def test_findPOTMsgSetsContaining_ordering(self):
1360 # As per bug 388473 findPOTMsgSetsContaining still used the old
1361 # potmsgset.sequence for ordering. Check that this is fixed.
1362 # This test will go away when potmsgset.sequence goes away.
1363
1364 # Give the method something to search for.
1365 self.factory.makeCurrentTranslationMessage(
1366 pofile=self.devel_pofile,
1367 potmsgset=self.potmsgset1,
1368 translations=["Shared translation"])
1369 self.factory.makeCurrentTranslationMessage(
1370 pofile=self.devel_pofile,
1371 potmsgset=self.potmsgset2,
1372 translations=["Another shared translation"])
1373
1374 # Mess with potmsgset.sequence.
1375 removeSecurityProxy(self.potmsgset1).sequence = 2
1376 removeSecurityProxy(self.potmsgset2).sequence = 1
1377
1378 potmsgsets = list(
1379 self.devel_pofile.findPOTMsgSetsContaining("translation"))
1380
1381 # Order ignores potmsgset.sequence.
1382 self.assertEquals(
1383 [self.potmsgset1, self.potmsgset2], potmsgsets)
1384
13851359
1386class TestPOFileSet(TestCaseWithFactory):1360class TestPOFileSet(TestCaseWithFactory):
1387 """Test PO file set methods."""1361 """Test PO file set methods."""