~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Steve Kowalik
  • Date: 2011-07-26 23:37:30 UTC
  • mfrom: (13528 devel)
  • mto: This revision was merged to the branch mainline in revision 13536.
  • Revision ID: stevenk@ubuntu.com-20110726233730-mh04vxxvth98z9ps
Merge devel, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from storm.expr import (
27
27
    And,
28
28
    Coalesce,
 
29
    Desc,
29
30
    Exists,
30
31
    Join,
31
32
    LeftJoin,
548
549
 
549
550
        Call-site will have to have appropriate clauseTables.
550
551
        """
 
552
        # When all the code that uses this method is moved to Storm,
 
553
        # we can replace it with _getStormClausesForPOFileMessages
 
554
        # and then remove it.
551
555
        clauses = [
552
556
            'TranslationTemplateItem.potemplate = %s' % sqlvalues(
553
557
                self.potemplate),
559
563
 
560
564
        return clauses
561
565
 
 
566
    def _getStormClausesForPOFileMessages(self, current=True):
 
567
        """Get TranslationMessages for the POFile via TranslationTemplateItem.
 
568
        """
 
569
        clauses = [
 
570
            TranslationTemplateItem.potemplate == self.potemplate,
 
571
            (TranslationTemplateItem.potmsgsetID ==
 
572
             TranslationMessage.potmsgsetID),
 
573
            TranslationMessage.language == self.language,
 
574
            ]
 
575
        if current:
 
576
            clauses.append(TranslationTemplateItem.sequence > 0)
 
577
 
 
578
        return clauses
 
579
 
562
580
    def getTranslationsFilteredBy(self, person):
563
581
        """See `IPOFile`."""
564
582
        assert person is not None, "You must provide a person to filter by."
565
 
        clauses = self._getClausesForPOFileMessages(current=False)
 
583
        clauses = self._getStormClausesForPOFileMessages(current=False)
566
584
        clauses.append(
567
 
            'TranslationMessage.submitter = %s' % sqlvalues(person))
 
585
            TranslationMessage.submitter == person)
568
586
 
569
 
        return TranslationMessage.select(
570
 
            " AND ".join(clauses),
571
 
            clauseTables=['TranslationTemplateItem'],
572
 
            orderBy=['sequence', '-date_created'])
 
587
        results = Store.of(self).find(
 
588
            TranslationMessage,
 
589
            *clauses)
 
590
        return results.order_by(
 
591
            TranslationTemplateItem.sequence,
 
592
            Desc(TranslationMessage.date_created))
573
593
 
574
594
    def _getTranslatedMessagesQuery(self):
575
595
        """Get query data for fetching all POTMsgSets with translations.