Merge lp:~henninge/launchpad/bug-720673-import-origin into lp:launchpad

Proposed by Henning Eggers
Status: Merged
Approved by: Henning Eggers
Approved revision: no longer in the source branch.
Merged at revision: 12407
Proposed branch: lp:~henninge/launchpad/bug-720673-import-origin
Merge into: lp:launchpad
Diff against target: 124 lines (+40/-9)
5 files modified
lib/lp/translations/doc/rosetta-karma.txt (+1/-4)
lib/lp/translations/interfaces/potmsgset.py (+5/-1)
lib/lp/translations/model/potmsgset.py (+9/-3)
lib/lp/translations/tests/test_potmsgset.py (+23/-0)
lib/lp/translations/utilities/translation_import.py (+2/-1)
To merge this branch: bzr merge lp:~henninge/launchpad/bug-720673-import-origin
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+50157@code.launchpad.net

Commit message

[r=abentley][bug=720673] Set origin correctly on imported TranslationMessages.

Description of the change

= Summary =

We had this great idea to simplify things in the import script by adding
translations first as a suggestion and then approving them if it verifies ok.
We missed the fact, though, that the suggest-approve mechanism was designed
for translations entered through the UI. So there behavior does not match
what the old import code did. I fixed a big part of that in the last branch
by introducing the "accept" methods as opposed to "approve". This branch now
deals with a little leftover in what submitSuggestion does differently. In
this case the difference is so little, though that I did not introduce a new
method but just added a parameter.

== Proposed fix ==

Add a parameter from_import to submitSuggestion to change it behavior as is
appropriate for imports, namely:
- set the origin to SCM (source code management)
- do not assign karma to the uploader.

We may have to rethink the karma story for uploads, maybe create its own
category.

== Pre-implementation notes ==

This is pretty obvious. ;-)

== Implementation details ==

Do you really need more detail?

== Tests ==

bin/test -vvcm lp.translations.tests.test_potmsgset -t submitSuggestion

== Demo and Q/A ==

Do an import and verify through a database query that the origin is set
correctly. It is not exposed in the UI.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/interfaces/potmsgset.py
  lib/lp/translations/tests/test_potmsgset.py
  lib/lp/translations/model/potmsgset.py
  lib/lp/translations/utilities/translation_import.py

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/doc/rosetta-karma.txt'
--- lib/lp/translations/doc/rosetta-karma.txt 2010-12-31 17:03:43 +0000
+++ lib/lp/translations/doc/rosetta-karma.txt 2011-02-17 16:47:38 +0000
@@ -222,15 +222,12 @@
222222
223Tell the PO file to import from the file data it has. The user has rights223Tell the PO file to import from the file data it has. The user has rights
224to edit translations directly, so his suggestion is approved directly.224to edit translations directly, so his suggestion is approved directly.
225Even when the user is also a reviwer, he should not get karma for reviewing225No karma is awarded for this action.
226or approving his own translations. IOW, he'll only get karma for submitting
227his suggestion.
228226
229 >>> potemplate = POTemplate.get(1)227 >>> potemplate = POTemplate.get(1)
230 >>> entry = translation_import_queue[entry_id]228 >>> entry = translation_import_queue[entry_id]
231 >>> pofile = potemplate.getPOFileByLang('es')229 >>> pofile = potemplate.getPOFileByLang('es')
232 >>> (subject, message) = pofile.importFromQueue(entry)230 >>> (subject, message) = pofile.importFromQueue(entry)
233 Karma added: action=translationsuggestionadded, product=evolution
234 >>> transaction.commit()231 >>> transaction.commit()
235232
236Let's try the case when a file is uploaded, but no translation is changed.233Let's try the case when a file is uploaded, but no translation is changed.
237234
=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
--- lib/lp/translations/interfaces/potmsgset.py 2011-01-27 23:13:20 +0000
+++ lib/lp/translations/interfaces/potmsgset.py 2011-02-17 16:47:38 +0000
@@ -222,13 +222,17 @@
222 translations.222 translations.
223 """223 """
224224
225 def submitSuggestion(pofile, submitter, new_translations):225 def submitSuggestion(pofile, submitter, new_translations,
226 from_import=False):
226 """Submit a suggested translation for this message.227 """Submit a suggested translation for this message.
227228
228 If an identical message is already present, it will be returned229 If an identical message is already present, it will be returned
229 (and it is not changed). Otherwise, a new one is created and230 (and it is not changed). Otherwise, a new one is created and
230 returned. Suggestions for translation credits messages are231 returned. Suggestions for translation credits messages are
231 ignored, and None is returned in that case.232 ignored, and None is returned in that case.
233 Setting from_import to true will prevent karma assignment and
234 set the origin of the created message to SCM instead of
235 ROSETTAWEB.
232 """236 """
233237
234 def dismissAllSuggestions(pofile, reviewer, lock_timestamp):238 def dismissAllSuggestions(pofile, reviewer, lock_timestamp):
235239
=== modified file 'lib/lp/translations/model/potmsgset.py'
--- lib/lp/translations/model/potmsgset.py 2011-02-15 23:54:54 +0000
+++ lib/lp/translations/model/potmsgset.py 2011-02-17 16:47:38 +0000
@@ -549,7 +549,8 @@
549 else:549 else:
550 return None550 return None
551551
552 def submitSuggestion(self, pofile, submitter, new_translations):552 def submitSuggestion(self, pofile, submitter, new_translations,
553 from_import=False):
553 """See `IPOTMsgSet`."""554 """See `IPOTMsgSet`."""
554 if self.is_translation_credit:555 if self.is_translation_credit:
555 # We don't support suggestions on credits messages.556 # We don't support suggestions on credits messages.
@@ -565,11 +566,16 @@
565 ('msgstr%d' % form, potranslation)566 ('msgstr%d' % form, potranslation)
566 for form, potranslation in potranslations.iteritems())567 for form, potranslation in potranslations.iteritems())
567568
568 pofile.potemplate.awardKarma(submitter, 'translationsuggestionadded')569 if from_import:
570 origin = RosettaTranslationOrigin.SCM
571 else:
572 origin = RosettaTranslationOrigin.ROSETTAWEB
573 pofile.potemplate.awardKarma(
574 submitter, 'translationsuggestionadded')
569575
570 return TranslationMessage(576 return TranslationMessage(
571 potmsgset=self, language=pofile.language,577 potmsgset=self, language=pofile.language,
572 origin=RosettaTranslationOrigin.ROSETTAWEB, submitter=submitter,578 origin=origin, submitter=submitter,
573 **forms)579 **forms)
574580
575 def _checkForConflict(self, current_message, lock_timestamp,581 def _checkForConflict(self, current_message, lock_timestamp,
576582
=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
--- lib/lp/translations/tests/test_potmsgset.py 2011-02-14 21:50:21 +0000
+++ lib/lp/translations/tests/test_potmsgset.py 2011-02-17 16:47:38 +0000
@@ -1396,6 +1396,29 @@
13961396
1397 self.assertEqual([], karma_listener.karma_events)1397 self.assertEqual([], karma_listener.karma_events)
13981398
1399 def test_from_import_origin(self):
1400 # With from_import set, the origin is set to SCM.
1401 pofile, potmsgset = self._makePOFileAndPOTMsgSet()
1402 owner = pofile.potemplate.owner
1403 translation = {0: self.factory.getUniqueString()}
1404
1405 suggestion = potmsgset.submitSuggestion(
1406 pofile, owner, translation, from_import=True)
1407
1408 self.assertEqual(RosettaTranslationOrigin.SCM, suggestion.origin)
1409
1410 def test_from_import_karma(self):
1411 # No karma is assigned if from_import is set.
1412 pofile, potmsgset = self._makePOFileAndPOTMsgSet()
1413 owner = pofile.potemplate.owner
1414 translation = {0: self.factory.getUniqueString()}
1415 karma_listener = self._listenForKarma(pofile)
1416
1417 potmsgset.submitSuggestion(
1418 pofile, owner, translation, from_import=True)
1419
1420 self.assertEqual([], karma_listener.karma_events)
1421
13991422
1400class TestSetCurrentTranslation(TestCaseWithFactory):1423class TestSetCurrentTranslation(TestCaseWithFactory):
1401 layer = DatabaseFunctionalLayer1424 layer = DatabaseFunctionalLayer
14021425
=== modified file 'lib/lp/translations/utilities/translation_import.py'
--- lib/lp/translations/utilities/translation_import.py 2011-02-15 12:13:20 +0000
+++ lib/lp/translations/utilities/translation_import.py 2011-02-17 16:47:38 +0000
@@ -545,7 +545,8 @@
545 # The message is first stored as a suggestion and only made545 # The message is first stored as a suggestion and only made
546 # current if it validates.546 # current if it validates.
547 new_message = potmsgset.submitSuggestion(547 new_message = potmsgset.submitSuggestion(
548 self.pofile, self.last_translator, sanitized_translations)548 self.pofile, self.last_translator, sanitized_translations,
549 from_import=True)
549550
550 validation_ok = self._validateMessage(551 validation_ok = self._validateMessage(
551 potmsgset, new_message, sanitized_translations, message_data)552 potmsgset, new_message, sanitized_translations, message_data)