~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/blueprints/model/specification.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-24 00:34:34 UTC
  • mfrom: (13101.1.5 90628-spec-sub)
  • Revision ID: launchpad@pqm.canonical.com-20110524003434-n05kxyulvedoksmx
[r=sinzui][bug=90628] 'Sort blueprints subscribers list by display
        name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
from canonical.launchpad.helpers import (
53
53
    get_contact_email_addresses,
54
54
    )
 
55
from lp.services.propertycache import (
 
56
    cachedproperty,
 
57
    get_property_cache,
 
58
    )
55
59
from lp.blueprints.adapters import SpecificationDelta
56
60
from lp.blueprints.enums import (
57
61
    NewSpecificationDefinitionStatus,
182
186
    date_started = UtcDateTimeCol(notNull=False, default=None)
183
187
 
184
188
    # useful joins
185
 
    subscriptions = SQLMultipleJoin('SpecificationSubscription',
 
189
    _subscriptions = SQLMultipleJoin('SpecificationSubscription',
186
190
        joinColumn='specification', orderBy='id')
187
191
    subscribers = SQLRelatedJoin('Person',
188
192
        joinColumn='specification', otherColumn='person',
213
217
        otherColumn='specification', orderBy='title',
214
218
        intermediateTable='SpecificationDependency')
215
219
 
 
220
    @cachedproperty
 
221
    def subscriptions(self):
 
222
        """Sort the subscriptions"""
 
223
        return sorted(
 
224
            self._subscriptions, key=lambda sub: sub.person.displayname)
 
225
 
216
226
    @property
217
227
    def target(self):
218
228
        """See ISpecification."""
545
555
        # since no previous subscription existed, create and return a new one
546
556
        sub = SpecificationSubscription(specification=self,
547
557
            person=person, essential=essential)
 
558
        property_cache = get_property_cache(self)
 
559
        if 'subscription' in property_cache:
 
560
            property_cache.subscriptions.append(sub)
 
561
            property_cache.subscriptions.sort(
 
562
                key=lambda sub: sub.person.displayname)
548
563
        notify(ObjectCreatedEvent(sub, user=user))
549
564
        return sub
550
565
 
553
568
        # see if a relevant subscription exists, and if so, delete it
554
569
        for sub in self.subscriptions:
555
570
            if sub.person.id == person.id:
 
571
                get_property_cache(self).subscriptions.remove(sub)
556
572
                SpecificationSubscription.delete(sub.id)
557
573
                return
558
574
 
694
710
            self.id, self.name, self.target.name)
695
711
 
696
712
 
697
 
 
698
713
class HasSpecificationsMixin:
699
714
    """A mixin class that implements many of the common shortcut properties
700
715
    for other classes that have specifications.