~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/model/potmsgset.py

[r=gmb][bug=504062,
        816366] Hide external suggestions to disabled translation templates
        by removing it from the suggestive potemplate cache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
 
376
376
        :param suggested_languages: Languages that suggestions should be found
377
377
            for.
378
 
        :param used_languages: Languages that used messages should be found for.
 
378
        :param used_languages: Languages that used messages should be found
 
379
            for.
379
380
        """
380
381
        if not config.rosetta.global_suggestions_enabled:
381
382
            return []
399
400
        used_languages = used_languages - both_languages
400
401
        lang_used = []
401
402
        if both_languages:
402
 
            lang_used.append('TranslationMessage.language IN %s' % 
 
403
            lang_used.append('TranslationMessage.language IN %s' %
403
404
                quote(both_languages))
404
405
        if used_languages:
405
406
            lang_used.append('(TranslationMessage.language IN %s AND %s)' % (
409
410
                '(TranslationMessage.language IN %s AND NOT %s)' % (
410
411
                quote(suggested_languages), in_use_clause))
411
412
 
412
 
        pots = SQL('''pots AS (
 
413
        msgsets = SQL('''msgsets AS (
413
414
                SELECT POTMsgSet.id
414
415
                FROM POTMsgSet
415
416
                JOIN TranslationTemplateItem ON
437
438
        ids_query = '''
438
439
            SELECT DISTINCT ON (%(msgstrs)s)
439
440
                TranslationMessage.id
440
 
            FROM TranslationMessage join pots on pots.id=translationmessage.potmsgset
 
441
            FROM TranslationMessage
 
442
            JOIN msgsets ON msgsets.id = TranslationMessage.potmsgset
441
443
            WHERE %(where)s
442
444
            ORDER BY %(msgstrs)s, date_created DESC
443
445
            ''' % ids_query_params
444
446
 
445
 
        result = IStore(TranslationMessage).with_(pots).find(
 
447
        result = IStore(TranslationMessage).with_(msgsets).find(
446
448
            TranslationMessage,
447
449
            TranslationMessage.id.is_in(SQL(ids_query)))
448
450
 
454
456
 
455
457
    def getExternallySuggestedTranslationMessages(self, language):
456
458
        """See `IPOTMsgSet`."""
457
 
        return self._getExternalTranslationMessages(suggested_languages=[language])
 
459
        return self._getExternalTranslationMessages(
 
460
            suggested_languages=[language])
458
461
 
459
462
    def getExternallySuggestedOrUsedTranslationMessages(self,
460
 
        suggested_languages=(), used_languages=()):
 
463
            suggested_languages=(), used_languages=()):
461
464
        """See `IPOTMsgSet`."""
462
465
        # This method exists because suggestions + used == all external
463
466
        # messages : its better not to do the work twice. We could use a
465
468
        # 2000, doing a single pass in python should be insignificantly
466
469
        # slower.
467
470
        result_type = namedtuple('SuggestedOrUsed', 'suggested used')
468
 
        result = defaultdict(lambda:result_type([], []))
 
471
        result = defaultdict(lambda: result_type([], []))
469
472
        for message in self._getExternalTranslationMessages(
470
473
            suggested_languages=suggested_languages,
471
474
            used_languages=used_languages):