Merge lp:~jtv/launchpad/recife-548805 into lp:~launchpad/launchpad/recife

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Aaron Bentley
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~jtv/launchpad/recife-548805
Merge into: lp:~launchpad/launchpad/recife
Diff against target: 245 lines (+69/-66)
6 files modified
lib/lp/translations/doc/remove-translations-by.txt (+2/-2)
lib/lp/translations/interfaces/translationmessage.py (+15/-0)
lib/lp/translations/model/potmsgset.py (+2/-2)
lib/lp/translations/model/translationmessage.py (+39/-61)
lib/lp/translations/scripts/gettext_check_messages.py (+4/-0)
lib/lp/translations/scripts/message_sharing_migration.py (+7/-1)
To merge this branch: bzr merge lp:~jtv/launchpad/recife-548805
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+22264@code.launchpad.net

Commit message

Retire TranslationMessage.is_current_* validators.

Description of the change

= Bug 548805 =

This branch gets rid of the validators for the TranslationMessage.is_current_* flags. These validators, when setting either of these flags, first un-set the respective flag on an existing message that the subject message replaces. The validators make the management of these flags very non-transparent, making it hard to re-work it all as we're trying to do.

There's also a drive-by where a test for the remove-translations-by script still used obsolete option names from before these flags were renamed.

Jeroen

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

Consider using storm.locals to make future imports simpler. Either way, approved.

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/doc/remove-translations-by.txt'
2--- lib/lp/translations/doc/remove-translations-by.txt 2010-03-23 19:31:02 +0000
3+++ lib/lp/translations/doc/remove-translations-by.txt 2010-03-31 16:46:33 +0000
4@@ -89,8 +89,8 @@
5 ... '--potemplate=%s' % str(potemplate.id),
6 ... '--not-language',
7 ... '--language=%s' % 'de',
8- ... '--is-current=%s' % 'true',
9- ... '--is-imported=%s' % 'false',
10+ ... '--is-current-ubuntu=%s' % 'true',
11+ ... '--is-current-upstream=%s' % 'false',
12 ... '--msgid=%s' % "My goose is undercooked.",
13 ... '--origin=%s' % 'ROSETTAWEB',
14 ... '--force',
15
16=== modified file 'lib/lp/translations/interfaces/translationmessage.py'
17--- lib/lp/translations/interfaces/translationmessage.py 2010-03-23 15:39:12 +0000
18+++ lib/lp/translations/interfaces/translationmessage.py 2010-03-31 16:46:33 +0000
19@@ -240,6 +240,21 @@
20 HTML element id.
21 """
22
23+ def makeCurrentUbuntu(new_value=True):
24+ """Set the `is_current_ubuntu` flag.
25+
26+ If setting to True, clears the flag on any competing
27+ TranslationMessages.
28+ """
29+
30+ def makeCurrentUpstream(new_value=True):
31+ """Set the `is_current_upstream` flag.
32+
33+ If setting to True, clears the flag on any competing
34+ TranslationMessages.
35+ """
36+
37+
38
39 class ITranslationMessageSuggestions(Interface):
40 """Suggested `ITranslationMessage`s for a `POTMsgSet`.
41
42=== modified file 'lib/lp/translations/model/potmsgset.py'
43--- lib/lp/translations/model/potmsgset.py 2010-03-26 20:21:58 +0000
44+++ lib/lp/translations/model/potmsgset.py 2010-03-31 16:46:33 +0000
45@@ -702,11 +702,11 @@
46 # Either converge_shared==True, or a new message.
47 new_message.potemplate = None
48
49- new_message.is_current_ubuntu = True
50+ new_message.makeCurrentUbuntu()
51 else:
52 new_message.potemplate = None
53 if is_current_upstream or new_message == upstream_message:
54- new_message.is_current_upstream = True
55+ new_message.makeCurrentUpstream()
56
57
58 def _isTranslationMessageASuggestion(self, force_suggestion,
59
60=== modified file 'lib/lp/translations/model/translationmessage.py'
61--- lib/lp/translations/model/translationmessage.py 2010-03-23 21:20:54 +0000
62+++ lib/lp/translations/model/translationmessage.py 2010-03-31 16:46:33 +0000
63@@ -1,4 +1,4 @@
64-# Copyright 2009 Canonical Ltd. This software is licensed under the
65+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
66 # GNU Affero General Public License version 3 (see the file LICENSE).
67
68 __metaclass__ = type
69@@ -155,62 +155,11 @@
70 # This object is already non persistent, so nothing needs to be done.
71 return
72
73-
74-def validate_is_current_ubuntu(self, attr, value):
75- """Unset current Ubuntu message before selecting new one as current.
76-
77- :param value: Whether we want this translation message as the new
78- current one.
79-
80- If there is already another current message, we unset it first.
81- """
82- assert value is not None, 'is_current_ubuntu field cannot be None.'
83-
84- if value and not self.is_current_ubuntu:
85- # We are setting this message as the current one. We need to
86- # change current one to non current before.
87- current_translation_message = (
88- self.potmsgset.getCurrentTranslationMessage(
89- self.potemplate,
90- self.language, self.variant))
91- if (current_translation_message is not None and
92- current_translation_message.potemplate == self.potemplate):
93- current_translation_message.is_current_ubuntu = False
94- # We need to flush the old current message before the
95- # new one because the database constraints prevent two
96- # current messages.
97- Store.of(self).add_flush_order(current_translation_message,
98- self)
99-
100- return value
101-
102-def validate_is_current_upstream(self, attr, value):
103- """Unset current upstream message before activing this one as upstream.
104-
105- :param value: Whether we want this translation message as the new
106- upstream one.
107-
108- If there is already another upstream message, we unset it first.
109- """
110- assert value is not None, 'is_current_upstream field cannot be None.'
111-
112- if value and not self.is_current_upstream:
113- # We are setting this message as the current one. We need to
114- # change current one to non current before.
115- upstream_translation_message = (
116- self.potmsgset.getImportedTranslationMessage(
117- self.potemplate,
118- self.language, self.variant))
119- if (upstream_translation_message is not None and
120- upstream_translation_message.potemplate == self.potemplate):
121- upstream_translation_message.is_current_upstream = False
122- # We need to flush the old upstream message before the
123- # new one because the database constraints prevent two
124- # upstream messages.
125- Store.of(self).add_flush_order(upstream_translation_message,
126- self)
127-
128- return value
129+ def makeCurrentUbuntu(self, new_value=True):
130+ self.is_current_ubuntu = new_value
131+
132+ def makeCurrentUpstream(self, new_value=True):
133+ self.is_current_upstream = new_value
134
135
136 class TranslationMessage(SQLBase, TranslationMessageMixIn):
137@@ -263,11 +212,9 @@
138 dbName='validation_status', notNull=True,
139 schema=TranslationValidationStatus)
140 is_current_ubuntu = BoolCol(
141- dbName='is_current_ubuntu', notNull=True, default=False,
142- storm_validator=validate_is_current_ubuntu)
143+ dbName='is_current_ubuntu', notNull=True, default=False)
144 is_current_upstream = BoolCol(
145- dbName='is_current_upstream', notNull=True, default=False,
146- storm_validator=validate_is_current_upstream)
147+ dbName='is_current_upstream', notNull=True, default=False)
148 was_obsolete_in_last_import = BoolCol(
149 dbName='was_obsolete_in_last_import', notNull=True, default=False)
150
151@@ -475,6 +422,37 @@
152
153 return twins.order_by(TranslationMessage.id).first()
154
155+ def makeCurrentUbuntu(self, new_value=True):
156+ """See `ITranslationMessage`."""
157+ if new_value and not self.is_current_ubuntu:
158+ incumbent = self.potmsgset.getCurrentTranslationMessage(
159+ self.potemplate, self.language, self.variant)
160+ if incumbent == self:
161+ return
162+ if (incumbent is not None and
163+ incumbent.potemplate == self.potemplate):
164+ # The incumbent is in the way. Clear its flag.
165+ incumbent.is_current_ubuntu = False
166+ Store.of(self).add_flush_order(incumbent, self)
167+
168+ self.is_current_ubuntu = new_value
169+
170+ def makeCurrentUpstream(self, new_value=True):
171+ """See `ITranslationMessage`."""
172+ if new_value and not self.is_current_upstream:
173+ incumbent = self.potmsgset.getImportedTranslationMessage(
174+ self.potemplate, self.language, self.variant)
175+ if incumbent == self:
176+ return
177+ if (incumbent is not None and
178+ incumbent.potemplate == self.potemplate):
179+ # The incumbent is in the way. Clear its flag.
180+ incumbent.is_current_upstream = False
181+ Store.of(self).add_flush_order(incumbent, self)
182+
183+ self.is_current_upstream = new_value
184+
185+
186
187 class TranslationMessageSet:
188 """See `ITranslationMessageSet`."""
189
190=== modified file 'lib/lp/translations/scripts/gettext_check_messages.py'
191--- lib/lp/translations/scripts/gettext_check_messages.py 2010-03-26 14:34:55 +0000
192+++ lib/lp/translations/scripts/gettext_check_messages.py 2010-03-31 16:46:33 +0000
193@@ -7,6 +7,8 @@
194
195 from datetime import timedelta, datetime
196
197+from storm.locals import Store
198+
199 from zope.component import getUtility
200 from zope.security.proxy import removeSecurityProxy
201
202@@ -136,6 +138,8 @@
203 self._disable_count += 1
204 if imported is not None:
205 imported.is_current_ubuntu = True
206+ Store.of(imported).add_flush_order(
207+ translationmessage, imported)
208 self._unmask_count += 1
209
210 def _do_commit(self):
211
212=== modified file 'lib/lp/translations/scripts/message_sharing_migration.py'
213--- lib/lp/translations/scripts/message_sharing_migration.py 2010-03-23 15:39:12 +0000
214+++ lib/lp/translations/scripts/message_sharing_migration.py 2010-03-31 16:46:33 +0000
215@@ -1,4 +1,4 @@
216-# Copyright 2009 Canonical Ltd. This software is licensed under the
217+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
218 # GNU Affero General Public License version 3 (see the file LICENSE).
219
220 __metaclass__ = type
221@@ -10,6 +10,8 @@
222 from zope.component import getUtility
223 from zope.security.proxy import removeSecurityProxy
224
225+from storm.locals import Store
226+
227 from canonical.launchpad.scripts.logger import log, DEBUG2
228 from canonical.launchpad.utilities.orderingcheck import OrderingCheck
229 from lp.translations.interfaces.potemplate import IPOTemplateSet
230@@ -147,12 +149,16 @@
231 # Transfer is_current_ubuntu flag.
232 source_message.is_current_ubuntu = False
233 target_message.is_current_ubuntu = True
234+ Store.of(source_message).add_flush_order(
235+ source_message, target_message)
236
237 if (source_message.is_current_upstream and
238 not target_message.is_current_upstream):
239 # Transfer is_current_upstream flag.
240 source_message.is_current_upstream = False
241 target_message.is_current_upstream = True
242+ Store.of(source_message).add_flush_order(
243+ source_message, target_message)
244
245 source_message.destroySelf()
246

Subscribers

People subscribed via source and target branches