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
1=== modified file 'lib/lp/translations/browser/configure.zcml'
2--- lib/lp/translations/browser/configure.zcml 2011-08-25 19:48:19 +0000
3+++ lib/lp/translations/browser/configure.zcml 2011-10-06 09:01:25 +0000
4@@ -528,7 +528,7 @@
5 layer="lp.translations.publisher.TranslationsLayer"/>
6 <browser:url
7 for="lp.translations.interfaces.translationmessage.ITranslationMessage"
8- path_expression="string:${potmsgset/sequence}"
9+ path_expression="string:${sequence}"
10 attribute_to_parent="browser_pofile"
11 rootsite="translations"/>
12 <browser:menus
13
14=== modified file 'lib/lp/translations/browser/tests/translationmessage-views.txt'
15--- lib/lp/translations/browser/tests/translationmessage-views.txt 2011-01-05 19:32:32 +0000
16+++ lib/lp/translations/browser/tests/translationmessage-views.txt 2011-10-06 09:01:25 +0000
17@@ -99,8 +99,8 @@
18 We are at the beginning because this subview is being used for the first
19 item.
20
21- >>> subview.context.potmsgset.sequence == 1
22- True
23+ >>> subview.context.potmsgset.getSequence(pofile.potemplate)
24+ 1
25
26 It does not have a plural message
27
28@@ -530,8 +530,6 @@
29 >>> pofile = factory.makePOFile('sr')
30 >>> potemplate = pofile.potemplate
31 >>> potmsgset = factory.makePOTMsgSet(potemplate, sequence=1)
32- >>> potmsgset.sequence
33- 1
34 >>> potmsgset.getSequence(potemplate)
35 1
36 >>> translationmessage = factory.makeCurrentTranslationMessage(
37
38=== modified file 'lib/lp/translations/doc/pofile.txt'
39--- lib/lp/translations/doc/pofile.txt 2011-05-27 19:53:20 +0000
40+++ lib/lp/translations/doc/pofile.txt 2011-10-06 09:01:25 +0000
41@@ -73,7 +73,7 @@
42
43 We need a helper method to better display test results.
44
45- >>> def print_potmsgsets(potmsgsets, pofile=None):
46+ >>> def print_potmsgsets(potmsgsets, pofile):
47 ... for potmsgset in potmsgsets:
48 ... singular = plural = None
49 ... translation = ""
50@@ -86,13 +86,16 @@
51 ... if len(plural) > 20:
52 ... plural = plural[:17] + "..."
53 ... if pofile is not None:
54- ... translation = potmsgset.getCurrentTranslation(
55+ ... message = potmsgset.getCurrentTranslation(
56 ... pofile.potemplate, pofile.language,
57- ... pofile.potemplate.translation_side).translations[0]
58+ ... pofile.potemplate.translation_side)
59+ ... if message is not None:
60+ ... translation = message.translations[0]
61 ... if len(translation) > 20:
62 ... translation = translation[:17] + "..."
63 ... print "%2d. %-20s %-20s %-20s" % (
64- ... potmsgset.sequence, singular, plural, translation)
65+ ... potmsgset.getSequence(pofile.potemplate),
66+ ... singular, plural, translation)
67
68
69 getFullLanguageCode
70@@ -131,7 +134,7 @@
71 >>> found_potmsgsets.count()
72 4
73
74- >>> print_potmsgsets(found_potmsgsets)
75+ >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
76 7. contact's header: None
77 14. The location and ... None
78 15. %d contact %d contacts
79@@ -144,7 +147,7 @@
80 >>> found_potmsgsets.count()
81 4
82
83- >>> print_potmsgsets(found_potmsgsets)
84+ >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
85 7. contact's header: None
86 14. The location and ... None
87 15. %d contact %d contacts
88@@ -157,7 +160,7 @@
89 >>> found_potmsgsets.count()
90 2
91
92- >>> print_potmsgsets(found_potmsgsets)
93+ >>> print_potmsgsets(found_potmsgsets, dummy_pofile)
94 15. %d contact %d contacts
95 16. Opening %d contac... Opening %d contac...
96
97
98=== modified file 'lib/lp/translations/doc/vpotexport.txt'
99--- lib/lp/translations/doc/vpotexport.txt 2009-07-29 18:53:50 +0000
100+++ lib/lp/translations/doc/vpotexport.txt 2011-10-06 09:01:25 +0000
101@@ -1,4 +1,5 @@
102-= Template export sets =
103+Template export sets
104+====================
105
106 POTemplate.getTranslationRows serialises a template's rows for export.
107
108@@ -15,7 +16,8 @@
109 True
110
111
112-= Template export set entry =
113+Template export set entry
114+=========================
115
116 VPOTExport represent a row for an entry in the POTemplate. Each row has
117 the following information, among other things:
118@@ -61,7 +63,7 @@
119
120 >>> first.sequence
121 0
122- >>> potmsgset.sequence
123+ >>> potmsgset.getSequence(first.potemplate)
124 0
125
126 The POT file header is a template of common information that will get filled
127
128=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
129--- lib/lp/translations/interfaces/potmsgset.py 2011-03-07 07:17:59 +0000
130+++ lib/lp/translations/interfaces/potmsgset.py 2011-10-06 09:01:25 +0000
131@@ -95,8 +95,6 @@
132 readonly=True,
133 schema=IPOMsgID)
134
135- sequence = Attribute("The ordering of this set within its file.")
136-
137 commenttext = Attribute("The manual comments this set has.")
138
139 filereferences = Attribute("The files where this set appears.")
140@@ -195,9 +193,9 @@
141 :param language: language we want translations for.
142 """
143
144- def getExternallySuggestedOrUsedTranslationMessages(suggested_languages=(),
145- used_languages=()):
146- """Find externally suggested or used translations for the same message.
147+ def getExternallySuggestedOrUsedTranslationMessages(
148+ suggested_languages=(), used_languages=()):
149+ """Find externally suggested/used translations for the same message.
150
151 This returns a mapping: language -> namedtuple (suggested, used)
152 containing the results of
153@@ -342,7 +340,7 @@
154 translation_credits_type = Choice(
155 title=u"The type of translation credit of this message.",
156 required=True,
157- vocabulary = TranslationCreditsType)
158+ vocabulary=TranslationCreditsType)
159
160 def makeHTMLID(suffix=None):
161 """Unique name for this `POTMsgSet` for use in HTML element ids.
162
163=== modified file 'lib/lp/translations/interfaces/translationmessage.py'
164--- lib/lp/translations/interfaces/translationmessage.py 2011-02-23 16:22:52 +0000
165+++ lib/lp/translations/interfaces/translationmessage.py 2011-10-06 09:01:25 +0000
166@@ -113,6 +113,10 @@
167 title=_("The translation file from where this translation comes"),
168 readonly=False, required=False, schema=IPOFile)
169
170+ sequence = Int(
171+ title=_("Sequence of a message in the PO file browser_pofile."),
172+ readonly=True, required=False)
173+
174 potemplate = Object(
175 title=_("The template this translation is in"),
176 readonly=False, required=False, schema=IPOTemplate)
177
178=== modified file 'lib/lp/translations/model/pofile.py'
179--- lib/lp/translations/model/pofile.py 2011-06-22 09:59:13 +0000
180+++ lib/lp/translations/model/pofile.py 2011-10-06 09:01:25 +0000
181@@ -1118,7 +1118,7 @@
182 error_message = error['error-message']
183 errorsdetails = '%s%d. "%s":\n\n%s\n\n' % (
184 errorsdetails,
185- potmsgset.sequence,
186+ potmsgset.getSequence(self.potemplate),
187 error_message,
188 pomessage)
189
190
191=== modified file 'lib/lp/translations/model/potmsgset.py'
192--- lib/lp/translations/model/potmsgset.py 2011-07-26 11:53:25 +0000
193+++ lib/lp/translations/model/potmsgset.py 2011-10-06 09:01:25 +0000
194@@ -18,7 +18,6 @@
195
196 from sqlobject import (
197 ForeignKey,
198- IntCol,
199 SQLObjectNotFound,
200 StringCol,
201 )
202@@ -139,7 +138,6 @@
203 notNull=True)
204 msgid_plural = ForeignKey(foreignKey='POMsgID', dbName='msgid_plural',
205 notNull=False, default=DEFAULT)
206- sequence = IntCol(dbName='sequence')
207 commenttext = StringCol(dbName='commenttext', notNull=False)
208 filereferences = StringCol(dbName='filereferences', notNull=False)
209 sourcecomment = StringCol(dbName='sourcecomment', notNull=False)
210@@ -1217,7 +1215,6 @@
211
212 def setSequence(self, potemplate, sequence):
213 """See `IPOTMsgSet`."""
214- self.sequence = sequence
215 translation_template_item = TranslationTemplateItem.selectOneBy(
216 potmsgset=self, potemplate=potemplate)
217 if translation_template_item is not None:
218
219=== modified file 'lib/lp/translations/model/translationmessage.py'
220--- lib/lp/translations/model/translationmessage.py 2011-02-24 14:31:46 +0000
221+++ lib/lp/translations/model/translationmessage.py 2011-10-06 09:01:25 +0000
222@@ -114,6 +114,14 @@
223 """See `ITranslationMessage`."""
224 self.browser_pofile = pofile
225
226+ @property
227+ def sequence(self):
228+ if self.browser_pofile:
229+ pofile = self.browser_pofile
230+ return self.potmsgset.getSequence(pofile.potemplate)
231+ else:
232+ return 0
233+
234 def markReviewed(self, reviewer, timestamp=None):
235 """See `ITranslationMessage`."""
236 if timestamp is None:
237
238=== modified file 'lib/lp/translations/templates/pofile-filter.pt'
239--- lib/lp/translations/templates/pofile-filter.pt 2009-09-14 10:35:23 +0000
240+++ lib/lp/translations/templates/pofile-filter.pt 2011-10-06 09:01:25 +0000
241@@ -29,7 +29,7 @@
242 <tal:translations condition="messages">
243 <p tal:condition="view/person">
244 <a tal:replace="structure view/person/fmt:link"/> has
245- submitted the following strings to
246+ submitted the following strings to
247 <a tal:attributes="href view/context/fmt:url">this translation</a>.
248 Contributions are visually coded:
249 <span class="usedtranslation">currently used translations</span>,
250@@ -46,10 +46,10 @@
251 <tal:message repeat="message messages">
252 <tr>
253 <td class="englishstring" style="text-align:right;">
254- <tal:obsolete condition="not:message/potmsgset/sequence">
255+ <tal:obsolete condition="not:message/context/sequence">
256 ~</tal:obsolete>
257- <tal:nonobsolete condition="message/potmsgset/sequence">
258- <a tal:content="string:${message/potmsgset/sequence}."
259+ <tal:nonobsolete condition="message/context/sequence">
260+ <a tal:content="string:${message/context/sequence}."
261 tal:attributes="href message/context/fmt:url" />
262 </tal:nonobsolete>
263 </td>
264
265=== modified file 'lib/lp/translations/tests/test_pofile.py'
266--- lib/lp/translations/tests/test_pofile.py 2011-08-03 11:00:11 +0000
267+++ lib/lp/translations/tests/test_pofile.py 2011-10-06 09:01:25 +0000
268@@ -1356,32 +1356,6 @@
269 self.assertEquals(
270 [self.potmsgset1, self.potmsgset2], potmsgsets)
271
272- def test_findPOTMsgSetsContaining_ordering(self):
273- # As per bug 388473 findPOTMsgSetsContaining still used the old
274- # potmsgset.sequence for ordering. Check that this is fixed.
275- # This test will go away when potmsgset.sequence goes away.
276-
277- # Give the method something to search for.
278- self.factory.makeCurrentTranslationMessage(
279- pofile=self.devel_pofile,
280- potmsgset=self.potmsgset1,
281- translations=["Shared translation"])
282- self.factory.makeCurrentTranslationMessage(
283- pofile=self.devel_pofile,
284- potmsgset=self.potmsgset2,
285- translations=["Another shared translation"])
286-
287- # Mess with potmsgset.sequence.
288- removeSecurityProxy(self.potmsgset1).sequence = 2
289- removeSecurityProxy(self.potmsgset2).sequence = 1
290-
291- potmsgsets = list(
292- self.devel_pofile.findPOTMsgSetsContaining("translation"))
293-
294- # Order ignores potmsgset.sequence.
295- self.assertEquals(
296- [self.potmsgset1, self.potmsgset2], potmsgsets)
297-
298
299 class TestPOFileSet(TestCaseWithFactory):
300 """Test PO file set methods."""