~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distributionsourcepackage.py

[r=wgrant][bug=831831] Refactor
 DistributionSourcePackage.getPersonsByEmail() into IPersonSet.getByEmails().

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    And,
21
21
    Count,
22
22
    Desc,
23
 
    Join,
24
23
    Max,
25
24
    Sum,
26
25
    )
32
31
    Storm,
33
32
    Unicode,
34
33
    )
35
 
from storm.store import EmptyResultSet
36
34
from zope.interface import implements
37
35
 
38
36
from canonical.database.sqlbase import sqlvalues
39
 
from canonical.launchpad.database.emailaddress import EmailAddress
40
37
from canonical.launchpad.interfaces.lpstorm import IStore
41
38
from canonical.lazr.utils import smartquote
42
39
from lp.bugs.interfaces.bugsummary import IBugSummaryDimension
65
62
from lp.registry.model.distroseries import DistroSeries
66
63
from lp.registry.model.karma import KarmaTotalCache
67
64
from lp.registry.model.packaging import Packaging
68
 
from lp.registry.model.person import Person
69
65
from lp.registry.model.sourcepackage import (
70
66
    SourcePackage,
71
67
    SourcePackageQuestionTargetMixin,
518
514
            sourcepackagename=self.sourcepackagename,
519
515
            language_code=language_code, language=language)
520
516
 
521
 
    @staticmethod
522
 
    def getPersonsByEmail(email_addresses):
523
 
        """[(EmailAddress,Person), ..] iterable for given email addresses."""
524
 
        if email_addresses is None or len(email_addresses) < 1:
525
 
            return EmptyResultSet()
526
 
        # Perform basic sanitization of email addresses.
527
 
        email_addresses = [
528
 
            address.lower().strip() for address in email_addresses]
529
 
        store = IStore(Person)
530
 
        origin = [
531
 
            Person, Join(EmailAddress, EmailAddress.personID == Person.id)]
532
 
        # Get all persons whose email addresses are in the list.
533
 
        result_set = store.using(*origin).find(
534
 
            (EmailAddress, Person),
535
 
            EmailAddress.email.lower().is_in(email_addresses))
536
 
        return result_set
537
 
 
538
517
    @classmethod
539
518
    def _get(cls, distribution, sourcepackagename):
540
519
        return Store.of(distribution).find(