Merge ~cjwatson/launchpad:stormify-translationmessage into launchpad:master
- Git
- lp:~cjwatson/launchpad
- stormify-translationmessage
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | 091d151d77bfa4bc125c7e60224820d3503406ba |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:stormify-translationmessage |
Merge into: | launchpad:master |
Diff against target: |
827 lines (+193/-143) 14 files modified
lib/lp/scripts/garbo.py (+1/-1) lib/lp/testing/factory.py (+1/-1) lib/lp/translations/browser/tests/translationmessage-views.rst (+4/-1) lib/lp/translations/doc/potmsgset.rst (+4/-1) lib/lp/translations/doc/translationmessage-destroy.rst (+7/-6) lib/lp/translations/model/currenttranslations.py (+8/-6) lib/lp/translations/model/pofile.py (+29/-28) lib/lp/translations/model/potmsgset.py (+5/-6) lib/lp/translations/model/translationmessage.py (+105/-65) lib/lp/translations/scripts/migrate_current_flag.py (+8/-8) lib/lp/translations/scripts/scrub_pofiletranslator.py (+10/-10) lib/lp/translations/tests/helpers.py (+2/-3) lib/lp/translations/utilities/translationmerger.py (+7/-5) lib/lp/translations/vocabularies.py (+2/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jürgen Gmach | Approve | ||
Review via email: mp+446348@code.launchpad.net |
Commit message
Convert TranslationMessage to Storm
Description of the change
To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py |
2 | index 57dc83a..4c5900b 100644 |
3 | --- a/lib/lp/scripts/garbo.py |
4 | +++ b/lib/lp/scripts/garbo.py |
5 | @@ -1624,7 +1624,7 @@ class UnusedPOTMsgSetPruner(TunableLoop): |
6 | # Remove related TranslationMessages. |
7 | related_translation_messages = store.find( |
8 | TranslationMessage, |
9 | - In(TranslationMessage.potmsgsetID, msgset_ids_to_remove), |
10 | + In(TranslationMessage.potmsgset_id, msgset_ids_to_remove), |
11 | ) |
12 | related_translation_messages.remove() |
13 | store.find(POTMsgSet, In(POTMsgSet.id, msgset_ids_to_remove)).remove() |
14 | diff --git a/lib/lp/testing/factory.py b/lib/lp/testing/factory.py |
15 | index ab55f4b..8764715 100644 |
16 | --- a/lib/lp/testing/factory.py |
17 | +++ b/lib/lp/testing/factory.py |
18 | @@ -4231,7 +4231,7 @@ class LaunchpadObjectFactory(ObjectFactory): |
19 | translation_message |
20 | ) |
21 | naked_translation_message.date_created = date_created |
22 | - naked_translation_message.sync() |
23 | + IStore(naked_translation_message).flush() |
24 | return ProxyFactory(translation_message) |
25 | |
26 | def makeCurrentTranslationMessage( |
27 | diff --git a/lib/lp/translations/browser/tests/translationmessage-views.rst b/lib/lp/translations/browser/tests/translationmessage-views.rst |
28 | index 4b6d758..3c4da4a 100644 |
29 | --- a/lib/lp/translations/browser/tests/translationmessage-views.rst |
30 | +++ b/lib/lp/translations/browser/tests/translationmessage-views.rst |
31 | @@ -4,6 +4,7 @@ TranslationMessage View |
32 | On this section, we are going to test the view class for an |
33 | ITranslationMessage object. |
34 | |
35 | + >>> from lp.services.database.interfaces import IStore |
36 | >>> from lp.services.database.sqlbase import flush_database_updates |
37 | >>> from lp.translations.model.pofile import POFile |
38 | >>> from lp.translations.model.translationmessage import ( |
39 | @@ -24,7 +25,9 @@ No plural forms |
40 | We are going to see what happens if we get an entry for a language |
41 | without the plural form information. |
42 | |
43 | - >>> translationmessage = TranslationMessage.get(1) |
44 | + >>> translationmessage = IStore(TranslationMessage).get( |
45 | + ... TranslationMessage, 1 |
46 | + ... ) |
47 | >>> pofile = POFile.get(1) |
48 | >>> language_tlh = getUtility(ILanguageSet).getLanguageByCode("tlh") |
49 | >>> pofile_tlh = pofile.potemplate.getPlaceholderPOFile(language_tlh) |
50 | diff --git a/lib/lp/translations/doc/potmsgset.rst b/lib/lp/translations/doc/potmsgset.rst |
51 | index 8fa016c..400c533 100644 |
52 | --- a/lib/lp/translations/doc/potmsgset.rst |
53 | +++ b/lib/lp/translations/doc/potmsgset.rst |
54 | @@ -11,6 +11,7 @@ standby database. |
55 | We need to get a POTMsgSet object to perform this test. |
56 | |
57 | >>> from zope.component import getUtility |
58 | + >>> from lp.services.database.interfaces import IStore |
59 | >>> from lp.translations.model.translationmessage import ( |
60 | ... TranslationMessage, |
61 | ... ) |
62 | @@ -284,7 +285,9 @@ isTranslationNewerThan |
63 | This method tells us whether the active translation was reviewed after |
64 | the given timestamp. |
65 | |
66 | - >>> translationmessage = TranslationMessage.get(2) |
67 | + >>> translationmessage = IStore(TranslationMessage).get( |
68 | + ... TranslationMessage, 2 |
69 | + ... ) |
70 | >>> potmsgset = translationmessage.potmsgset |
71 | >>> from lp.translations.model.pofile import POFile |
72 | >>> pofile = POFile.get(1) |
73 | diff --git a/lib/lp/translations/doc/translationmessage-destroy.rst b/lib/lp/translations/doc/translationmessage-destroy.rst |
74 | index 0841544..6c79ec3 100644 |
75 | --- a/lib/lp/translations/doc/translationmessage-destroy.rst |
76 | +++ b/lib/lp/translations/doc/translationmessage-destroy.rst |
77 | @@ -9,6 +9,7 @@ but we test it here to be sure it appears in our public interface. |
78 | |
79 | We will need extra permissions to use this method. |
80 | |
81 | + >>> from lp.services.database.interfaces import IStore |
82 | >>> from lp.translations.model.translationmessage import ( |
83 | ... TranslationMessage, |
84 | ... ) |
85 | @@ -17,15 +18,16 @@ We will need extra permissions to use this method. |
86 | |
87 | Select an existing ITranslationMessage and try to remove it. |
88 | |
89 | - >>> translationmessage = TranslationMessage.get(1) |
90 | + >>> translationmessage = IStore(TranslationMessage).get( |
91 | + ... TranslationMessage, 1 |
92 | + ... ) |
93 | >>> translationmessage.destroySelf() |
94 | |
95 | It should not exist now. |
96 | |
97 | - >>> translationmessage = TranslationMessage.get(1) |
98 | - Traceback (most recent call last): |
99 | - ... |
100 | - storm.sqlobject.SQLObjectNotFound: ... |
101 | + >>> translationmessage = IStore(TranslationMessage).get( |
102 | + ... TranslationMessage, 1 |
103 | + ... ) |
104 | |
105 | |
106 | POFileTranslator update on remove |
107 | @@ -37,7 +39,6 @@ translation, we get two POFileTranslator records for each of the POFiles. |
108 | # We need to be able to create persons and projects so let's just use |
109 | # a global 'postgres' permission which allows everything. |
110 | >>> switch_dbuser("postgres") |
111 | - >>> from lp.services.database.interfaces import IStore |
112 | >>> from lp.app.enums import ServiceUsage |
113 | >>> from lp.testing.factory import LaunchpadObjectFactory |
114 | >>> from lp.translations.model.pofiletranslator import POFileTranslator |
115 | diff --git a/lib/lp/translations/model/currenttranslations.py b/lib/lp/translations/model/currenttranslations.py |
116 | index 8bb108b..84688a0 100644 |
117 | --- a/lib/lp/translations/model/currenttranslations.py |
118 | +++ b/lib/lp/translations/model/currenttranslations.py |
119 | @@ -59,8 +59,10 @@ class CurrentTranslations: |
120 | raise ValueError("sides must not be empty") |
121 | |
122 | clauses = [ |
123 | - TranslationMessage.potmsgsetID.is_in(s.id for s in potmsgsets), |
124 | - TranslationMessage.languageID.is_in(lang.id for lang in languages), |
125 | + TranslationMessage.potmsgset_id.is_in(s.id for s in potmsgsets), |
126 | + TranslationMessage.language_id.is_in( |
127 | + lang.id for lang in languages |
128 | + ), |
129 | ] |
130 | |
131 | side_clauses = [] |
132 | @@ -78,7 +80,7 @@ class CurrentTranslations: |
133 | clauses.append( |
134 | Or( |
135 | TranslationMessage.potemplate == None, |
136 | - TranslationMessage.potemplateID.is_in( |
137 | + TranslationMessage.potemplate_id.is_in( |
138 | t.id for t in potemplates if t is not None |
139 | ), |
140 | ) |
141 | @@ -92,9 +94,9 @@ class CurrentTranslations: |
142 | if not trait.getFlag(message): |
143 | continue |
144 | key = CurrentTranslationKey( |
145 | - message.potmsgsetID, |
146 | - message.potemplateID, |
147 | - message.languageID, |
148 | + message.potmsgset_id, |
149 | + message.potemplate_id, |
150 | + message.language_id, |
151 | side, |
152 | ) |
153 | messages_by_key[key] = message |
154 | diff --git a/lib/lp/translations/model/pofile.py b/lib/lp/translations/model/pofile.py |
155 | index 6539f65..232927a 100644 |
156 | --- a/lib/lp/translations/model/pofile.py |
157 | +++ b/lib/lp/translations/model/pofile.py |
158 | @@ -154,7 +154,7 @@ class POFileMixIn(RosettaStats): |
159 | tm_ids, |
160 | Join( |
161 | TranslationTemplateItem, |
162 | - tm_ids.potmsgsetID |
163 | + tm_ids.potmsgset_id |
164 | == TranslationTemplateItem.potmsgset_id, |
165 | ), |
166 | ), |
167 | @@ -162,7 +162,7 @@ class POFileMixIn(RosettaStats): |
168 | TranslationTemplateItem.potemplate |
169 | == pofile.potemplate, |
170 | TranslationTemplateItem.sequence > 0, |
171 | - tm_ids.languageID == pofile.languageID, |
172 | + tm_ids.language_id == pofile.languageID, |
173 | ), |
174 | distinct=True, |
175 | ) |
176 | @@ -175,7 +175,7 @@ class POFileMixIn(RosettaStats): |
177 | ), |
178 | ] |
179 | return Select( |
180 | - TranslationMessage.potmsgsetID, |
181 | + TranslationMessage.potmsgset_id, |
182 | tables=( |
183 | TranslationMessage, |
184 | Join( |
185 | @@ -386,11 +386,11 @@ class POFile(SQLBase, POFileMixIn): |
186 | def getTranslationMessages(self, condition=None): |
187 | """See `IPOFile`.""" |
188 | applicable_template = Coalesce( |
189 | - TranslationMessage.potemplateID, self.potemplate.id |
190 | + TranslationMessage.potemplate_id, self.potemplate.id |
191 | ) |
192 | clauses = [ |
193 | TranslationTemplateItem.potmsgset_id |
194 | - == TranslationMessage.potmsgsetID, |
195 | + == TranslationMessage.potmsgset_id, |
196 | TranslationTemplateItem.potemplate == self.potemplate, |
197 | TranslationMessage.language == self.language, |
198 | applicable_template == self.potemplate.id, |
199 | @@ -536,7 +536,7 @@ class POFile(SQLBase, POFileMixIn): |
200 | TranslationTemplateItem.potemplate == self.potemplate, |
201 | ( |
202 | TranslationTemplateItem.potmsgset_id |
203 | - == TranslationMessage.potmsgsetID |
204 | + == TranslationMessage.potmsgset_id |
205 | ), |
206 | TranslationMessage.language == self.language, |
207 | ] |
208 | @@ -580,23 +580,23 @@ class POFile(SQLBase, POFileMixIn): |
209 | # * (it's diverged AND non-empty) |
210 | # OR (it's shared AND non-empty AND no diverged one exists) |
211 | diverged_translation_clause = ( |
212 | - TranslationMessage.potemplateID == self.potemplate.id, |
213 | + TranslationMessage.potemplate_id == self.potemplate.id, |
214 | ) |
215 | |
216 | Diverged = ClassAlias(TranslationMessage, "Diverged") |
217 | shared_translation_clause = And( |
218 | - TranslationMessage.potemplateID == None, |
219 | + TranslationMessage.potemplate_id == None, |
220 | Not( |
221 | Exists( |
222 | Select( |
223 | 1, |
224 | tables=[Diverged], |
225 | where=And( |
226 | - Diverged.potmsgsetID |
227 | - == TranslationMessage.potmsgsetID, |
228 | - Diverged.languageID == self.language.id, |
229 | + Diverged.potmsgset_id |
230 | + == TranslationMessage.potmsgset_id, |
231 | + Diverged.language_id == self.language.id, |
232 | getattr(Diverged, flag_name), |
233 | - Diverged.potemplateID == self.potemplate.id, |
234 | + Diverged.potemplate_id == self.potemplate.id, |
235 | ), |
236 | ) |
237 | ) |
238 | @@ -674,10 +674,10 @@ class POFile(SQLBase, POFileMixIn): |
239 | Coalesce(Diverged.date_reviewed, Diverged.date_created), |
240 | tables=[Diverged], |
241 | where=And( |
242 | - Diverged.potmsgsetID == POTMsgSet.id, |
243 | - Diverged.languageID == self.language.id, |
244 | + Diverged.potmsgset_id == POTMsgSet.id, |
245 | + Diverged.language_id == self.language.id, |
246 | getattr(Diverged, flag_name), |
247 | - Diverged.potemplateID == self.potemplate.id, |
248 | + Diverged.potemplate_id == self.potemplate.id, |
249 | ), |
250 | ) |
251 | |
252 | @@ -686,10 +686,10 @@ class POFile(SQLBase, POFileMixIn): |
253 | Coalesce(Shared.date_reviewed, Shared.date_created), |
254 | tables=[Shared], |
255 | where=And( |
256 | - Shared.potmsgsetID == POTMsgSet.id, |
257 | - Shared.languageID == self.language.id, |
258 | + Shared.potmsgset_id == POTMsgSet.id, |
259 | + Shared.language_id == self.language.id, |
260 | getattr(Shared, flag_name), |
261 | - Shared.potemplateID == None, |
262 | + Shared.potemplate_id == None, |
263 | ), |
264 | ) |
265 | |
266 | @@ -708,7 +708,7 @@ class POFile(SQLBase, POFileMixIn): |
267 | query = And( |
268 | POTMsgSet.id.is_in( |
269 | Select( |
270 | - TranslationMessage.potmsgsetID, |
271 | + TranslationMessage.potmsgset_id, |
272 | tables=[ |
273 | TranslationMessage, |
274 | TranslationTemplateItem, |
275 | @@ -753,22 +753,23 @@ class POFile(SQLBase, POFileMixIn): |
276 | tables=[Diverged], |
277 | where=And( |
278 | Diverged.id != Imported.id, |
279 | - Diverged.potmsgsetID == TranslationMessage.potmsgsetID, |
280 | - Diverged.languageID == self.language.id, |
281 | + Diverged.potmsgset_id |
282 | + == TranslationMessage.potmsgset_id, |
283 | + Diverged.language_id == self.language.id, |
284 | getattr(Diverged, other_side_flag_name), |
285 | - Diverged.potemplateID == self.potemplate.id, |
286 | + Diverged.potemplate_id == self.potemplate.id, |
287 | ), |
288 | ) |
289 | ) |
290 | ) |
291 | imported_clauses = [ |
292 | Imported.id != TranslationMessage.id, |
293 | - Imported.potmsgsetID == POTMsgSet.id, |
294 | - Imported.languageID == self.language.id, |
295 | + Imported.potmsgset_id == POTMsgSet.id, |
296 | + Imported.language_id == self.language.id, |
297 | getattr(Imported, other_side_flag_name), |
298 | Or( |
299 | - Imported.potemplateID == self.potemplate.id, |
300 | - And(Imported.potemplateID == None, imported_no_diverged), |
301 | + Imported.potemplate_id == self.potemplate.id, |
302 | + And(Imported.potemplate_id == None, imported_no_diverged), |
303 | ), |
304 | ] |
305 | imported_clauses.extend( |
306 | @@ -1635,9 +1636,9 @@ class POFileSet: |
307 | message_select = Select( |
308 | True, |
309 | And( |
310 | - TranslationMessage.potmsgsetID == POTMsgSet.id, |
311 | + TranslationMessage.potmsgset_id == POTMsgSet.id, |
312 | TranslationMessage.potemplate == None, |
313 | - POFile.languageID == TranslationMessage.languageID, |
314 | + POFile.languageID == TranslationMessage.language_id, |
315 | Or( |
316 | And( |
317 | POTemplate.productseries == None, |
318 | diff --git a/lib/lp/translations/model/potmsgset.py b/lib/lp/translations/model/potmsgset.py |
319 | index 4635d5c..9cdefa0 100644 |
320 | --- a/lib/lp/translations/model/potmsgset.py |
321 | +++ b/lib/lp/translations/model/potmsgset.py |
322 | @@ -398,19 +398,19 @@ class POTMsgSet(SQLBase): |
323 | lang_used = [] |
324 | if both_languages: |
325 | lang_used.append( |
326 | - TranslationMessage.languageID.is_in(both_languages) |
327 | + TranslationMessage.language_id.is_in(both_languages) |
328 | ) |
329 | if used_languages: |
330 | lang_used.append( |
331 | And( |
332 | - TranslationMessage.languageID.is_in(used_languages), |
333 | + TranslationMessage.language_id.is_in(used_languages), |
334 | in_use_clause, |
335 | ) |
336 | ) |
337 | if suggested_languages: |
338 | lang_used.append( |
339 | And( |
340 | - TranslationMessage.languageID.is_in(suggested_languages), |
341 | + TranslationMessage.language_id.is_in(suggested_languages), |
342 | Not(in_use_clause), |
343 | ) |
344 | ) |
345 | @@ -626,9 +626,9 @@ class POTMsgSet(SQLBase): |
346 | # Prefer either shared or diverged messages, depending on |
347 | # arguments. |
348 | if prefer_shared: |
349 | - order = [NullsFirst(TranslationMessage.potemplateID)] |
350 | + order = [NullsFirst(TranslationMessage.potemplate_id)] |
351 | else: |
352 | - order = [NullsLast(TranslationMessage.potemplateID)] |
353 | + order = [NullsLast(TranslationMessage.potemplate_id)] |
354 | |
355 | # Normally at most one message should match. But if there is |
356 | # more than one, prefer the one that adds the fewest extraneous |
357 | @@ -829,7 +829,6 @@ class POTMsgSet(SQLBase): |
358 | return TranslationMessage( |
359 | potmsgset=self, |
360 | potemplate=potemplate, |
361 | - pofile=pofile, |
362 | language=pofile.language, |
363 | origin=origin, |
364 | submitter=submitter, |
365 | diff --git a/lib/lp/translations/model/translationmessage.py b/lib/lp/translations/model/translationmessage.py |
366 | index 25403fb..0265f4d 100644 |
367 | --- a/lib/lp/translations/model/translationmessage.py |
368 | +++ b/lib/lp/translations/model/translationmessage.py |
369 | @@ -12,25 +12,20 @@ __all__ = [ |
370 | from datetime import datetime, timezone |
371 | |
372 | from storm.expr import And |
373 | -from storm.locals import SQL, Int, Reference |
374 | +from storm.locals import SQL, Bool, DateTime, Int, Reference, Unicode |
375 | from storm.store import Store |
376 | from zope.component import getUtility |
377 | from zope.interface import implementer |
378 | from zope.security.proxy import removeSecurityProxy |
379 | |
380 | +from lp.app.errors import NotFoundError |
381 | from lp.registry.interfaces.person import IPersonSet, validate_public_person |
382 | from lp.services.database.bulk import load, load_related |
383 | from lp.services.database.constants import DEFAULT, UTC_NOW |
384 | -from lp.services.database.datetimecol import UtcDateTimeCol |
385 | from lp.services.database.enumcol import DBEnum |
386 | from lp.services.database.interfaces import IStore |
387 | -from lp.services.database.sqlbase import SQLBase, quote, sqlvalues |
388 | -from lp.services.database.sqlobject import ( |
389 | - BoolCol, |
390 | - ForeignKey, |
391 | - SQLObjectNotFound, |
392 | - StringCol, |
393 | -) |
394 | +from lp.services.database.sqlbase import sqlvalues |
395 | +from lp.services.database.stormbase import StormBase |
396 | from lp.services.propertycache import cachedproperty, get_property_cache |
397 | from lp.translations.interfaces.currenttranslations import ICurrentTranslations |
398 | from lp.translations.interfaces.potemplate import IPOTemplateSet |
399 | @@ -222,41 +217,40 @@ class PlaceholderTranslationMessage(TranslationMessageMixIn): |
400 | |
401 | |
402 | @implementer(ITranslationMessage) |
403 | -class TranslationMessage(SQLBase, TranslationMessageMixIn): |
404 | - _table = "TranslationMessage" |
405 | +class TranslationMessage(StormBase, TranslationMessageMixIn): |
406 | + __storm_table__ = "TranslationMessage" |
407 | |
408 | + id = Int(primary=True) |
409 | browser_pofile = None |
410 | - potemplate = ForeignKey( |
411 | - foreignKey="POTemplate", |
412 | - dbName="potemplate", |
413 | - notNull=False, |
414 | - default=None, |
415 | - ) |
416 | - language = ForeignKey( |
417 | - foreignKey="Language", dbName="language", notNull=False, default=None |
418 | - ) |
419 | - potmsgset = ForeignKey( |
420 | - foreignKey="POTMsgSet", dbName="potmsgset", notNull=True |
421 | - ) |
422 | - date_created = UtcDateTimeCol( |
423 | - dbName="date_created", notNull=True, default=UTC_NOW |
424 | + potemplate_id = Int(name="potemplate", allow_none=True, default=None) |
425 | + potemplate = Reference(potemplate_id, "POTemplate.id") |
426 | + language_id = Int(name="language", allow_none=True, default=None) |
427 | + language = Reference(language_id, "Language.id") |
428 | + potmsgset_id = Int(name="potmsgset", allow_none=False) |
429 | + potmsgset = Reference(potmsgset_id, "POTMsgSet.id") |
430 | + date_created = DateTime( |
431 | + name="date_created", |
432 | + allow_none=False, |
433 | + default=UTC_NOW, |
434 | + tzinfo=timezone.utc, |
435 | ) |
436 | - submitter = ForeignKey( |
437 | - foreignKey="Person", |
438 | - storm_validator=validate_public_person, |
439 | - dbName="submitter", |
440 | - notNull=True, |
441 | + submitter_id = Int( |
442 | + name="submitter", validator=validate_public_person, allow_none=False |
443 | ) |
444 | - date_reviewed = UtcDateTimeCol( |
445 | - dbName="date_reviewed", notNull=False, default=None |
446 | + submitter = Reference(submitter_id, "Person.id") |
447 | + date_reviewed = DateTime( |
448 | + name="date_reviewed", |
449 | + allow_none=True, |
450 | + default=None, |
451 | + tzinfo=timezone.utc, |
452 | ) |
453 | - reviewer = ForeignKey( |
454 | - dbName="reviewer", |
455 | - foreignKey="Person", |
456 | - storm_validator=validate_public_person, |
457 | - notNull=False, |
458 | + reviewer_id = Int( |
459 | + name="reviewer", |
460 | + validator=validate_public_person, |
461 | + allow_none=True, |
462 | default=None, |
463 | ) |
464 | + reviewer = Reference(reviewer_id, "Person.id") |
465 | |
466 | assert TranslationConstants.MAX_PLURAL_FORMS == 6, ( |
467 | "Change this code to support %d plural forms." |
468 | @@ -276,7 +270,7 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
469 | msgstr5_id = Int(name="msgstr5", allow_none=True, default=DEFAULT) |
470 | msgstr5 = Reference(msgstr5_id, "POTranslation.id") |
471 | |
472 | - comment = StringCol(dbName="comment", notNull=False, default=None) |
473 | + comment = Unicode(name="comment", allow_none=True, default=None) |
474 | origin = DBEnum( |
475 | name="origin", allow_none=False, enum=RosettaTranslationOrigin |
476 | ) |
477 | @@ -285,16 +279,59 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
478 | allow_none=False, |
479 | enum=TranslationValidationStatus, |
480 | ) |
481 | - is_current_ubuntu = BoolCol( |
482 | - dbName="is_current_ubuntu", notNull=True, default=False |
483 | + is_current_ubuntu = Bool( |
484 | + name="is_current_ubuntu", allow_none=False, default=False |
485 | ) |
486 | - is_current_upstream = BoolCol( |
487 | - dbName="is_current_upstream", notNull=True, default=False |
488 | + is_current_upstream = Bool( |
489 | + name="is_current_upstream", allow_none=False, default=False |
490 | ) |
491 | - was_obsolete_in_last_import = BoolCol( |
492 | - dbName="was_obsolete_in_last_import", notNull=True, default=False |
493 | + was_obsolete_in_last_import = Bool( |
494 | + name="was_obsolete_in_last_import", allow_none=False, default=False |
495 | ) |
496 | |
497 | + def __init__( |
498 | + self, |
499 | + potmsgset, |
500 | + submitter, |
501 | + potemplate=None, |
502 | + language=None, |
503 | + date_created=DEFAULT, |
504 | + date_reviewed=None, |
505 | + reviewer=None, |
506 | + msgstr0=None, |
507 | + msgstr1=None, |
508 | + msgstr2=None, |
509 | + msgstr3=None, |
510 | + msgstr4=None, |
511 | + msgstr5=None, |
512 | + comment=None, |
513 | + origin=None, |
514 | + validation_status=DEFAULT, |
515 | + is_current_ubuntu=DEFAULT, |
516 | + is_current_upstream=DEFAULT, |
517 | + was_obsolete_in_last_import=DEFAULT, |
518 | + ): |
519 | + super().__init__() |
520 | + self.potmsgset = potmsgset |
521 | + self.submitter = submitter |
522 | + self.potemplate = potemplate |
523 | + self.language = language |
524 | + self.date_created = date_created |
525 | + self.date_reviewed = date_reviewed |
526 | + self.reviewer = reviewer |
527 | + self.msgstr0 = msgstr0 |
528 | + self.msgstr1 = msgstr1 |
529 | + self.msgstr2 = msgstr2 |
530 | + self.msgstr3 = msgstr3 |
531 | + self.msgstr4 = msgstr4 |
532 | + self.msgstr5 = msgstr5 |
533 | + self.comment = comment |
534 | + self.origin = origin |
535 | + self.validation_status = validation_status |
536 | + self.is_current_ubuntu = is_current_ubuntu |
537 | + self.is_current_upstream = is_current_upstream |
538 | + self.was_obsolete_in_last_import = was_obsolete_in_last_import |
539 | + |
540 | # XXX jamesh 2008-05-02: |
541 | # This method is not being called anymore. The Storm |
542 | # validator code doesn't handle getters. |
543 | @@ -436,7 +473,7 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
544 | FROM TranslationTemplateItem |
545 | WHERE potmsgset = %s AND sequence > 0 |
546 | LIMIT 1)""" |
547 | - % sqlvalues(self.potmsgsetID) |
548 | + % sqlvalues(self.potmsgset_id) |
549 | ), |
550 | POFile.language == self.language, |
551 | ) |
552 | @@ -453,22 +490,22 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
553 | def getSharedEquivalent(self): |
554 | """See `ITranslationMessage`.""" |
555 | clauses = [ |
556 | - "potemplate IS NULL", |
557 | - "potmsgset = %s" % sqlvalues(self.potmsgset), |
558 | - "language = %s" % sqlvalues(self.language), |
559 | + TranslationMessage.potemplate == None, |
560 | + TranslationMessage.potmsgset == self.potmsgset, |
561 | + TranslationMessage.language == self.language, |
562 | ] |
563 | |
564 | for form in range(TranslationConstants.MAX_PLURAL_FORMS): |
565 | - msgstr_name = "msgstr%d" % form |
566 | - msgstr = getattr(self, "msgstr%d_id" % form) |
567 | + msgstr_name = "msgstr%d_id" % form |
568 | + msgstr_property = getattr(TranslationMessage, msgstr_name) |
569 | + msgstr = getattr(self, msgstr_name) |
570 | if msgstr is None: |
571 | - form_clause = "%s IS NULL" % msgstr_name |
572 | + form_clause = msgstr_property == None |
573 | else: |
574 | - form_clause = "%s = %s" % (msgstr_name, quote(msgstr)) |
575 | + form_clause = msgstr_property == msgstr |
576 | clauses.append(form_clause) |
577 | |
578 | - where_clause = SQL(" AND ".join(clauses)) |
579 | - return Store.of(self).find(TranslationMessage, where_clause).one() |
580 | + return Store.of(self).find(TranslationMessage, *clauses).one() |
581 | |
582 | def shareIfPossible(self): |
583 | """See `ITranslationMessage`.""" |
584 | @@ -537,8 +574,8 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
585 | |
586 | forms_match = TranslationMessage.msgstr0_id == self.msgstr0_id |
587 | for form in range(1, TranslationConstants.MAX_PLURAL_FORMS): |
588 | - form_name = "msgstr%d" % form |
589 | - form_value = getattr(self, "msgstr%d_id" % form) |
590 | + form_name = "msgstr%d_id" % form |
591 | + form_value = getattr(self, form_name) |
592 | forms_match = And( |
593 | forms_match, |
594 | getattr(TranslationMessage, form_name) == form_value, |
595 | @@ -580,6 +617,9 @@ class TranslationMessage(SQLBase, TranslationMessageMixIn): |
596 | ) |
597 | return clone |
598 | |
599 | + def destroySelf(self): |
600 | + Store.of(self).remove(self) |
601 | + |
602 | |
603 | @implementer(ITranslationMessageSet) |
604 | class TranslationMessageSet: |
605 | @@ -587,10 +627,10 @@ class TranslationMessageSet: |
606 | |
607 | def getByID(self, ID): |
608 | """See `ITranslationMessageSet`.""" |
609 | - try: |
610 | - return TranslationMessage.get(ID) |
611 | - except SQLObjectNotFound: |
612 | - return None |
613 | + tm = IStore(TranslationMessage).get(TranslationMessage, ID) |
614 | + if tm is None: |
615 | + raise NotFoundError(ID) |
616 | + return tm |
617 | |
618 | def preloadDetails( |
619 | self, |
620 | @@ -636,12 +676,12 @@ class TranslationMessageSet: |
621 | ], |
622 | ) |
623 | if need_potmsgset: |
624 | - load_related(POTMsgSet, tms, ["potmsgsetID"]) |
625 | + load_related(POTMsgSet, tms, ["potmsgset_id"]) |
626 | if need_people: |
627 | list( |
628 | getUtility(IPersonSet).getPrecachedPersonsFromIDs( |
629 | - [tm.submitterID for tm in tms] |
630 | - + [tm.reviewerID for tm in tms] |
631 | + [tm.submitter_id for tm in tms] |
632 | + + [tm.reviewer_id for tm in tms] |
633 | ) |
634 | ) |
635 | if need_potmsgset_current_message: |
636 | @@ -685,7 +725,7 @@ class TranslationMessageSet: |
637 | TranslationTemplateItem.sequence, |
638 | ), |
639 | TranslationTemplateItem.potmsgset_id.is_in( |
640 | - message.potmsgsetID for message in messages |
641 | + message.potmsgset_id for message in messages |
642 | ), |
643 | POFile.potemplateID == TranslationTemplateItem.potemplate_id, |
644 | *pofile_constraints, |
645 | @@ -700,6 +740,6 @@ class TranslationMessageSet: |
646 | for message in messages: |
647 | assert message.language == language |
648 | pofile_id, sequence = potmsgset_map.get( |
649 | - message.potmsgsetID, (None, None) |
650 | + message.potmsgset_id, (None, None) |
651 | ) |
652 | message.setPOFile(IStore(POFile).get(POFile, pofile_id), sequence) |
653 | diff --git a/lib/lp/translations/scripts/migrate_current_flag.py b/lib/lp/translations/scripts/migrate_current_flag.py |
654 | index 0b09102..26046bf 100644 |
655 | --- a/lib/lp/translations/scripts/migrate_current_flag.py |
656 | +++ b/lib/lp/translations/scripts/migrate_current_flag.py |
657 | @@ -64,20 +64,20 @@ class TranslationMessageImportedFlagUpdater: |
658 | where=And( |
659 | PreviousImported.is_current_upstream == True, |
660 | ( |
661 | - PreviousImported.potmsgsetID |
662 | - == CurrentTranslation.potmsgsetID |
663 | + PreviousImported.potmsgset_id |
664 | + == CurrentTranslation.potmsgset_id |
665 | ), |
666 | Or( |
667 | And( |
668 | - PreviousImported.potemplateID == None, |
669 | - CurrentTranslation.potemplateID == None, |
670 | + PreviousImported.potemplate_id == None, |
671 | + CurrentTranslation.potemplate_id == None, |
672 | ), |
673 | ( |
674 | - PreviousImported.potemplateID |
675 | - == CurrentTranslation.potemplateID |
676 | + PreviousImported.potemplate_id |
677 | + == CurrentTranslation.potemplate_id |
678 | ), |
679 | ), |
680 | - PreviousImported.languageID == CurrentTranslation.languageID, |
681 | + PreviousImported.language_id == CurrentTranslation.language_id, |
682 | CurrentTranslation.id.is_in(tm_ids), |
683 | ), |
684 | ) |
685 | @@ -147,7 +147,7 @@ class MigrateCurrentFlagProcess: |
686 | TranslationMessage.is_current_ubuntu == True, |
687 | TranslationMessage.is_current_upstream == False, |
688 | ( |
689 | - TranslationMessage.potmsgsetID |
690 | + TranslationMessage.potmsgset_id |
691 | == TranslationTemplateItem.potmsgset_id |
692 | ), |
693 | TranslationTemplateItem.potemplate_id == POTemplate.id, |
694 | diff --git a/lib/lp/translations/scripts/scrub_pofiletranslator.py b/lib/lp/translations/scripts/scrub_pofiletranslator.py |
695 | index 7aa0cb1..dccade1 100644 |
696 | --- a/lib/lp/translations/scripts/scrub_pofiletranslator.py |
697 | +++ b/lib/lp/translations/scripts/scrub_pofiletranslator.py |
698 | @@ -84,11 +84,11 @@ def summarize_contributors(potemplate_id, language_ids, potmsgset_ids): |
699 | store = IStore(POFile) |
700 | contribs = {language_id: set() for language_id in language_ids} |
701 | for language_id, submitter_id in store.find( |
702 | - (TranslationMessage.languageID, TranslationMessage.submitterID), |
703 | - TranslationMessage.potmsgsetID.is_in(potmsgset_ids), |
704 | - TranslationMessage.languageID.is_in(language_ids), |
705 | + (TranslationMessage.language_id, TranslationMessage.submitter_id), |
706 | + TranslationMessage.potmsgset_id.is_in(potmsgset_ids), |
707 | + TranslationMessage.language_id.is_in(language_ids), |
708 | TranslationMessage.msgstr0 != None, |
709 | - Coalesce(TranslationMessage.potemplateID, potemplate_id) |
710 | + Coalesce(TranslationMessage.potemplate_id, potemplate_id) |
711 | == potemplate_id, |
712 | ).config(distinct=True): |
713 | contribs[language_id].add(submitter_id) |
714 | @@ -114,15 +114,15 @@ def get_contributions(pofile, potmsgset_ids): |
715 | language_id = pofile.language.id |
716 | template_id = pofile.potemplate.id |
717 | contribs = store.find( |
718 | - (TranslationMessage.submitterID, TranslationMessage.date_created), |
719 | - TranslationMessage.potmsgsetID.is_in(potmsgset_ids), |
720 | - TranslationMessage.languageID == language_id, |
721 | + (TranslationMessage.submitter_id, TranslationMessage.date_created), |
722 | + TranslationMessage.potmsgset_id.is_in(potmsgset_ids), |
723 | + TranslationMessage.language_id == language_id, |
724 | TranslationMessage.msgstr0 != None, |
725 | - Coalesce(TranslationMessage.potemplateID, template_id) == template_id, |
726 | + Coalesce(TranslationMessage.potemplate_id, template_id) == template_id, |
727 | ) |
728 | - contribs = contribs.config(distinct=(TranslationMessage.submitterID,)) |
729 | + contribs = contribs.config(distinct=(TranslationMessage.submitter_id,)) |
730 | contribs = contribs.order_by( |
731 | - TranslationMessage.submitterID, Desc(TranslationMessage.date_created) |
732 | + TranslationMessage.submitter_id, Desc(TranslationMessage.date_created) |
733 | ) |
734 | return dict(contribs) |
735 | |
736 | diff --git a/lib/lp/translations/tests/helpers.py b/lib/lp/translations/tests/helpers.py |
737 | index ffd1ec9..ed55ceb 100644 |
738 | --- a/lib/lp/translations/tests/helpers.py |
739 | +++ b/lib/lp/translations/tests/helpers.py |
740 | @@ -7,7 +7,7 @@ __all__ = [ |
741 | "make_translationmessage_for_context", |
742 | ] |
743 | |
744 | -from storm.expr import Or |
745 | +from storm.expr import Desc, Or |
746 | from storm.store import Store |
747 | from zope.component import getUtility |
748 | from zope.security.proxy import removeSecurityProxy |
749 | @@ -82,7 +82,6 @@ def make_translationmessage( |
750 | new_message = TranslationMessage( |
751 | potmsgset=potmsgset, |
752 | potemplate=potemplate, |
753 | - pofile=None, |
754 | language=pofile.language, |
755 | origin=origin, |
756 | submitter=submitter, |
757 | @@ -115,7 +114,7 @@ def get_all_translations_diverged_anywhere(pofile, potmsgset): |
758 | TranslationMessage.potemplate != pofile.potemplate, |
759 | TranslationMessage.language == pofile.language, |
760 | ) |
761 | - return result.order_by(-TranslationMessage.potemplateID) |
762 | + return result.order_by(Desc(TranslationMessage.potemplate_id)) |
763 | |
764 | |
765 | def summarize_current_translations(pofile, potmsgset): |
766 | diff --git a/lib/lp/translations/utilities/translationmerger.py b/lib/lp/translations/utilities/translationmerger.py |
767 | index 7992a65..3963227 100644 |
768 | --- a/lib/lp/translations/utilities/translationmerger.py |
769 | +++ b/lib/lp/translations/utilities/translationmerger.py |
770 | @@ -642,7 +642,9 @@ class TranslationMerger: |
771 | |
772 | for ids in tm_ids: |
773 | for id in ids: |
774 | - message = TranslationMessage.get(id) |
775 | + message = IStore(TranslationMessage).get( |
776 | + TranslationMessage, id |
777 | + ) |
778 | removeSecurityProxy(message).shareIfPossible() |
779 | |
780 | self.tm.endTransaction(intermediate=True) |
781 | @@ -671,7 +673,7 @@ class TranslationMerger: |
782 | for form in range(TranslationConstants.MAX_PLURAL_FORMS) |
783 | ) |
784 | |
785 | - return (tm.potemplateID, tm.languageID) + msgstr_ids |
786 | + return (tm.potemplate_id, tm.language_id) + msgstr_ids |
787 | |
788 | @staticmethod |
789 | def _partitionTranslationMessageIds(potmsgset): |
790 | @@ -687,10 +689,10 @@ class TranslationMerger: |
791 | """ |
792 | ids_per_language = {} |
793 | tms = potmsgset.getAllTranslationMessages().order_by( |
794 | - TranslationMessage.languageID |
795 | + TranslationMessage.language_id |
796 | ) |
797 | for tm in tms: |
798 | - language = removeSecurityProxy(tm).languageID |
799 | + language = removeSecurityProxy(tm).language_id |
800 | if language not in ids_per_language: |
801 | ids_per_language[language] = [] |
802 | ids_per_language[language].append(tm.id) |
803 | @@ -719,7 +721,7 @@ class TranslationMerger: |
804 | translations = {} |
805 | |
806 | for tm_id in ids: |
807 | - tm = TranslationMessage.get(tm_id) |
808 | + tm = IStore(TranslationMessage).get(TranslationMessage, tm_id) |
809 | key = self._getPOTMsgSetTranslationMessageKey(tm) |
810 | |
811 | if key in translations: |
812 | diff --git a/lib/lp/translations/vocabularies.py b/lib/lp/translations/vocabularies.py |
813 | index 680db35..b856f80 100644 |
814 | --- a/lib/lp/translations/vocabularies.py |
815 | +++ b/lib/lp/translations/vocabularies.py |
816 | @@ -80,9 +80,9 @@ class TranslationGroupVocabulary(NamedStormVocabulary): |
817 | _table = TranslationGroup |
818 | |
819 | |
820 | -class TranslationMessageVocabulary(SQLObjectVocabularyBase): |
821 | +class TranslationMessageVocabulary(StormVocabularyBase): |
822 | _table = TranslationMessage |
823 | - _orderBy = "date_created" |
824 | + _order_by = "date_created" |
825 | |
826 | def toTerm(self, obj): |
827 | translation = "" |