Merge lp:~jtv/launchpad/independence-for-ihastranslationtemplates into lp:launchpad

Proposed by Jeroen T. Vermeulen on 2010-11-08
Status: Merged
Approved by: Jeroen T. Vermeulen on 2010-11-08
Approved revision: no longer in the source branch.
Merged at revision: 11890
Proposed branch: lp:~jtv/launchpad/independence-for-ihastranslationtemplates
Merge into: lp:launchpad
Diff against target: 667 lines (+257/-196)
15 files modified
lib/canonical/launchpad/interfaces/_schema_circular_imports.py (+7/-0)
lib/lp/registry/interfaces/distroseries.py (+3/-1)
lib/lp/registry/interfaces/productseries.py (+3/-1)
lib/lp/registry/interfaces/sourcepackage.py (+3/-1)
lib/lp/registry/model/distroseries.py (+3/-1)
lib/lp/registry/model/productseries.py (+3/-1)
lib/lp/registry/model/sourcepackage.py (+2/-2)
lib/lp/translations/browser/poexportrequest.py (+3/-1)
lib/lp/translations/interfaces/hastranslationtemplates.py (+104/-0)
lib/lp/translations/interfaces/potemplate.py (+0/-87)
lib/lp/translations/interfaces/translatedlanguage.py (+3/-1)
lib/lp/translations/model/hastranslationtemplates.py (+117/-0)
lib/lp/translations/model/potemplate.py (+0/-98)
lib/lp/translations/model/translatedlanguage.py (+3/-1)
lib/lp/translations/tests/test_hastranslationtemplates.py (+3/-1)
To merge this branch: bzr merge lp:~jtv/launchpad/independence-for-ihastranslationtemplates
Reviewer Review Type Date Requested Status
Henning Eggers (community) code 2010-11-08 Approve on 2010-11-08
Review via email: mp+40321@code.launchpad.net

Commit Message

Move IHasTranslationTemplates into its own file.

Description of the Change

= Independence for IHasTranslationTemplates! =

This branch does absolutely nothing but move IHasTranslationTemplates and its supporting mixin implementation into modules of their own. Helps avoid some circular imports I'm facing.

So instead of boring you with the formalities of a cover letter, instead let me tell you a story this reminds me of. I heard of someone who set up a food stall at some demonstration (either for or against global warming, I believe). To express his support for the cause, he gave the food he made away for free. The sign on his stall said: free falafel.

The first group to approach his stall asked: "who's Falafel?"

Jeroen

To post a comment you must log in.
Henning Eggers (henninge) wrote :

Very good! (Without looking too closely if the copied text really remains unchanged.) Thank you very much.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/interfaces/_schema_circular_imports.py'
2--- lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2010-11-04 07:14:21 +0000
3+++ lib/canonical/launchpad/interfaces/_schema_circular_imports.py 2010-11-08 12:49:43 +0000
4@@ -117,6 +117,9 @@
5 from lp.translations.interfaces.hastranslationimports import (
6 IHasTranslationImports,
7 )
8+from lp.translations.interfaces.hastranslationtemplates import (
9+ IHasTranslationTemplates,
10+ )
11 from lp.translations.interfaces.pofile import IPOFile
12 from lp.translations.interfaces.potemplate import (
13 IPOTemplate,
14@@ -475,6 +478,10 @@
15 # IBugTracker
16 patch_reference_property(IBugTracker, 'owner', IPerson)
17
18+# IHasTranslationTemplates
19+patch_collection_return_type(
20+ IHasTranslationTemplates, 'getTranslationTemplates', IPOTemplate)
21+
22 # IPOTemplate
23 patch_collection_property(IPOTemplate, 'pofiles', IPOFile)
24 patch_reference_property(IPOTemplate, 'product', IProduct)
25
26=== modified file 'lib/lp/registry/interfaces/distroseries.py'
27--- lib/lp/registry/interfaces/distroseries.py 2010-11-08 03:45:09 +0000
28+++ lib/lp/registry/interfaces/distroseries.py 2010-11-08 12:49:43 +0000
29@@ -89,8 +89,10 @@
30 from lp.translations.interfaces.hastranslationimports import (
31 IHasTranslationImports,
32 )
33+from lp.translations.interfaces.hastranslationtemplates import (
34+ IHasTranslationTemplates,
35+ )
36 from lp.translations.interfaces.languagepack import ILanguagePack
37-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
38
39
40 class DistroSeriesNameField(ContentNameField):
41
42=== modified file 'lib/lp/registry/interfaces/productseries.py'
43--- lib/lp/registry/interfaces/productseries.py 2010-10-29 10:01:34 +0000
44+++ lib/lp/registry/interfaces/productseries.py 2010-11-08 12:49:43 +0000
45@@ -76,7 +76,9 @@
46 from lp.translations.interfaces.hastranslationimports import (
47 IHasTranslationImports,
48 )
49-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
50+from lp.translations.interfaces.hastranslationtemplates import (
51+ IHasTranslationTemplates,
52+ )
53 from lp.translations.interfaces.translations import (
54 TranslationsBranchImportMode,
55 )
56
57=== modified file 'lib/lp/registry/interfaces/sourcepackage.py'
58--- lib/lp/registry/interfaces/sourcepackage.py 2010-10-29 10:01:34 +0000
59+++ lib/lp/registry/interfaces/sourcepackage.py 2010-11-08 12:49:43 +0000
60@@ -55,10 +55,12 @@
61 IHasMergeProposals,
62 )
63 from lp.soyuz.interfaces.component import IComponent
64+from lp.translations.interfaces.hastranslationtemplates import (
65+ IHasTranslationTemplates,
66+ )
67 from lp.translations.interfaces.hastranslationimports import (
68 IHasTranslationImports,
69 )
70-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
71
72
73 class ISourcePackage(IBugTarget, IHasBranches, IHasMergeProposals,
74
75=== modified file 'lib/lp/registry/model/distroseries.py'
76--- lib/lp/registry/model/distroseries.py 2010-11-08 03:45:09 +0000
77+++ lib/lp/registry/model/distroseries.py 2010-11-08 12:49:43 +0000
78@@ -187,11 +187,13 @@
79 from lp.translations.model.hastranslationimports import (
80 HasTranslationImportsMixin,
81 )
82+from lp.translations.model.hastranslationtemplates import (
83+ HasTranslationTemplatesMixin,
84+ )
85 from lp.translations.model.languagepack import LanguagePack
86 from lp.translations.model.pofile import POFile
87 from lp.translations.model.pofiletranslator import POFileTranslator
88 from lp.translations.model.potemplate import (
89- HasTranslationTemplatesMixin,
90 POTemplate,
91 TranslationTemplatesCollection,
92 )
93
94=== modified file 'lib/lp/registry/model/productseries.py'
95--- lib/lp/registry/model/productseries.py 2010-11-02 06:21:58 +0000
96+++ lib/lp/registry/model/productseries.py 2010-11-08 12:49:43 +0000
97@@ -92,9 +92,11 @@
98 from lp.translations.model.hastranslationimports import (
99 HasTranslationImportsMixin,
100 )
101+from lp.translations.model.hastranslationtemplates import (
102+ HasTranslationTemplatesMixin,
103+ )
104 from lp.translations.model.pofile import POFile
105 from lp.translations.model.potemplate import (
106- HasTranslationTemplatesMixin,
107 POTemplate,
108 TranslationTemplatesCollection,
109 )
110
111=== modified file 'lib/lp/registry/model/sourcepackage.py'
112--- lib/lp/registry/model/sourcepackage.py 2010-10-29 10:09:04 +0000
113+++ lib/lp/registry/model/sourcepackage.py 2010-11-08 12:49:43 +0000
114@@ -94,10 +94,10 @@
115 from lp.translations.model.hastranslationimports import (
116 HasTranslationImportsMixin,
117 )
118-from lp.translations.model.potemplate import (
119+from lp.translations.model.hastranslationtemplates import (
120 HasTranslationTemplatesMixin,
121- TranslationTemplatesCollection,
122 )
123+from lp.translations.model.potemplate import TranslationTemplatesCollection
124
125
126 class SourcePackageQuestionTargetMixin(QuestionTargetMixin):
127
128=== modified file 'lib/lp/translations/browser/poexportrequest.py'
129--- lib/lp/translations/browser/poexportrequest.py 2010-09-27 20:47:58 +0000
130+++ lib/lp/translations/browser/poexportrequest.py 2010-11-08 12:49:43 +0000
131@@ -19,7 +19,9 @@
132 from lp.app.browser.tales import DurationFormatterAPI
133 from lp.services.propertycache import cachedproperty
134 from lp.translations.interfaces.poexportrequest import IPOExportRequestSet
135-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
136+from lp.translations.interfaces.hastranslationtemplates import (
137+ IHasTranslationTemplates,
138+ )
139 from lp.translations.interfaces.translationexporter import (
140 ITranslationExporter,
141 )
142
143=== added file 'lib/lp/translations/interfaces/hastranslationtemplates.py'
144--- lib/lp/translations/interfaces/hastranslationtemplates.py 1970-01-01 00:00:00 +0000
145+++ lib/lp/translations/interfaces/hastranslationtemplates.py 2010-11-08 12:49:43 +0000
146@@ -0,0 +1,104 @@
147+# Copyright 2010 Canonical Ltd. This software is licensed under the
148+# GNU Affero General Public License version 3 (see the file LICENSE).
149+
150+"""Interface for objects that translation templates can belong to."""
151+
152+__metaclass__ = type
153+__all__ = [
154+ 'IHasTranslationTemplates',
155+ ]
156+
157+from lazr.restful.declarations import (
158+ export_read_operation,
159+ operation_returns_collection_of,
160+ )
161+from zope.interface import Interface
162+from zope.schema import Bool
163+
164+from canonical.launchpad import _
165+
166+
167+class IHasTranslationTemplates(Interface):
168+ """An entity that has translation templates attached.
169+
170+ Examples include `ISourcePackage`, `IDistroSeries`, and `IProductSeries`.
171+ """
172+
173+ has_translation_templates = Bool(
174+ title=_("Does this object have any translation templates?"),
175+ readonly=True)
176+
177+ has_current_translation_templates = Bool(
178+ title=_("Does this object have current translation templates?"),
179+ readonly=True)
180+
181+ has_translation_files = Bool(
182+ title=_("Does this object have translation files?"),
183+ readonly=True)
184+
185+ def getTemplatesCollection():
186+ """Return templates as a `TranslationTemplatesCollection`.
187+
188+ The collection selects all `POTemplate`s attached to the
189+ translation target that implements this interface.
190+ """
191+
192+ def getCurrentTemplatesCollection():
193+ """Return `TranslationTemplatesCollection` of current templates.
194+
195+ A translation template is considered active when both
196+ `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
197+ containing `Product` or `Distribution` are set to True.
198+ """
199+ # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
200+ # official_rosetta distinction into browser code.
201+
202+ def getCurrentTranslationTemplates(just_ids=False):
203+ """Return an iterator over all active translation templates.
204+
205+ :param just_ids: If True, return only the `POTemplate.id` rather
206+ than the full `POTemplate`. Used to save time on retrieving
207+ and deserializing the objects from the database.
208+
209+ A translation template is considered active when both
210+ `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
211+ containing `Product` or `Distribution` are set to True.
212+ """
213+ # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
214+ # official_rosetta distinction into browser code.
215+
216+ def getCurrentTranslationFiles(just_ids=False):
217+ """Return an iterator over all active translation files.
218+
219+ A translation file is active if it's attached to an
220+ active translation template.
221+ """
222+
223+ def getObsoleteTranslationTemplates():
224+ """Return an iterator over its not active translation templates.
225+
226+ A translation template is considered not active when any of
227+ `IPOTemplate`.iscurrent or `IDistribution`.official_rosetta flags
228+ are set to False.
229+ """
230+
231+ @export_read_operation()
232+ @operation_returns_collection_of(Interface)
233+ def getTranslationTemplates():
234+ """Return an iterator over all its translation templates.
235+
236+ The returned templates are either obsolete or current.
237+
238+ :return: A sequence of `IPOTemplate`.
239+ """
240+
241+ def getTranslationTemplateFormats():
242+ """A list of native formats for all current translation templates.
243+ """
244+
245+ def getTemplatesAndLanguageCounts():
246+ """List tuples of `POTemplate` and its language count.
247+
248+ A template's language count is the number of `POFile`s that
249+ exist for it.
250+ """
251
252=== modified file 'lib/lp/translations/interfaces/potemplate.py'
253--- lib/lp/translations/interfaces/potemplate.py 2010-10-03 15:30:06 +0000
254+++ lib/lp/translations/interfaces/potemplate.py 2010-11-08 12:49:43 +0000
255@@ -9,9 +9,7 @@
256 )
257 from lazr.restful.declarations import (
258 export_as_webservice_entry,
259- export_read_operation,
260 exported,
261- operation_returns_collection_of,
262 )
263 from lazr.restful.fields import (
264 CollectionField,
265@@ -47,7 +45,6 @@
266 __metaclass__ = type
267
268 __all__ = [
269- 'IHasTranslationTemplates',
270 'IPOTemplate',
271 'IPOTemplateSet',
272 'IPOTemplateSharingSubset',
273@@ -725,90 +722,6 @@
274 required=True)
275
276
277-class IHasTranslationTemplates(Interface):
278- """An entity that has translation templates attached.
279-
280- Examples include `ISourcePackage`, `IDistroSeries`, and `IProductSeries`.
281- """
282-
283- has_translation_templates = Bool(
284- title=_("Does this object have any translation templates?"),
285- readonly=True)
286-
287- has_current_translation_templates = Bool(
288- title=_("Does this object have current translation templates?"),
289- readonly=True)
290-
291- has_translation_files = Bool(
292- title=_("Does this object have translation files?"),
293- readonly=True)
294-
295- def getTemplatesCollection():
296- """Return templates as a `TranslationTemplatesCollection`.
297-
298- The collection selects all `POTemplate`s attached to the
299- translation target that implements this interface.
300- """
301-
302- def getCurrentTemplatesCollection():
303- """Return `TranslationTemplatesCollection` of current templates.
304-
305- A translation template is considered active when both
306- `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
307- containing `Product` or `Distribution` are set to True.
308- """
309- # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
310- # official_rosetta distinction into browser code.
311-
312- def getCurrentTranslationTemplates(just_ids=False):
313- """Return an iterator over all active translation templates.
314-
315- :param just_ids: If True, return only the `POTemplate.id` rather
316- than the full `POTemplate`. Used to save time on retrieving
317- and deserializing the objects from the database.
318-
319- A translation template is considered active when both
320- `IPOTemplate`.iscurrent and the `official_rosetta` flag for its
321- containing `Product` or `Distribution` are set to True.
322- """
323- # XXX JeroenVermeulen 2010-07-16 bug=605924: Move the
324- # official_rosetta distinction into browser code.
325-
326- def getCurrentTranslationFiles(just_ids=False):
327- """Return an iterator over all active translation files.
328-
329- A translation file is active if it's attached to an
330- active translation template.
331- """
332-
333- def getObsoleteTranslationTemplates():
334- """Return an iterator over its not active translation templates.
335-
336- A translation template is considered not active when any of
337- `IPOTemplate`.iscurrent or `IDistribution`.official_rosetta flags
338- are set to False.
339- """
340-
341- @export_read_operation()
342- @operation_returns_collection_of(IPOTemplate)
343- def getTranslationTemplates():
344- """Return an iterator over all its translation templates.
345-
346- The returned templates are either obsolete or current.
347- """
348-
349- def getTranslationTemplateFormats():
350- """A list of native formats for all current translation templates.
351- """
352-
353- def getTemplatesAndLanguageCounts():
354- """List tuples of `POTemplate` and its language count.
355-
356- A template's language count is the number of `POFile`s that
357- exist for it.
358- """
359-
360-
361 class ITranslationTemplatesCollection(Interface):
362 """A `Collection` of `POTemplate`s."""
363
364
365=== modified file 'lib/lp/translations/interfaces/translatedlanguage.py'
366--- lib/lp/translations/interfaces/translatedlanguage.py 2010-08-20 20:31:18 +0000
367+++ lib/lp/translations/interfaces/translatedlanguage.py 2010-11-08 12:49:43 +0000
368@@ -16,7 +16,9 @@
369 from canonical.launchpad import _
370 from lp.registry.interfaces.person import IPerson
371 from lp.services.worlddata.interfaces.language import ILanguage
372-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
373+from lp.translations.interfaces.hastranslationtemplates import (
374+ IHasTranslationTemplates,
375+ )
376
377
378 __metaclass__ = type
379
380=== added file 'lib/lp/translations/model/hastranslationtemplates.py'
381--- lib/lp/translations/model/hastranslationtemplates.py 1970-01-01 00:00:00 +0000
382+++ lib/lp/translations/model/hastranslationtemplates.py 2010-11-08 12:49:43 +0000
383@@ -0,0 +1,117 @@
384+# Copyright 2010 Canonical Ltd. This software is licensed under the
385+# GNU Affero General Public License version 3 (see the file LICENSE).
386+
387+"""Implementation class for objects that `POTemplate`s can belong to."""
388+
389+__metaclass__ = type
390+__all__ = [
391+ 'HasTranslationTemplatesMixin',
392+ ]
393+
394+from storm.expr import (
395+ Count,
396+ Desc,
397+ )
398+from zope.interface import implements
399+
400+from canonical.launchpad import helpers
401+from lp.app.enums import service_uses_launchpad
402+from lp.translations.interfaces.hastranslationtemplates import (
403+ IHasTranslationTemplates,
404+ )
405+from lp.translations.model.potemplate import POTemplate
406+from lp.translations.model.pofile import POFile
407+
408+
409+class HasTranslationTemplatesMixin:
410+ """Helper class for implementing `IHasTranslationTemplates`."""
411+ implements(IHasTranslationTemplates)
412+
413+ def getTemplatesCollection(self):
414+ """See `IHasTranslationTemplates`.
415+
416+ To be provided by derived classes.
417+ """
418+ raise NotImplementedError(
419+ "Child class must provide getTemplatesCollection.")
420+
421+ def _orderTemplates(self, result):
422+ """Apply the conventional ordering to a result set of templates."""
423+ return result.order_by(Desc(POTemplate.priority), POTemplate.name)
424+
425+ def getCurrentTemplatesCollection(self, current_value=True):
426+ """See `IHasTranslationTemplates`."""
427+ collection = self.getTemplatesCollection()
428+
429+ # XXX JeroenVermeulen 2010-07-15 bug=605924: Move the
430+ # translations_usage distinction into browser code.
431+ pillar = collection.target_pillar
432+ if service_uses_launchpad(pillar.translations_usage):
433+ return collection.restrictCurrent(current_value)
434+ else:
435+ # Product/Distribution does not have translation enabled.
436+ # Treat all templates as obsolete.
437+ return collection.refine(not current_value)
438+
439+ def getCurrentTranslationTemplates(self,
440+ just_ids=False,
441+ current_value=True):
442+ """See `IHasTranslationTemplates`."""
443+ if just_ids:
444+ selection = POTemplate.id
445+ else:
446+ selection = POTemplate
447+
448+ collection = self.getCurrentTemplatesCollection(current_value)
449+ return self._orderTemplates(collection.select(selection))
450+
451+ @property
452+ def has_translation_templates(self):
453+ """See `IHasTranslationTemplates`."""
454+ return bool(self.getTranslationTemplates().any())
455+
456+ @property
457+ def has_current_translation_templates(self):
458+ """See `IHasTranslationTemplates`."""
459+ return bool(
460+ self.getCurrentTranslationTemplates(just_ids=True).any())
461+
462+ def getCurrentTranslationFiles(self, just_ids=False):
463+ """See `IHasTranslationTemplates`."""
464+ if just_ids:
465+ selection = POFile.id
466+ else:
467+ selection = POFile
468+
469+ collection = self.getCurrentTemplatesCollection()
470+ return collection.joinPOFile().select(selection)
471+
472+ @property
473+ def has_translation_files(self):
474+ """See `IHasTranslationTemplates`."""
475+ return bool(
476+ self.getCurrentTranslationFiles(just_ids=True).any())
477+
478+ def getObsoleteTranslationTemplates(self):
479+ """See `IHasTranslationTemplates`."""
480+ # XXX JeroenVermeulen 2010-07-15 bug=605924: This returns a list
481+ # whereas the analogous method for current template returns a
482+ # result set. Clean up this mess.
483+ return list(self.getCurrentTranslationTemplates(current_value=False))
484+
485+ def getTranslationTemplates(self):
486+ """See `IHasTranslationTemplates`."""
487+ return self._orderTemplates(self.getTemplatesCollection().select())
488+
489+ def getTranslationTemplateFormats(self):
490+ """See `IHasTranslationTemplates`."""
491+ formats_query = self.getCurrentTranslationTemplates().order_by(
492+ 'source_file_format').config(distinct=True)
493+ return helpers.shortlist(
494+ formats_query.values(POTemplate.source_file_format), 10)
495+
496+ def getTemplatesAndLanguageCounts(self):
497+ """See `IHasTranslationTemplates`."""
498+ join = self.getTemplatesCollection().joinOuterPOFile()
499+ result = join.select(POTemplate, Count(POFile.id))
500+ return result.group_by(POTemplate)
501
502=== modified file 'lib/lp/translations/model/potemplate.py'
503--- lib/lp/translations/model/potemplate.py 2010-10-29 05:58:51 +0000
504+++ lib/lp/translations/model/potemplate.py 2010-11-08 12:49:43 +0000
505@@ -8,7 +8,6 @@
506 __metaclass__ = type
507 __all__ = [
508 'get_pofiles_for',
509- 'HasTranslationTemplatesMixin',
510 'POTemplate',
511 'POTemplateSet',
512 'POTemplateSubset',
513@@ -32,7 +31,6 @@
514 )
515 from storm.expr import (
516 And,
517- Count,
518 Desc,
519 In,
520 Join,
521@@ -64,7 +62,6 @@
522 IMasterStore,
523 IStore,
524 )
525-from lp.app.enums import service_uses_launchpad
526 from lp.app.errors import NotFoundError
527 from lp.registry.interfaces.person import validate_public_person
528 from lp.registry.model.sourcepackagename import SourcePackageName
529@@ -75,7 +72,6 @@
530 from lp.translations.enums import RosettaImportStatus
531 from lp.translations.interfaces.pofile import IPOFileSet
532 from lp.translations.interfaces.potemplate import (
533- IHasTranslationTemplates,
534 IPOTemplate,
535 IPOTemplateSet,
536 IPOTemplateSharingSubset,
537@@ -1555,100 +1551,6 @@
538 return messages
539
540
541-class HasTranslationTemplatesMixin:
542- """Helper class for implementing `IHasTranslationTemplates`."""
543- implements(IHasTranslationTemplates)
544-
545- def getTemplatesCollection(self):
546- """See `IHasTranslationTemplates`.
547-
548- To be provided by derived classes.
549- """
550- raise NotImplementedError(
551- "Child class must provide getTemplatesCollection.")
552-
553- def _orderTemplates(self, result):
554- """Apply the conventional ordering to a result set of templates."""
555- return result.order_by(Desc(POTemplate.priority), POTemplate.name)
556-
557- def getCurrentTemplatesCollection(self, current_value=True):
558- """See `IHasTranslationTemplates`."""
559- collection = self.getTemplatesCollection()
560-
561- # XXX JeroenVermeulen 2010-07-15 bug=605924: Move the
562- # translations_usage distinction into browser code.
563- pillar = collection.target_pillar
564- if service_uses_launchpad(pillar.translations_usage):
565- return collection.restrictCurrent(current_value)
566- else:
567- # Product/Distribution does not have translation enabled.
568- # Treat all templates as obsolete.
569- return collection.refine(not current_value)
570-
571- def getCurrentTranslationTemplates(self,
572- just_ids=False,
573- current_value=True):
574- """See `IHasTranslationTemplates`."""
575- if just_ids:
576- selection = POTemplate.id
577- else:
578- selection = POTemplate
579-
580- collection = self.getCurrentTemplatesCollection(current_value)
581- return self._orderTemplates(collection.select(selection))
582-
583- @property
584- def has_translation_templates(self):
585- """See `IHasTranslationTemplates`."""
586- return bool(self.getTranslationTemplates().any())
587-
588- @property
589- def has_current_translation_templates(self):
590- """See `IHasTranslationTemplates`."""
591- return bool(
592- self.getCurrentTranslationTemplates(just_ids=True).any())
593-
594- def getCurrentTranslationFiles(self, just_ids=False):
595- """See `IHasTranslationTemplates`."""
596- if just_ids:
597- selection = POFile.id
598- else:
599- selection = POFile
600-
601- collection = self.getCurrentTemplatesCollection()
602- return collection.joinPOFile().select(selection)
603-
604- @property
605- def has_translation_files(self):
606- """See `IHasTranslationTemplates`."""
607- return bool(
608- self.getCurrentTranslationFiles(just_ids=True).any())
609-
610- def getObsoleteTranslationTemplates(self):
611- """See `IHasTranslationTemplates`."""
612- # XXX JeroenVermeulen 2010-07-15 bug=605924: This returns a list
613- # whereas the analogous method for current template returns a
614- # result set. Clean up this mess.
615- return list(self.getCurrentTranslationTemplates(current_value=False))
616-
617- def getTranslationTemplates(self):
618- """See `IHasTranslationTemplates`."""
619- return self._orderTemplates(self.getTemplatesCollection().select())
620-
621- def getTranslationTemplateFormats(self):
622- """See `IHasTranslationTemplates`."""
623- formats_query = self.getCurrentTranslationTemplates().order_by(
624- 'source_file_format').config(distinct=True)
625- return helpers.shortlist(
626- formats_query.values(POTemplate.source_file_format), 10)
627-
628- def getTemplatesAndLanguageCounts(self):
629- """See `IHasTranslationTemplates`."""
630- join = self.getTemplatesCollection().joinOuterPOFile()
631- result = join.select(POTemplate, Count(POFile.id))
632- return result.group_by(POTemplate)
633-
634-
635 class TranslationTemplatesCollection(Collection):
636 """A `Collection` of `POTemplate`."""
637 starting_table = POTemplate
638
639=== modified file 'lib/lp/translations/model/translatedlanguage.py'
640--- lib/lp/translations/model/translatedlanguage.py 2010-08-20 20:31:18 +0000
641+++ lib/lp/translations/model/translatedlanguage.py 2010-11-08 12:49:43 +0000
642@@ -12,7 +12,9 @@
643 )
644 from zope.interface import implements
645
646-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
647+from lp.translations.interfaces.hastranslationtemplates import (
648+ IHasTranslationTemplates,
649+ )
650 from lp.translations.interfaces.translatedlanguage import (
651 IPOFilesByPOTemplates,
652 ITranslatedLanguage,
653
654=== modified file 'lib/lp/translations/tests/test_hastranslationtemplates.py'
655--- lib/lp/translations/tests/test_hastranslationtemplates.py 2010-10-04 19:50:45 +0000
656+++ lib/lp/translations/tests/test_hastranslationtemplates.py 2010-11-08 12:49:43 +0000
657@@ -8,7 +8,9 @@
658 from canonical.testing.layers import ZopelessDatabaseLayer
659 from lp.app.enums import ServiceUsage
660 from lp.testing import TestCaseWithFactory
661-from lp.translations.interfaces.potemplate import IHasTranslationTemplates
662+from lp.translations.interfaces.hastranslationtemplates import (
663+ IHasTranslationTemplates,
664+ )
665 from lp.translations.interfaces.translationfileformat import (
666 TranslationFileFormat,
667 )