~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-03-14 19:38:14 UTC
  • mto: This revision was merged to the branch mainline in revision 12622.
  • Revision ID: curtis.hovey@canonical.com-20110314193814-fchvgi85m4x5cuyl
Added any_person bool arg to IPersonMergeSource.find() so that a user
can be matched when it is either in the 'to' or 'from' relationship.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
from lazr.delegates import delegates
13
13
import simplejson
14
 
from storm.expr import And
 
14
from storm.expr import (
 
15
    And,
 
16
    Or,
 
17
    )
15
18
from storm.locals import (
16
19
    Int,
17
20
    Reference,
342
345
            minor_person=from_person, major_person=to_person, metadata={})
343
346
 
344
347
    @classmethod
345
 
    def find(cls, from_person=None, to_person=None):
 
348
    def find(cls, from_person=None, to_person=None, any_person=False):
346
349
        """See `IPersonMergeJobSource`."""
347
350
        conditions = [
348
351
            PersonTransferJob.job_type == cls.class_job_type,
349
352
            PersonTransferJob.job_id == Job.id,
350
353
            Job._status.is_in(Job.PENDING_STATUSES)]
 
354
        arg_conditions = []
351
355
        if from_person is not None:
352
 
            conditions.append(
 
356
            arg_conditions.append(
353
357
                PersonTransferJob.minor_person == from_person)
354
358
        if to_person is not None:
355
 
            conditions.append(
 
359
            arg_conditions.append(
356
360
                PersonTransferJob.major_person == to_person)
 
361
        if any_person and from_person is not None and to_person is not None:
 
362
            arg_conditions = [Or(*arg_conditions)]
 
363
        conditions.extend(arg_conditions)
357
364
        return DecoratedResultSet(
358
365
            IStore(PersonTransferJob).find(
359
366
                PersonTransferJob, *conditions), cls)