Merge lp:~adiroiban/launchpad/bug-512307 into lp:launchpad
- bug-512307
- Merge into devel
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Graham Binns | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~adiroiban/launchpad/bug-512307 | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
246 lines (+111/-19) 5 files modified
lib/lp/translations/browser/language.py (+26/-3) lib/lp/translations/browser/tests/language-views.txt (+73/-7) lib/lp/translations/stories/standalone/xx-pofile-details.txt (+4/-3) lib/lp/translations/templates/language-portlet-top-contributors.pt (+2/-2) lib/lp/translations/templates/pofile-details.pt (+6/-4) |
||||
To merge this branch: | bzr merge lp:~adiroiban/launchpad/bug-512307 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Graham Binns (community) | code | Approve | |
Review via email: mp+20442@code.launchpad.net |
Commit message
Filter merge accounts from overall language contributors.
Description of the change
Adi Roiban (adiroiban) wrote : | # |
Graham Binns (gmb) wrote : | # |
Hi Adi,
Nice branch. I've got a couple of comments - just fixes needed in the doctest narrative - other than that this is fine. Please ping me when you've made the necessary changes and I'll EC2 it.
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -34,7 +34,6 @@
> ITranslationsPe
> from lp.translations
> from lp.translations
> -from canonical.
>
> from canonical.widgets import LabeledMultiChe
>
> @@ -214,8 +213,31 @@
> })
> return translation_teams
>
> - def getTopContribut
> - return self.context.
> + @property
> + def top_contributor
> + """
> + Get top 20 contributors for a language.
s/Get/Get the
> +
> + Instead of merged account, show the merged target account.
This would read better as: "If an account has been merged, the account
into which it was merged will be returned."
> + """
> + translators = []
> + for translator in reversed(
> + # Get only the top 20 contributors
> + if (len(translators) >= 20):
> + break
> +
> + # For merged account add the target account
> + if translator.merged != None:
> + translator_target = translator.merged
> + else:
> + translator_target = translator
> +
> + # Add translator only if it was not previouly added as a
> + # merged account
> + if translator_target not in translators:
> + translators.
> +
> + return translators
>
> @property
> def friendly_
>
> === modified file 'lib/lp/
> --- lib/lp/
> +++ lib/lp/
> @@ -1,8 +1,8 @@
> Language Views
> -==================
> +==============
>
> Admin Language
> -------------------
> +--------------
>
> >>> from zope.component import getUtility
> >>> from lp.services.
> @@ -34,7 +34,7 @@
>
>
> Add Language
> -------------------
> +------------
>
> >>> language_add_view = create_
> ... layer=Translati
> @@ -77,13 +77,22 @@
>
>
> View Language
> -------------------
> -
> +-------------
> +
> +Translators list for each language is computed using KarmaCache table for
s/list/lists ; s/is computed/are computed ; s/table/tables.
> +users which have configured their prefered language. Since KarmaCache tables
> +are generated using nightly builds, we will change Langauge.
> +use the list of translators generated by this test.
> +
> + >>> ...
Adi Roiban (adiroiban) wrote : | # |
Thanks for the review.
I have fixed and pushed the pagetest comments.
Here is the diff.
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -216,9 +216,10 @@
@property
def top_contributor
"""
- Get top 20 contributors for a language.
+ Get the top 20 contributors for a language.
- Instead of merged account, show the merged target account.
+ If an account has been merged, the account into which it was
+ merged will be returned.
"""
for translator in reversed(
=== modified file 'lib/lp/
--- lib/lp/
+++ lib/lp/
@@ -79,7 +79,7 @@
View Language
-------------
-Translators list for each language is computed using KarmaCache table for
+Translators lists for each language are computed using KarmaCache tables for
users which have configured their prefered language. Since KarmaCache tables
are generated using nightly builds, we will change Langauge.
use the list of translators generated by this test.
@@ -104,7 +104,7 @@
1 : 2, 3, 4, 22, 23, 24...
2 : 5, 6, 7, 8, 9, 10...
-Top 20 contributors are listed on the language page, and for merged account
+The top 20 contributors are listed on the language page, and for merged account
we will see their targed account.
Create some translators and a merged account.
Preview Diff
1 | === modified file 'lib/lp/translations/browser/language.py' | |||
2 | --- lib/lp/translations/browser/language.py 2009-12-08 10:20:37 +0000 | |||
3 | +++ lib/lp/translations/browser/language.py 2010-03-16 01:06:32 +0000 | |||
4 | @@ -34,7 +34,6 @@ | |||
5 | 34 | ITranslationsPerson) | 34 | ITranslationsPerson) |
6 | 35 | from lp.translations.browser.translations import TranslationsMixin | 35 | from lp.translations.browser.translations import TranslationsMixin |
7 | 36 | from lp.translations.utilities.pluralforms import make_friendly_plural_forms | 36 | from lp.translations.utilities.pluralforms import make_friendly_plural_forms |
8 | 37 | from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities | ||
9 | 38 | 37 | ||
10 | 39 | from canonical.widgets import LabeledMultiCheckBoxWidget | 38 | from canonical.widgets import LabeledMultiCheckBoxWidget |
11 | 40 | 39 | ||
12 | @@ -214,8 +213,32 @@ | |||
13 | 214 | }) | 213 | }) |
14 | 215 | return translation_teams | 214 | return translation_teams |
15 | 216 | 215 | ||
18 | 217 | def getTopContributors(self): | 216 | @property |
19 | 218 | return self.context.translators[:20] | 217 | def top_contributors(self): |
20 | 218 | """ | ||
21 | 219 | Get the top 20 contributors for a language. | ||
22 | 220 | |||
23 | 221 | If an account has been merged, the account into which it was | ||
24 | 222 | merged will be returned. | ||
25 | 223 | """ | ||
26 | 224 | translators = [] | ||
27 | 225 | for translator in reversed(list(self.context.translators)): | ||
28 | 226 | # Get only the top 20 contributors | ||
29 | 227 | if (len(translators) >= 20): | ||
30 | 228 | break | ||
31 | 229 | |||
32 | 230 | # For merged account add the target account | ||
33 | 231 | if translator.merged != None: | ||
34 | 232 | translator_target = translator.merged | ||
35 | 233 | else: | ||
36 | 234 | translator_target = translator | ||
37 | 235 | |||
38 | 236 | # Add translator only if it was not previouly added as a | ||
39 | 237 | # merged account | ||
40 | 238 | if translator_target not in translators: | ||
41 | 239 | translators.append(translator_target) | ||
42 | 240 | |||
43 | 241 | return translators | ||
44 | 219 | 242 | ||
45 | 220 | @property | 243 | @property |
46 | 221 | def friendly_plural_forms(self): | 244 | def friendly_plural_forms(self): |
47 | 222 | 245 | ||
48 | === modified file 'lib/lp/translations/browser/tests/language-views.txt' | |||
49 | --- lib/lp/translations/browser/tests/language-views.txt 2010-03-05 13:50:29 +0000 | |||
50 | +++ lib/lp/translations/browser/tests/language-views.txt 2010-03-16 01:06:32 +0000 | |||
51 | @@ -1,8 +1,8 @@ | |||
52 | 1 | Language Views | 1 | Language Views |
54 | 2 | ================== | 2 | ============== |
55 | 3 | 3 | ||
56 | 4 | Admin Language | 4 | Admin Language |
58 | 5 | ------------------ | 5 | -------------- |
59 | 6 | 6 | ||
60 | 7 | >>> from zope.component import getUtility | 7 | >>> from zope.component import getUtility |
61 | 8 | >>> from lp.services.worlddata.interfaces.language import ILanguageSet | 8 | >>> from lp.services.worlddata.interfaces.language import ILanguageSet |
62 | @@ -34,7 +34,7 @@ | |||
63 | 34 | 34 | ||
64 | 35 | 35 | ||
65 | 36 | Add Language | 36 | Add Language |
67 | 37 | ------------------ | 37 | ------------ |
68 | 38 | 38 | ||
69 | 39 | >>> language_add_view = create_view(language_set, '+add', | 39 | >>> language_add_view = create_view(language_set, '+add', |
70 | 40 | ... layer=TranslationsLayer) | 40 | ... layer=TranslationsLayer) |
71 | @@ -77,13 +77,24 @@ | |||
72 | 77 | 77 | ||
73 | 78 | 78 | ||
74 | 79 | View Language | 79 | View Language |
77 | 80 | ------------------ | 80 | ------------- |
78 | 81 | 81 | ||
79 | 82 | Translators lists for each language are computed using KarmaCache tables for | ||
80 | 83 | users which have configured their prefered language. Since KarmaCache tables | ||
81 | 84 | are generated using nightly builds, we will change Langauge.translators to | ||
82 | 85 | use the list of translators generated by this test. | ||
83 | 86 | |||
84 | 87 | Language.translators is deleted so that we can add our custom | ||
85 | 88 | implementation later. | ||
86 | 89 | |||
87 | 90 | >>> from lp.services.worlddata.model.language import Language | ||
88 | 91 | >>> translators_method = Language.translators | ||
89 | 92 | >>> del Language.translators | ||
90 | 82 | >>> serbian = language_set.getLanguageByCode('sr') | 93 | >>> serbian = language_set.getLanguageByCode('sr') |
91 | 83 | >>> language_view = create_initialized_view(serbian, '+index', | 94 | >>> language_view = create_initialized_view(serbian, '+index', |
92 | 84 | ... layer=TranslationsLayer) | 95 | ... layer=TranslationsLayer) |
93 | 85 | 96 | ||
95 | 86 | The friendlypluralforms function shows us a list of plural forms and | 97 | The 'friendly_plural_forms' function shows us a list of plural forms and |
96 | 87 | a set of examples for each one, so one won't need to understand the plural | 98 | a set of examples for each one, so one won't need to understand the plural |
97 | 88 | formula expression to see how it works. | 99 | formula expression to see how it works. |
98 | 89 | 100 | ||
99 | @@ -95,6 +106,61 @@ | |||
100 | 95 | 1 : 2, 3, 4, 22, 23, 24... | 106 | 1 : 2, 3, 4, 22, 23, 24... |
101 | 96 | 2 : 0, 5, 6, 7, 8, 9... | 107 | 2 : 0, 5, 6, 7, 8, 9... |
102 | 97 | 108 | ||
103 | 109 | The top 20 contributors are listed on the language page, and for merged account | ||
104 | 110 | we will see their targed account. | ||
105 | 111 | |||
106 | 112 | Create some translators and a merged account. | ||
107 | 113 | |||
108 | 114 | >>> from zope.security.proxy import removeSecurityProxy | ||
109 | 115 | >>> translators = [] | ||
110 | 116 | >>> for translator_nr in range(22): | ||
111 | 117 | ... translators.append(factory.makePerson( | ||
112 | 118 | ... name='translator-' + str(translator_nr), | ||
113 | 119 | ... displayname='Translator No.' + str(translator_nr))) | ||
114 | 120 | >>> translator_main = factory.makePerson( | ||
115 | 121 | ... name='translator-main', | ||
116 | 122 | ... displayname='Translator Main') | ||
117 | 123 | >>> translators.append(translator_main) | ||
118 | 124 | >>> translator_merged = removeSecurityProxy(factory.makePerson( | ||
119 | 125 | ... name='translator-merged', | ||
120 | 126 | ... displayname='Translator Merged')) | ||
121 | 127 | >>> translators.append(translator_merged) | ||
122 | 128 | >>> translator_merged.merged = translator_main | ||
123 | 129 | |||
124 | 130 | Create a product, a template with one msgset and a pofile | ||
125 | 131 | |||
126 | 132 | >>> product = factory.makeProduct(official_rosetta=True) | ||
127 | 133 | >>> template = factory.makePOTemplate( | ||
128 | 134 | ... productseries=product.getSeries('trunk')) | ||
129 | 135 | >>> potmsgset = factory.makePOTMsgSet(template) | ||
130 | 136 | >>> pofile = factory.makePOFile('sr', potemplate=template) | ||
131 | 137 | |||
132 | 138 | Add a translation for each translator and one more for main and merged | ||
133 | 139 | accounts. | ||
134 | 140 | |||
135 | 141 | >>> for translator in translators: | ||
136 | 142 | ... translation = factory.makeTranslationMessage( | ||
137 | 143 | ... pofile=pofile, translator=translator, potmsgset=potmsgset) | ||
138 | 144 | >>> translation = factory.makeTranslationMessage( | ||
139 | 145 | ... pofile=pofile, translator=translator_merged, potmsgset=potmsgset) | ||
140 | 146 | >>> translation = factory.makeTranslationMessage( | ||
141 | 147 | ... pofile=pofile, translator=translator_main, potmsgset=potmsgset) | ||
142 | 148 | |||
143 | 149 | Langauge.translators is Monkey-patched to avoid fetching KarmaCache. | ||
144 | 150 | |||
145 | 151 | >>> serbian.translators = translators | ||
146 | 152 | >>> language_view = create_initialized_view(serbian, '+index', | ||
147 | 153 | ... layer=TranslationsLayer) | ||
148 | 154 | >>> top_contributors = language_view.top_contributors | ||
149 | 155 | >>> translator_main in top_contributors | ||
150 | 156 | True | ||
151 | 157 | >>> translator_merged in top_contributors | ||
152 | 158 | False | ||
153 | 159 | |||
154 | 160 | In the end, the changes done to Language class are reverted. | ||
155 | 161 | |||
156 | 162 | >>> Language.translators = translators_method | ||
157 | 163 | |||
158 | 98 | View LanguageSet | 164 | View LanguageSet |
159 | 99 | ------------------ | 165 | ------------------ |
160 | 100 | 166 | ||
161 | @@ -110,7 +176,7 @@ | |||
162 | 110 | <a href=".../en" ...>English</a>, | 176 | <a href=".../en" ...>English</a>, |
163 | 111 | <a href=".../es" ...>Spanish</a> | 177 | <a href=".../es" ...>Spanish</a> |
164 | 112 | 178 | ||
166 | 113 | For a user without any preferred languages, English will be returned. | 179 | For a user without any preferred languages, English will be returned. |
167 | 114 | 180 | ||
168 | 115 | >>> person = factory.makePerson() | 181 | >>> person = factory.makePerson() |
169 | 116 | >>> print person.languages | 182 | >>> print person.languages |
170 | 117 | 183 | ||
171 | === modified file 'lib/lp/translations/stories/standalone/xx-pofile-details.txt' | |||
172 | --- lib/lp/translations/stories/standalone/xx-pofile-details.txt 2010-03-11 20:54:36 +0000 | |||
173 | +++ lib/lp/translations/stories/standalone/xx-pofile-details.txt 2010-03-16 01:06:32 +0000 | |||
174 | @@ -151,10 +151,8 @@ | |||
175 | 151 | >>> language_code = 'es' | 151 | >>> language_code = 'es' |
176 | 152 | >>> pofile = factory.makePOFile(language_code, potemplate=template) | 152 | >>> pofile = factory.makePOFile(language_code, potemplate=template) |
177 | 153 | >>> potmsgset = factory.makePOTMsgSet(template) | 153 | >>> potmsgset = factory.makePOTMsgSet(template) |
178 | 154 | >>> potmsgset.setSequence(template, 1) | ||
179 | 155 | >>> translation = factory.makeTranslationMessage(pofile=pofile, | 154 | >>> translation = factory.makeTranslationMessage(pofile=pofile, |
180 | 156 | ... translator=merged_translator, potmsgset=potmsgset) | 155 | ... translator=merged_translator, potmsgset=potmsgset) |
181 | 157 | >>> potmsgset.setSequence(template, 2) | ||
182 | 158 | >>> translation = factory.makeTranslationMessage(pofile=pofile, | 156 | >>> translation = factory.makeTranslationMessage(pofile=pofile, |
183 | 159 | ... translator=translator, potmsgset=potmsgset) | 157 | ... translator=translator, potmsgset=potmsgset) |
184 | 160 | >>> from zope.security.proxy import removeSecurityProxy | 158 | >>> from zope.security.proxy import removeSecurityProxy |
185 | @@ -165,10 +163,13 @@ | |||
186 | 165 | ... ("http://translations.launchpad.dev/" | 163 | ... ("http://translations.launchpad.dev/" |
187 | 166 | ... "ubuntu/hoary/+source/%s/+pots/%s/%s/+details") % ( | 164 | ... "ubuntu/hoary/+source/%s/+pots/%s/%s/+details") % ( |
188 | 167 | ... package.name, template.name, language_code)) | 165 | ... package.name, template.name, language_code)) |
190 | 168 | >>> print extract_text(find_main_content(browser.contents)) | 166 | >>> main_text = extract_text(find_main_content(browser.contents)) |
191 | 167 | >>> print main_text | ||
192 | 169 | Details for ... | 168 | Details for ... |
193 | 170 | Contributors to this translation | 169 | Contributors to this translation |
194 | 171 | The following people have made some contribution to this specific | 170 | The following people have made some contribution to this specific |
195 | 172 | translation: | 171 | translation: |
196 | 173 | Poly Glot (filter) | 172 | Poly Glot (filter) |
197 | 174 | 173 | ||
198 | 174 | >>> u'Mere Pere' in main_text | ||
199 | 175 | False | ||
200 | 175 | 176 | ||
201 | === modified file 'lib/lp/translations/templates/language-portlet-top-contributors.pt' | |||
202 | --- lib/lp/translations/templates/language-portlet-top-contributors.pt 2009-08-28 15:40:27 +0000 | |||
203 | +++ lib/lp/translations/templates/language-portlet-top-contributors.pt 2010-03-16 01:06:32 +0000 | |||
204 | @@ -3,7 +3,7 @@ | |||
205 | 3 | xmlns:metal="http://xml.zope.org/namespaces/metal" | 3 | xmlns:metal="http://xml.zope.org/namespaces/metal" |
206 | 4 | xmlns:i18n="http://xml.zope.org/namespaces/i18n" | 4 | xmlns:i18n="http://xml.zope.org/namespaces/i18n" |
207 | 5 | class="portlet" id="portlet-top-contributors" | 5 | class="portlet" id="portlet-top-contributors" |
209 | 6 | tal:condition="view/getTopContributors"> | 6 | tal:condition="view/top_contributors"> |
210 | 7 | <h2>Top contributors</h2> | 7 | <h2>Top contributors</h2> |
211 | 8 | <div class="portletBody portletContent"> | 8 | <div class="portletBody portletContent"> |
212 | 9 | <p> | 9 | <p> |
213 | @@ -14,7 +14,7 @@ | |||
214 | 14 | </tal:language_name>: | 14 | </tal:language_name>: |
215 | 15 | </p> | 15 | </p> |
216 | 16 | <ul> | 16 | <ul> |
218 | 17 | <li tal:repeat="contributor view/getTopContributors"> | 17 | <li tal:repeat="contributor view/top_contributors"> |
219 | 18 | <a tal:replace="structure contributor/fmt:link">Guilherme Salgado</a> | 18 | <a tal:replace="structure contributor/fmt:link">Guilherme Salgado</a> |
220 | 19 | </li> | 19 | </li> |
221 | 20 | </ul> | 20 | </ul> |
222 | 21 | 21 | ||
223 | === modified file 'lib/lp/translations/templates/pofile-details.pt' | |||
224 | --- lib/lp/translations/templates/pofile-details.pt 2010-01-20 22:31:50 +0000 | |||
225 | +++ lib/lp/translations/templates/pofile-details.pt 2010-03-16 01:06:32 +0000 | |||
226 | @@ -41,14 +41,16 @@ | |||
227 | 41 | </p> | 41 | </p> |
228 | 42 | 42 | ||
229 | 43 | <ul tal:condition="view/contributors"> | 43 | <ul tal:condition="view/contributors"> |
233 | 44 | <li tal:repeat="contributor view/contributors"> | 44 | <tal:contributors-loop repeat="contributor view/contributors"> |
234 | 45 | <tal:not-merged condition="not: contributor/merged"> | 45 | <li tal:condition="not: contributor/merged"> |
235 | 46 | <a tal:replace="structure contributor/fmt:link" /> | 46 | <a tal:replace="structure contributor/fmt:link"> |
236 | 47 | Mister Potato | ||
237 | 48 | </a> | ||
238 | 47 | (<a tal:attributes=" | 49 | (<a tal:attributes=" |
239 | 48 | href string:${context/fmt:url}/+filter?person=${contributor/name}" | 50 | href string:${context/fmt:url}/+filter?person=${contributor/name}" |
240 | 49 | >filter</a>) | 51 | >filter</a>) |
241 | 50 | </tal:not-merged> | ||
242 | 51 | </li> | 52 | </li> |
243 | 53 | </tal:contributors-loop> | ||
244 | 52 | </ul> | 54 | </ul> |
245 | 53 | 55 | ||
246 | 54 | <p | 56 | <p |
= Bug 512307= /translations. launchpad. net/+languages/ st we can see that Leonardo Gregianin appears twice, one with this current account (leogregianin) and an old merged one, (leogregianin- merged.
On https:/
We should not show merged accounts.
In bug 121520 , we fixed some placed where merged accounts were displayed, but missed language- portlet- top-contributor s.pt
== Proposed fix ==
Only show top 20 contributors and if we have a merged account in the top, replace it with the target account.
== Pre-implementation notes ==
My initial proposed fix was to just filter the merge account, but since by doing this we will no longer have a top 20, Jeroen asked to replace merged account with they target.
== Implementation details ==
Top contributors for a language, depends on the full contributors list and this is generated by cronjobs that compute the KarmaCache tables. I talked with Danilo and for writing the tests he suggest to fake the generation of language contributors.
In lib/lp/ translations/ templates/ pofile- details. pt I have done a small cleanup for my fix for bug 121520, since for merged account it generates empty <li> tags.
== Tests ==
lp-test -t language-views -t pofile-details
== Demo and Q/A ==
Since overall language statistics depends on KarmaCache and user preferences it is hard to test it on a local branch.
= Launchpad lint =
Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.
Linting changed files: translations/ browser/ language. py translations/ browser/ tests/language- views.txt translations/ stories/ standalone/ xx-pofile- details. txt translations/ templates/ language- portlet- top-contributor s.pt translations/ templates/ pofile- details. pt
lib/lp/
lib/lp/
lib/lp/
lib/lp/
lib/lp/