Merge lp:~danilo/launchpad/no-dummy-psl into lp:launchpad
- no-dummy-psl
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Robert Collins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 11182 |
Proposed branch: | lp:~danilo/launchpad/no-dummy-psl |
Merge into: | lp:launchpad |
Diff against target: |
409 lines (+61/-85) 7 files modified
lib/lp/translations/browser/productseries.py (+7/-7) lib/lp/translations/browser/tests/test_breadcrumbs.py (+26/-12) lib/lp/translations/configure.zcml (+1/-6) lib/lp/translations/doc/canonical_url_examples.txt (+6/-5) lib/lp/translations/interfaces/productserieslanguage.py (+2/-7) lib/lp/translations/model/productserieslanguage.py (+12/-44) lib/lp/translations/tests/test_productserieslanguage.py (+7/-4) |
To merge this branch: | bzr merge lp:~danilo/launchpad/no-dummy-psl |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Approve | ||
Review via email: mp+30293@code.launchpad.net |
Commit message
Get rid of DummyProductSer
Description of the change
= Get rid of dummy ProductSeriesLa
When ProductSeriesLa
As part of reworking ISeriesLanguage interface to be more generic and re-usable, this is a refactoring branch that gets rid of the DummyProductSer
= Tests =
bin/test -cvvt productseriesla
(we just confirm everything works as it used to: existing tests cover all the cases where we were using dummies, and the dummy_ProductSe
= QA =
https:/
https:/
Both work in identical way to how they work today, but we've got less code for a net win.
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/
lib/lp/
lib/lp/
lib/lp/
lib/lp/
lib/lp/
lib/lp/
Robert Collins (lifeless) : | # |
Preview Diff
1 | === modified file 'lib/lp/translations/browser/productseries.py' | |||
2 | --- lib/lp/translations/browser/productseries.py 2010-06-17 03:29:53 +0000 | |||
3 | +++ lib/lp/translations/browser/productseries.py 2010-07-21 09:39:56 +0000 | |||
4 | @@ -344,9 +344,7 @@ | |||
5 | 344 | 344 | ||
6 | 345 | Produces a list containing a ProductSeriesLanguage object for | 345 | Produces a list containing a ProductSeriesLanguage object for |
7 | 346 | each language this product has been translated into, and for each | 346 | each language this product has been translated into, and for each |
11 | 347 | of the user's preferred languages. Where the series has no | 347 | of the user's preferred languages. |
9 | 348 | ProductSeriesLanguage for that language, we use a | ||
10 | 349 | DummyProductSeriesLanguage. | ||
12 | 350 | """ | 348 | """ |
13 | 351 | 349 | ||
14 | 352 | if self.context.potemplate_count == 0: | 350 | if self.context.potemplate_count == 0: |
15 | @@ -369,11 +367,13 @@ | |||
16 | 369 | pofile = pot.getPOFileByLang(lang.code) | 367 | pofile = pot.getPOFileByLang(lang.code) |
17 | 370 | if pofile is None: | 368 | if pofile is None: |
18 | 371 | pofile = pot.getDummyPOFile(lang.code) | 369 | pofile = pot.getDummyPOFile(lang.code) |
21 | 372 | productserieslang = productserieslangset.getDummy( | 370 | productserieslang = ( |
22 | 373 | self.context, lang, pofile=pofile) | 371 | productserieslangset.getProductSeriesLanguage( |
23 | 372 | self.context, lang, pofile=pofile)) | ||
24 | 374 | else: | 373 | else: |
27 | 375 | productserieslang = productserieslangset.getDummy( | 374 | productserieslang = ( |
28 | 376 | self.context, lang) | 375 | productserieslangset.getProductSeriesLanguage( |
29 | 376 | self.context, lang)) | ||
30 | 377 | productserieslangs.append( | 377 | productserieslangs.append( |
31 | 378 | productserieslang) | 378 | productserieslang) |
32 | 379 | 379 | ||
33 | 380 | 380 | ||
34 | === modified file 'lib/lp/translations/browser/tests/test_breadcrumbs.py' | |||
35 | --- lib/lp/translations/browser/tests/test_breadcrumbs.py 2010-04-28 10:13:00 +0000 | |||
36 | +++ lib/lp/translations/browser/tests/test_breadcrumbs.py 2010-07-21 09:39:56 +0000 | |||
37 | @@ -23,7 +23,8 @@ | |||
38 | 23 | name='crumb-tester', displayname="Crumb Tester") | 23 | name='crumb-tester', displayname="Crumb Tester") |
39 | 24 | self.assertBreadcrumbs( | 24 | self.assertBreadcrumbs( |
40 | 25 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), | 25 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), |
42 | 26 | ("Translations", 'http://translations.launchpad.dev/crumb-tester')], | 26 | ("Translations", |
43 | 27 | 'http://translations.launchpad.dev/crumb-tester')], | ||
44 | 27 | product, rootsite='translations') | 28 | product, rootsite='translations') |
45 | 28 | 29 | ||
46 | 29 | def test_productseries(self): | 30 | def test_productseries(self): |
47 | @@ -33,7 +34,8 @@ | |||
48 | 33 | self.assertBreadcrumbs( | 34 | self.assertBreadcrumbs( |
49 | 34 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), | 35 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), |
50 | 35 | ("Series test", 'http://launchpad.dev/crumb-tester/test'), | 36 | ("Series test", 'http://launchpad.dev/crumb-tester/test'), |
52 | 36 | ("Translations", 'http://translations.launchpad.dev/crumb-tester/test')], | 37 | ("Translations", |
53 | 38 | 'http://translations.launchpad.dev/crumb-tester/test')], | ||
54 | 37 | series, rootsite='translations') | 39 | series, rootsite='translations') |
55 | 38 | 40 | ||
56 | 39 | def test_distribution(self): | 41 | def test_distribution(self): |
57 | @@ -41,7 +43,8 @@ | |||
58 | 41 | name='crumb-tester', displayname="Crumb Tester") | 43 | name='crumb-tester', displayname="Crumb Tester") |
59 | 42 | self.assertBreadcrumbs( | 44 | self.assertBreadcrumbs( |
60 | 43 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), | 45 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), |
62 | 44 | ("Translations", 'http://translations.launchpad.dev/crumb-tester')], | 46 | ("Translations", |
63 | 47 | 'http://translations.launchpad.dev/crumb-tester')], | ||
64 | 45 | distribution, rootsite='translations') | 48 | distribution, rootsite='translations') |
65 | 46 | 49 | ||
66 | 47 | def test_distroseries(self): | 50 | def test_distroseries(self): |
67 | @@ -52,7 +55,8 @@ | |||
68 | 52 | self.assertBreadcrumbs( | 55 | self.assertBreadcrumbs( |
69 | 53 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), | 56 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), |
70 | 54 | ("Test (1.0)", 'http://launchpad.dev/crumb-tester/test'), | 57 | ("Test (1.0)", 'http://launchpad.dev/crumb-tester/test'), |
72 | 55 | ("Translations", 'http://translations.launchpad.dev/crumb-tester/test')], | 58 | ("Translations", |
73 | 59 | 'http://translations.launchpad.dev/crumb-tester/test')], | ||
74 | 56 | series, rootsite='translations') | 60 | series, rootsite='translations') |
75 | 57 | 61 | ||
76 | 58 | def test_project(self): | 62 | def test_project(self): |
77 | @@ -60,7 +64,8 @@ | |||
78 | 60 | name='crumb-tester', displayname="Crumb Tester") | 64 | name='crumb-tester', displayname="Crumb Tester") |
79 | 61 | self.assertBreadcrumbs( | 65 | self.assertBreadcrumbs( |
80 | 62 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), | 66 | [("Crumb Tester", 'http://launchpad.dev/crumb-tester'), |
82 | 63 | ("Translations", 'http://translations.launchpad.dev/crumb-tester')], | 67 | ("Translations", |
83 | 68 | 'http://translations.launchpad.dev/crumb-tester')], | ||
84 | 64 | project, rootsite='translations') | 69 | project, rootsite='translations') |
85 | 65 | 70 | ||
86 | 66 | def test_person(self): | 71 | def test_person(self): |
87 | @@ -68,7 +73,8 @@ | |||
88 | 68 | name='crumb-tester', displayname="Crumb Tester") | 73 | name='crumb-tester', displayname="Crumb Tester") |
89 | 69 | self.assertBreadcrumbs( | 74 | self.assertBreadcrumbs( |
90 | 70 | [("Crumb Tester", 'http://launchpad.dev/~crumb-tester'), | 75 | [("Crumb Tester", 'http://launchpad.dev/~crumb-tester'), |
92 | 71 | ("Translations", 'http://translations.launchpad.dev/~crumb-tester')], | 76 | ("Translations", |
93 | 77 | 'http://translations.launchpad.dev/~crumb-tester')], | ||
94 | 72 | person, rootsite='translations') | 78 | person, rootsite='translations') |
95 | 73 | 79 | ||
96 | 74 | 80 | ||
97 | @@ -77,14 +83,16 @@ | |||
98 | 77 | def test_translationgroupset(self): | 83 | def test_translationgroupset(self): |
99 | 78 | group_set = getUtility(ITranslationGroupSet) | 84 | group_set = getUtility(ITranslationGroupSet) |
100 | 79 | self.assertBreadcrumbs( | 85 | self.assertBreadcrumbs( |
102 | 80 | [("Translation groups", 'http://translations.launchpad.dev/+groups')], | 86 | [("Translation groups", |
103 | 87 | 'http://translations.launchpad.dev/+groups')], | ||
104 | 81 | group_set, rootsite='translations') | 88 | group_set, rootsite='translations') |
105 | 82 | 89 | ||
106 | 83 | def test_translationgroup(self): | 90 | def test_translationgroup(self): |
107 | 84 | group = self.factory.makeTranslationGroup( | 91 | group = self.factory.makeTranslationGroup( |
108 | 85 | name='test-translators', title='Test translators') | 92 | name='test-translators', title='Test translators') |
109 | 86 | self.assertBreadcrumbs( | 93 | self.assertBreadcrumbs( |
111 | 87 | [("Translation groups", 'http://translations.launchpad.dev/+groups'), | 94 | [("Translation groups", |
112 | 95 | 'http://translations.launchpad.dev/+groups'), | ||
113 | 88 | ("Test translators", | 96 | ("Test translators", |
114 | 89 | 'http://translations.launchpad.dev/+groups/test-translators')], | 97 | 'http://translations.launchpad.dev/+groups/test-translators')], |
115 | 90 | group, rootsite='translations') | 98 | group, rootsite='translations') |
116 | @@ -111,7 +119,8 @@ | |||
117 | 111 | ("Translations", | 119 | ("Translations", |
118 | 112 | "http://translations.launchpad.dev/crumb-tester/test"), | 120 | "http://translations.launchpad.dev/crumb-tester/test"), |
119 | 113 | ("Serbian (sr)", | 121 | ("Serbian (sr)", |
121 | 114 | "http://translations.launchpad.dev/crumb-tester/test/+lang/sr")], | 122 | "http://translations.launchpad.dev/" |
122 | 123 | "crumb-tester/test/+lang/sr")], | ||
123 | 115 | serieslanguage) | 124 | serieslanguage) |
124 | 116 | 125 | ||
125 | 117 | def test_productserieslanguage(self): | 126 | def test_productserieslanguage(self): |
126 | @@ -119,7 +128,8 @@ | |||
127 | 119 | name='crumb-tester', displayname="Crumb Tester") | 128 | name='crumb-tester', displayname="Crumb Tester") |
128 | 120 | series = self.factory.makeProductSeries( | 129 | series = self.factory.makeProductSeries( |
129 | 121 | name="test", product=product) | 130 | name="test", product=product) |
131 | 122 | serieslanguage = getUtility(IProductSeriesLanguageSet).getDummy( | 131 | psl_set = getUtility(IProductSeriesLanguageSet) |
132 | 132 | serieslanguage = psl_set.getProductSeriesLanguage( | ||
133 | 123 | series, self.language) | 133 | series, self.language) |
134 | 124 | 134 | ||
135 | 125 | self.assertBreadcrumbs( | 135 | self.assertBreadcrumbs( |
136 | @@ -128,11 +138,14 @@ | |||
137 | 128 | ("Translations", | 138 | ("Translations", |
138 | 129 | "http://translations.launchpad.dev/crumb-tester/test"), | 139 | "http://translations.launchpad.dev/crumb-tester/test"), |
139 | 130 | ("Serbian (sr)", | 140 | ("Serbian (sr)", |
141 | 131 | "http://translations.launchpad.dev/crumb-tester/test/+lang/sr")], | 141 | "http://translations.launchpad.dev/" |
142 | 142 | "crumb-tester/test/+lang/sr")], | ||
143 | 132 | serieslanguage) | 143 | serieslanguage) |
144 | 133 | 144 | ||
145 | 134 | 145 | ||
146 | 135 | class TestPOTemplateBreadcrumbs(BaseBreadcrumbTestCase): | 146 | class TestPOTemplateBreadcrumbs(BaseBreadcrumbTestCase): |
147 | 147 | """Test POTemplate breadcrumbs.""" | ||
148 | 148 | |||
149 | 136 | def test_potemplate(self): | 149 | def test_potemplate(self): |
150 | 137 | product = self.factory.makeProduct( | 150 | product = self.factory.makeProduct( |
151 | 138 | name='crumb-tester', displayname="Crumb Tester", | 151 | name='crumb-tester', displayname="Crumb Tester", |
152 | @@ -147,7 +160,8 @@ | |||
153 | 147 | ("Translations", | 160 | ("Translations", |
154 | 148 | "http://translations.launchpad.dev/crumb-tester/test"), | 161 | "http://translations.launchpad.dev/crumb-tester/test"), |
155 | 149 | (smartquote('Template "template"'), | 162 | (smartquote('Template "template"'), |
157 | 150 | "http://translations.launchpad.dev/crumb-tester/test/+pots/template")], | 163 | "http://translations.launchpad.dev/" |
158 | 164 | "crumb-tester/test/+pots/template")], | ||
159 | 151 | potemplate) | 165 | potemplate) |
160 | 152 | 166 | ||
161 | 153 | 167 | ||
162 | 154 | 168 | ||
163 | === modified file 'lib/lp/translations/configure.zcml' | |||
164 | --- lib/lp/translations/configure.zcml 2010-05-04 13:42:25 +0000 | |||
165 | +++ lib/lp/translations/configure.zcml 2010-07-21 09:39:56 +0000 | |||
166 | @@ -372,7 +372,7 @@ | |||
167 | 372 | interface="lp.translations.interfaces.translationtemplateitem.ITranslationTemplateItem"/> | 372 | interface="lp.translations.interfaces.translationtemplateitem.ITranslationTemplateItem"/> |
168 | 373 | </class> | 373 | </class> |
169 | 374 | 374 | ||
171 | 375 | <!-- ProductSeriesLanguage and Dummy --> | 375 | <!-- ProductSeriesLanguage --> |
172 | 376 | 376 | ||
173 | 377 | <adapter | 377 | <adapter |
174 | 378 | provides="canonical.launchpad.webapp.interfaces.IBreadcrumb" | 378 | provides="canonical.launchpad.webapp.interfaces.IBreadcrumb" |
175 | @@ -385,11 +385,6 @@ | |||
176 | 385 | <allow | 385 | <allow |
177 | 386 | interface="lp.translations.interfaces.productserieslanguage.IProductSeriesLanguage"/> | 386 | interface="lp.translations.interfaces.productserieslanguage.IProductSeriesLanguage"/> |
178 | 387 | </class> | 387 | </class> |
179 | 388 | <class | ||
180 | 389 | class="lp.translations.model.productserieslanguage.DummyProductSeriesLanguage"> | ||
181 | 390 | <allow | ||
182 | 391 | interface="lp.translations.interfaces.productserieslanguage.IProductSeriesLanguage"/> | ||
183 | 392 | </class> | ||
184 | 393 | 388 | ||
185 | 394 | <!-- ProductSeriesLanguageSet --> | 389 | <!-- ProductSeriesLanguageSet --> |
186 | 395 | 390 | ||
187 | 396 | 391 | ||
188 | === modified file 'lib/lp/translations/doc/canonical_url_examples.txt' | |||
189 | --- lib/lp/translations/doc/canonical_url_examples.txt 2009-09-17 16:22:32 +0000 | |||
190 | +++ lib/lp/translations/doc/canonical_url_examples.txt 2010-07-21 09:39:56 +0000 | |||
191 | @@ -50,13 +50,13 @@ | |||
192 | 50 | 50 | ||
193 | 51 | >>> potemplate = potemplatesubset['evolution-2.2'] | 51 | >>> potemplate = potemplatesubset['evolution-2.2'] |
194 | 52 | >>> canonical_url(potemplate) | 52 | >>> canonical_url(potemplate) |
196 | 53 | u'http://translations.launchpad.dev/ubuntu/hoary/+source/evolution/+pots/evolution-2.2' | 53 | u'http://translations.../hoary/+source/evolution/+pots/evolution-2.2' |
197 | 54 | 54 | ||
198 | 55 | And we can get a particular PO file for this PO template by its language code. | 55 | And we can get a particular PO file for this PO template by its language code. |
199 | 56 | 56 | ||
200 | 57 | >>> pofile = potemplate.getPOFileByLang('es') | 57 | >>> pofile = potemplate.getPOFileByLang('es') |
201 | 58 | >>> canonical_url(pofile) | 58 | >>> canonical_url(pofile) |
203 | 59 | u'http://translations.../ubuntu/hoary/+source/evolution/+pots/evolution-2.2/es' | 59 | u'http://translations.../hoary/+source/evolution/+pots/evolution-2.2/es' |
204 | 60 | 60 | ||
205 | 61 | Also, we can get the url to a translation message. | 61 | Also, we can get the url to a translation message. |
206 | 62 | 62 | ||
207 | @@ -65,7 +65,7 @@ | |||
208 | 65 | ... pofile.potemplate, pofile.language) | 65 | ... pofile.potemplate, pofile.language) |
209 | 66 | >>> translationmessage.setPOFile(pofile) | 66 | >>> translationmessage.setPOFile(pofile) |
210 | 67 | >>> print canonical_url(translationmessage) | 67 | >>> print canonical_url(translationmessage) |
212 | 68 | http://translations.../ubuntu/hoary/+source/evolution/+pots/evolution-2.2/es/1 | 68 | http://transl.../hoary/+source/evolution/+pots/evolution-2.2/es/1 |
213 | 69 | 69 | ||
214 | 70 | Even for a dummy one. | 70 | Even for a dummy one. |
215 | 71 | 71 | ||
216 | @@ -73,7 +73,7 @@ | |||
217 | 73 | >>> translationmessage = potmsgset.getCurrentDummyTranslationMessage( | 73 | >>> translationmessage = potmsgset.getCurrentDummyTranslationMessage( |
218 | 74 | ... pofile.potemplate, pofile.language) | 74 | ... pofile.potemplate, pofile.language) |
219 | 75 | >>> print canonical_url(translationmessage) | 75 | >>> print canonical_url(translationmessage) |
221 | 76 | http://translations.../ubuntu/hoary/+source/evolution/+pots/evolution-2.2/es/20 | 76 | http://transl.../hoary/+source/evolution/+pots/evolution-2.2/es/20 |
222 | 77 | 77 | ||
223 | 78 | Upstream POTemplateSubsets work in much the same way, except they hang off a | 78 | Upstream POTemplateSubsets work in much the same way, except they hang off a |
224 | 79 | product series. Let's get a product series. | 79 | product series. Let's get a product series. |
225 | @@ -173,7 +173,8 @@ | |||
226 | 173 | >>> from lp.translations.interfaces.productserieslanguage import ( | 173 | >>> from lp.translations.interfaces.productserieslanguage import ( |
227 | 174 | ... IProductSeriesLanguageSet) | 174 | ... IProductSeriesLanguageSet) |
228 | 175 | 175 | ||
230 | 176 | >>> coo_cah_serbian = getUtility(IProductSeriesLanguageSet).getDummy( | 176 | >>> psl_set = getUtility(IProductSeriesLanguageSet) |
231 | 177 | >>> coo_cah_serbian = psl_set.getProductSeriesLanguage( | ||
232 | 177 | ... productseries, serbian) | 178 | ... productseries, serbian) |
233 | 178 | >>> canonical_url(coo_cah_serbian) | 179 | >>> canonical_url(coo_cah_serbian) |
234 | 179 | u'http://translations.launchpad.dev/coo/cah/+lang/sr' | 180 | u'http://translations.launchpad.dev/coo/cah/+lang/sr' |
235 | 180 | 181 | ||
236 | === modified file 'lib/lp/translations/interfaces/productserieslanguage.py' | |||
237 | --- lib/lp/translations/interfaces/productserieslanguage.py 2009-10-30 19:38:18 +0000 | |||
238 | +++ lib/lp/translations/interfaces/productserieslanguage.py 2010-07-21 09:39:56 +0000 | |||
239 | @@ -49,7 +49,6 @@ | |||
240 | 49 | last_changed_date = Datetime( | 49 | last_changed_date = Datetime( |
241 | 50 | title=_('When this file was last changed.')) | 50 | title=_('When this file was last changed.')) |
242 | 51 | 51 | ||
243 | 52 | |||
244 | 53 | def getPOFilesFor(potemplates): | 52 | def getPOFilesFor(potemplates): |
245 | 54 | """Return `POFiles` for each of `potemplates`, in the same order. | 53 | """Return `POFiles` for each of `potemplates`, in the same order. |
246 | 55 | 54 | ||
247 | @@ -67,10 +66,6 @@ | |||
248 | 67 | class IProductSeriesLanguageSet(Interface): | 66 | class IProductSeriesLanguageSet(Interface): |
249 | 68 | """The set of productserieslanguages.""" | 67 | """The set of productserieslanguages.""" |
250 | 69 | 68 | ||
257 | 70 | def getDummy(productseries, language, variant=None): | 69 | def getProductSeriesLanguage(productseries, language, variant=None, |
258 | 71 | """Return a new DummyProductSeriesLanguage for the given | 70 | pofile=None): |
253 | 72 | productseries and language. | ||
254 | 73 | """ | ||
255 | 74 | |||
256 | 75 | def getProductSeriesLanguage(productseries, language, variant=None): | ||
259 | 76 | """Return a PSL for a productseries and a language.""" | 71 | """Return a PSL for a productseries and a language.""" |
260 | 77 | 72 | ||
261 | === modified file 'lib/lp/translations/model/productserieslanguage.py' | |||
262 | --- lib/lp/translations/model/productserieslanguage.py 2009-10-30 19:39:58 +0000 | |||
263 | +++ lib/lp/translations/model/productserieslanguage.py 2010-07-21 09:39:56 +0000 | |||
264 | @@ -6,18 +6,17 @@ | |||
265 | 6 | __metaclass__ = type | 6 | __metaclass__ = type |
266 | 7 | 7 | ||
267 | 8 | __all__ = [ | 8 | __all__ = [ |
268 | 9 | 'DummyProductSeriesLanguage', | ||
269 | 10 | 'ProductSeriesLanguage', | 9 | 'ProductSeriesLanguage', |
270 | 11 | 'ProductSeriesLanguageSet', | 10 | 'ProductSeriesLanguageSet', |
271 | 12 | ] | 11 | ] |
272 | 13 | 12 | ||
273 | 14 | from zope.interface import implements | 13 | from zope.interface import implements |
274 | 15 | 14 | ||
276 | 16 | from storm.expr import Sum | 15 | from storm.expr import Coalesce, Sum |
277 | 17 | from storm.store import Store | 16 | from storm.store import Store |
278 | 18 | 17 | ||
279 | 19 | from lp.translations.utilities.rosettastats import RosettaStats | 18 | from lp.translations.utilities.rosettastats import RosettaStats |
281 | 20 | from lp.translations.model.pofile import DummyPOFile, POFile | 19 | from lp.translations.model.pofile import POFile |
282 | 21 | from lp.translations.model.potemplate import get_pofiles_for, POTemplate | 20 | from lp.translations.model.potemplate import get_pofiles_for, POTemplate |
283 | 22 | from lp.translations.interfaces.productserieslanguage import ( | 21 | from lp.translations.interfaces.productserieslanguage import ( |
284 | 23 | IProductSeriesLanguage, IProductSeriesLanguageSet) | 22 | IProductSeriesLanguage, IProductSeriesLanguageSet) |
285 | @@ -41,8 +40,8 @@ | |||
286 | 41 | # Reset all cached counts. | 40 | # Reset all cached counts. |
287 | 42 | self.setCounts() | 41 | self.setCounts() |
288 | 43 | 42 | ||
291 | 44 | def setCounts(self, total=None, imported=None, changed=None, new=None, | 43 | def setCounts(self, total=0, imported=0, changed=0, new=0, |
292 | 45 | unreviewed=None, last_changed=None): | 44 | unreviewed=0, last_changed=None): |
293 | 46 | """See `IProductSeriesLanguage`.""" | 45 | """See `IProductSeriesLanguage`.""" |
294 | 47 | self._messagecount = total | 46 | self._messagecount = total |
295 | 48 | # "currentcount" in RosettaStats conflicts our recent terminology | 47 | # "currentcount" in RosettaStats conflicts our recent terminology |
296 | @@ -55,7 +54,6 @@ | |||
297 | 55 | if last_changed is not None: | 54 | if last_changed is not None: |
298 | 56 | self._last_changed_date = last_changed | 55 | self._last_changed_date = last_changed |
299 | 57 | 56 | ||
300 | 58 | |||
301 | 59 | def _getMessageCount(self): | 57 | def _getMessageCount(self): |
302 | 60 | store = Store.of(self.language) | 58 | store = Store.of(self.language) |
303 | 61 | query = store.find(Sum(POTemplate.messagecount), | 59 | query = store.find(Sum(POTemplate.messagecount), |
304 | @@ -70,20 +68,16 @@ | |||
305 | 70 | """See `IProductSeriesLanguage`.""" | 68 | """See `IProductSeriesLanguage`.""" |
306 | 71 | store = Store.of(self.language) | 69 | store = Store.of(self.language) |
307 | 72 | query = store.find( | 70 | query = store.find( |
312 | 73 | (Sum(POFile.currentcount), | 71 | (Coalesce(Sum(POFile.currentcount), 0), |
313 | 74 | Sum(POFile.updatescount), | 72 | Coalesce(Sum(POFile.updatescount), 0), |
314 | 75 | Sum(POFile.rosettacount), | 73 | Coalesce(Sum(POFile.rosettacount), 0), |
315 | 76 | Sum(POFile.unreviewed_count)), | 74 | Coalesce(Sum(POFile.unreviewed_count), 0)), |
316 | 77 | POFile.language==self.language, | 75 | POFile.language==self.language, |
317 | 78 | POFile.variant==None, | 76 | POFile.variant==None, |
318 | 79 | POFile.potemplate==POTemplate.id, | 77 | POFile.potemplate==POTemplate.id, |
319 | 80 | POTemplate.productseries==self.productseries, | 78 | POTemplate.productseries==self.productseries, |
320 | 81 | POTemplate.iscurrent==True) | 79 | POTemplate.iscurrent==True) |
321 | 82 | imported, changed, new, unreviewed = query[0] | 80 | imported, changed, new, unreviewed = query[0] |
322 | 83 | if (imported is None or changed is None or | ||
323 | 84 | new is None or unreviewed is None): | ||
324 | 85 | # Set all counts to zero. | ||
325 | 86 | imported = changed = new = unreviewed = 0 | ||
326 | 87 | self.setCounts(self._getMessageCount(), imported, changed, | 81 | self.setCounts(self._getMessageCount(), imported, changed, |
327 | 88 | new, unreviewed) | 82 | new, unreviewed) |
328 | 89 | 83 | ||
329 | @@ -138,40 +132,14 @@ | |||
330 | 138 | return get_pofiles_for(potemplates, self.language, self.variant) | 132 | return get_pofiles_for(potemplates, self.language, self.variant) |
331 | 139 | 133 | ||
332 | 140 | 134 | ||
333 | 141 | class DummyProductSeriesLanguage(ProductSeriesLanguage): | ||
334 | 142 | """See `IProductSeriesLanguage`. | ||
335 | 143 | |||
336 | 144 | Implementation of IProductSeriesLanguage for a language with no | ||
337 | 145 | translations. | ||
338 | 146 | """ | ||
339 | 147 | implements(IProductSeriesLanguage) | ||
340 | 148 | |||
341 | 149 | def __init__(self, productseries, language, variant=None, pofile=None): | ||
342 | 150 | ProductSeriesLanguage.__init__( | ||
343 | 151 | self, productseries, language, variant, pofile) | ||
344 | 152 | self.setCounts(self._getMessageCount(), 0, 0, 0, 0) | ||
345 | 153 | |||
346 | 154 | def getPOFilesFor(self, potemplates): | ||
347 | 155 | """See `IProductSeriesLanguage`.""" | ||
348 | 156 | return [ | ||
349 | 157 | DummyPOFile(template, self.language, self.variant) | ||
350 | 158 | for template in potemplates | ||
351 | 159 | ] | ||
352 | 160 | |||
353 | 161 | |||
354 | 162 | class ProductSeriesLanguageSet: | 135 | class ProductSeriesLanguageSet: |
355 | 163 | """See `IProductSeriesLanguageSet`. | 136 | """See `IProductSeriesLanguageSet`. |
356 | 164 | 137 | ||
358 | 165 | Provides a means to get a ProductSeriesLanguage or create a dummy. | 138 | Provides a means to get a ProductSeriesLanguage. |
359 | 166 | """ | 139 | """ |
360 | 167 | implements(IProductSeriesLanguageSet) | 140 | implements(IProductSeriesLanguageSet) |
361 | 168 | 141 | ||
362 | 169 | def getProductSeriesLanguage(self, productseries, language, | 142 | def getProductSeriesLanguage(self, productseries, language, |
371 | 170 | variant=None): | 143 | variant=None, pofile=None): |
372 | 171 | """See `IProductSeriesLanguageSet`.""" | 144 | """See `IProductSeriesLanguageSet`.""" |
373 | 172 | return ProductSeriesLanguage(productseries, language, variant) | 145 | return ProductSeriesLanguage(productseries, language, variant, pofile) |
366 | 173 | |||
367 | 174 | def getDummy(self, productseries, language, variant=None, pofile=None): | ||
368 | 175 | """See `IProductSeriesLanguageSet`.""" | ||
369 | 176 | return DummyProductSeriesLanguage( | ||
370 | 177 | productseries, language, variant, pofile) | ||
374 | 178 | 146 | ||
375 | === modified file 'lib/lp/translations/tests/test_productserieslanguage.py' | |||
376 | --- lib/lp/translations/tests/test_productserieslanguage.py 2009-11-04 17:15:56 +0000 | |||
377 | +++ lib/lp/translations/tests/test_productserieslanguage.py 2010-07-21 09:39:56 +0000 | |||
378 | @@ -143,16 +143,19 @@ | |||
379 | 143 | psl.last_changed_date), | 143 | psl.last_changed_date), |
380 | 144 | stats) | 144 | stats) |
381 | 145 | 145 | ||
383 | 146 | def test_DummyProductSeriesLanguage(self): | 146 | def test_dummy_ProductSeriesLanguage(self): |
384 | 147 | # With no templates all counts are zero. | 147 | # With no templates all counts are zero. |
386 | 148 | psl = self.psl_set.getDummy(self.productseries, self.language) | 148 | psl = self.psl_set.getProductSeriesLanguage( |
387 | 149 | self.productseries, self.language) | ||
388 | 149 | self.failUnless(verifyObject(IProductSeriesLanguage, psl)) | 150 | self.failUnless(verifyObject(IProductSeriesLanguage, psl)) |
389 | 150 | self.assertPSLStatistics(psl, (0, 0, 0, 0, 0, 0, None)) | 151 | self.assertPSLStatistics(psl, (0, 0, 0, 0, 0, 0, None)) |
390 | 151 | 152 | ||
391 | 152 | # Adding a single template with 10 messages makes the total | 153 | # Adding a single template with 10 messages makes the total |
392 | 153 | # count of messages go up to 10. | 154 | # count of messages go up to 10. |
393 | 154 | potemplate = self.createPOTemplateWithPOTMsgSets(10) | 155 | potemplate = self.createPOTemplateWithPOTMsgSets(10) |
395 | 155 | psl = self.psl_set.getDummy(self.productseries, self.language) | 156 | psl = self.psl_set.getProductSeriesLanguage( |
396 | 157 | self.productseries, self.language) | ||
397 | 158 | psl.recalculateCounts() | ||
398 | 156 | self.assertPSLStatistics( | 159 | self.assertPSLStatistics( |
399 | 157 | psl, (10, 0, 0, 0, 0, 0, None)) | 160 | psl, (10, 0, 0, 0, 0, 0, None)) |
400 | 158 | 161 | ||
401 | @@ -168,7 +171,7 @@ | |||
402 | 168 | # Getting PSL through PSLSet gives an uninitialized object. | 171 | # Getting PSL through PSLSet gives an uninitialized object. |
403 | 169 | psl = self.psl_set.getProductSeriesLanguage( | 172 | psl = self.psl_set.getProductSeriesLanguage( |
404 | 170 | self.productseries, self.language) | 173 | self.productseries, self.language) |
406 | 171 | self.assertEquals(psl.messageCount(), None) | 174 | self.assertEquals(psl.messageCount(), 0) |
407 | 172 | 175 | ||
408 | 173 | # So, we need to get it through productseries.productserieslanguages. | 176 | # So, we need to get it through productseries.productserieslanguages. |
409 | 174 | psl = self.productseries.productserieslanguages[0] | 177 | psl = self.productseries.productserieslanguages[0] |