51
51
from zope.interface import implements
52
52
from zope.security.proxy import removeSecurityProxy
54
from lp.app.enums import ServiceUsage
54
from canonical.database.constants import DEFAULT
55
from canonical.database.datetimecol import UtcDateTimeCol
56
from canonical.database.enumcol import EnumCol
57
from canonical.database.sqlbase import (
58
flush_database_updates,
64
from canonical.launchpad import helpers
65
from canonical.launchpad.components.decoratedresultset import (
68
from canonical.launchpad.interfaces.lpstorm import (
55
72
from lp.app.errors import NotFoundError
56
73
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
57
74
from lp.registry.interfaces.person import validate_public_person
58
75
from lp.registry.model.packaging import Packaging
59
76
from lp.registry.model.sourcepackagename import SourcePackageName
60
77
from lp.services.database.collection import Collection
61
from lp.services.database.constants import DEFAULT
62
from lp.services.database.datetimecol import UtcDateTimeCol
63
from lp.services.database.decoratedresultset import DecoratedResultSet
64
from lp.services.database.enumcol import EnumCol
65
from lp.services.database.lpstorm import (
69
from lp.services.database.sqlbase import (
70
flush_database_updates,
76
from lp.services.helpers import shortlist
77
from lp.services.mail.helpers import get_email_template
78
78
from lp.services.propertycache import cachedproperty
79
79
from lp.services.worlddata.model.language import Language
80
80
from lp.translations.enums import RosettaImportStatus
244
244
"""See `IPOTemplate`."""
245
245
self._cached_pofiles_by_language = None
247
def _removeFromSuggestivePOTemplatesCache(self):
248
"""One level of indirection to make testing easier."""
250
IPOTemplateSet).removeFromSuggestivePOTemplatesCache(self)
252
def setActive(self, active):
253
"""See `IPOTemplate`."""
254
if not active and active != self.iscurrent:
255
self._removeFromSuggestivePOTemplatesCache()
256
self.iscurrent = active
259
248
def uses_english_msgids(self):
260
249
"""See `IPOTemplate`."""
933
922
rosetta_experts = getUtility(ILaunchpadCelebrities).rosetta_experts
934
923
subject = 'Translation template import - %s' % self.displayname
935
# Can use template_mail = 'poimport-template-confirmation.txt' to send
936
# mail when everything is imported, but those mails aren't very useful
937
# to or much welcomed by the recipients. See bug 855150.
924
template_mail = 'poimport-template-confirmation.txt'
939
925
errors, warnings = None, None
941
927
errors, warnings = translation_importer.importFile(
1014
1000
"Statistics update failed: %s" % unicode(error))
1016
if template_mail is not None:
1017
template = get_email_template(
1018
template_mail, 'translations')
1019
message = template % replacements
1020
return (subject, message)
1002
template = helpers.get_email_template(template_mail, 'translations')
1003
message = template % replacements
1004
return (subject, message)
1024
1006
def getTranslationRows(self):
1025
1007
"""See `IPOTemplate`."""
1207
1189
result = self._build_query(POTemplate.name == name, ordered=False)
1208
1190
return result.one()
1210
def getPOTemplatesByTranslationDomain(self, translation_domain):
1192
def getPOTemplateByTranslationDomain(self, translation_domain):
1211
1193
"""See `IPOTemplateSubset`."""
1212
return self._build_query(
1194
query_result = self._build_query(
1213
1195
POTemplate.translation_domain == translation_domain)
1197
# Fetch up to 2 templates, to check for duplicates.
1198
matches = query_result.config(limit=2)
1200
result = [match for match in matches]
1201
if len(result) == 0:
1203
elif len(result) == 1:
1206
templates = ['"%s"' % template.displayname for template in result]
1209
"Found %d competing templates with translation domain '%s': "
1211
% (len(templates), translation_domain, '; '.join(templates)))
1215
1214
def getPOTemplateByPath(self, path):
1216
1215
"""See `IPOTemplateSubset`."""
1217
1216
result = self._build_query(
1337
1336
conditions, POTemplate.distroseries == distroseries)
1339
1338
store = IStore(POTemplate)
1340
matches = shortlist(store.find(POTemplate, conditions))
1339
matches = helpers.shortlist(store.find(POTemplate, conditions))
1342
1341
if len(matches) == 0:
1376
1375
return IMasterStore(POTemplate).execute(
1377
1376
"DELETE FROM SuggestivePOTemplate").rowcount
1379
def removeFromSuggestivePOTemplatesCache(self, potemplate):
1380
"""See `IPOTemplateSet`."""
1381
rowcount = IMasterStore(POTemplate).execute(
1382
"DELETE FROM SuggestivePOTemplate "
1383
"WHERE potemplate = %s" % sqlvalues(potemplate)).rowcount
1384
return rowcount == 1
1386
1378
def populateSuggestivePOTemplatesCache(self):
1387
1379
"""See `IPOTemplateSet`."""
1380
# XXX j.c.sackett 2010-08-30 bug=627631 Once data migration has
1381
# happened for the usage enums, this sql needs to be updated to
1382
# check for the translations_usage, not official_rosetta.
1388
1383
return IMasterStore(POTemplate).execute("""
1389
1384
INSERT INTO SuggestivePOTemplate (
1390
1385
SELECT POTemplate.id
1399
1394
Product.id = ProductSeries.product
1401
1396
POTemplate.iscurrent AND (
1402
Distribution.translations_usage IN %(usage)s OR
1403
Product.translations_usage IN %(usage)s)
1397
Distribution.official_rosetta OR
1398
Product.official_rosetta)
1404
1399
ORDER BY POTemplate.id
1408
ServiceUsage.LAUNCHPAD, ServiceUsage.EXTERNAL)}
1412
1404
class POTemplateSharingSubset(object):