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
1=== modified file 'lib/lp/translations/doc/rosetta-karma.txt'
2--- lib/lp/translations/doc/rosetta-karma.txt 2010-12-31 17:03:43 +0000
3+++ lib/lp/translations/doc/rosetta-karma.txt 2011-02-17 16:47:38 +0000
4@@ -222,15 +222,12 @@
5
6 Tell the PO file to import from the file data it has. The user has rights
7 to edit translations directly, so his suggestion is approved directly.
8-Even when the user is also a reviwer, he should not get karma for reviewing
9-or approving his own translations. IOW, he'll only get karma for submitting
10-his suggestion.
11+No karma is awarded for this action.
12
13 >>> potemplate = POTemplate.get(1)
14 >>> entry = translation_import_queue[entry_id]
15 >>> pofile = potemplate.getPOFileByLang('es')
16 >>> (subject, message) = pofile.importFromQueue(entry)
17- Karma added: action=translationsuggestionadded, product=evolution
18 >>> transaction.commit()
19
20 Let's try the case when a file is uploaded, but no translation is changed.
21
22=== modified file 'lib/lp/translations/interfaces/potmsgset.py'
23--- lib/lp/translations/interfaces/potmsgset.py 2011-01-27 23:13:20 +0000
24+++ lib/lp/translations/interfaces/potmsgset.py 2011-02-17 16:47:38 +0000
25@@ -222,13 +222,17 @@
26 translations.
27 """
28
29- def submitSuggestion(pofile, submitter, new_translations):
30+ def submitSuggestion(pofile, submitter, new_translations,
31+ from_import=False):
32 """Submit a suggested translation for this message.
33
34 If an identical message is already present, it will be returned
35 (and it is not changed). Otherwise, a new one is created and
36 returned. Suggestions for translation credits messages are
37 ignored, and None is returned in that case.
38+ Setting from_import to true will prevent karma assignment and
39+ set the origin of the created message to SCM instead of
40+ ROSETTAWEB.
41 """
42
43 def dismissAllSuggestions(pofile, reviewer, lock_timestamp):
44
45=== modified file 'lib/lp/translations/model/potmsgset.py'
46--- lib/lp/translations/model/potmsgset.py 2011-02-15 23:54:54 +0000
47+++ lib/lp/translations/model/potmsgset.py 2011-02-17 16:47:38 +0000
48@@ -549,7 +549,8 @@
49 else:
50 return None
51
52- def submitSuggestion(self, pofile, submitter, new_translations):
53+ def submitSuggestion(self, pofile, submitter, new_translations,
54+ from_import=False):
55 """See `IPOTMsgSet`."""
56 if self.is_translation_credit:
57 # We don't support suggestions on credits messages.
58@@ -565,11 +566,16 @@
59 ('msgstr%d' % form, potranslation)
60 for form, potranslation in potranslations.iteritems())
61
62- pofile.potemplate.awardKarma(submitter, 'translationsuggestionadded')
63+ if from_import:
64+ origin = RosettaTranslationOrigin.SCM
65+ else:
66+ origin = RosettaTranslationOrigin.ROSETTAWEB
67+ pofile.potemplate.awardKarma(
68+ submitter, 'translationsuggestionadded')
69
70 return TranslationMessage(
71 potmsgset=self, language=pofile.language,
72- origin=RosettaTranslationOrigin.ROSETTAWEB, submitter=submitter,
73+ origin=origin, submitter=submitter,
74 **forms)
75
76 def _checkForConflict(self, current_message, lock_timestamp,
77
78=== modified file 'lib/lp/translations/tests/test_potmsgset.py'
79--- lib/lp/translations/tests/test_potmsgset.py 2011-02-14 21:50:21 +0000
80+++ lib/lp/translations/tests/test_potmsgset.py 2011-02-17 16:47:38 +0000
81@@ -1396,6 +1396,29 @@
82
83 self.assertEqual([], karma_listener.karma_events)
84
85+ def test_from_import_origin(self):
86+ # With from_import set, the origin is set to SCM.
87+ pofile, potmsgset = self._makePOFileAndPOTMsgSet()
88+ owner = pofile.potemplate.owner
89+ translation = {0: self.factory.getUniqueString()}
90+
91+ suggestion = potmsgset.submitSuggestion(
92+ pofile, owner, translation, from_import=True)
93+
94+ self.assertEqual(RosettaTranslationOrigin.SCM, suggestion.origin)
95+
96+ def test_from_import_karma(self):
97+ # No karma is assigned if from_import is set.
98+ pofile, potmsgset = self._makePOFileAndPOTMsgSet()
99+ owner = pofile.potemplate.owner
100+ translation = {0: self.factory.getUniqueString()}
101+ karma_listener = self._listenForKarma(pofile)
102+
103+ potmsgset.submitSuggestion(
104+ pofile, owner, translation, from_import=True)
105+
106+ self.assertEqual([], karma_listener.karma_events)
107+
108
109 class TestSetCurrentTranslation(TestCaseWithFactory):
110 layer = DatabaseFunctionalLayer
111
112=== modified file 'lib/lp/translations/utilities/translation_import.py'
113--- lib/lp/translations/utilities/translation_import.py 2011-02-15 12:13:20 +0000
114+++ lib/lp/translations/utilities/translation_import.py 2011-02-17 16:47:38 +0000
115@@ -545,7 +545,8 @@
116 # The message is first stored as a suggestion and only made
117 # current if it validates.
118 new_message = potmsgset.submitSuggestion(
119- self.pofile, self.last_translator, sanitized_translations)
120+ self.pofile, self.last_translator, sanitized_translations,
121+ from_import=True)
122
123 validation_ok = self._validateMessage(
124 potmsgset, new_message, sanitized_translations, message_data)