~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
3346
3346
 
3347
3347
    def getByEmail(self, email):
3348
3348
        """See `IPersonSet`."""
3349
 
        email = ensure_unicode(email).strip().lower()
3350
 
        return IStore(Person).find(
 
3349
        address = self.getByEmails([email]).one()
 
3350
        if address:
 
3351
            return address[1]
 
3352
 
 
3353
    def getByEmails(self, emails, include_hidden=True):
 
3354
        """See `IPersonSet`."""
 
3355
        if not emails:
 
3356
            return EmptyResultSet()
 
3357
        addresses = [
 
3358
            ensure_unicode(address.lower().strip())
 
3359
            for address in emails]
 
3360
        extra_query = True
 
3361
        if not include_hidden:
 
3362
            extra_query = Person.hide_email_addresses == False
 
3363
        return IStore(Person).using(
3351
3364
            Person,
3352
 
            Person.id == EmailAddress.personID,
3353
 
            EmailAddress.email.lower() == email).one()
 
3365
            Join(EmailAddress, EmailAddress.personID == Person.id)
 
3366
        ).find(
 
3367
            (EmailAddress, Person),
 
3368
            EmailAddress.email.lower().is_in(addresses), extra_query)
3354
3369
 
3355
3370
    def latest_teams(self, limit=5):
3356
3371
        """See `IPersonSet`."""