~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Curtis Hovey
  • Date: 2011-05-27 21:53:34 UTC
  • mto: This revision was merged to the branch mainline in revision 13136.
  • Revision ID: curtis.hovey@canonical.com-20110527215334-jqlkmt52nnl4bpeh
Moved launchpad.event into registry interfaces.

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.app.errors import UserCannotUnsubscribePerson
 
55
from lp.services.propertycache import (
 
56
    cachedproperty,
 
57
    get_property_cache,
 
58
    )
56
59
from lp.blueprints.adapters import SpecificationDelta
57
60
from lp.blueprints.enums import (
58
61
    NewSpecificationDefinitionStatus,
90
93
from lp.registry.interfaces.person import validate_public_person
91
94
from lp.registry.interfaces.productseries import IProductSeries
92
95
from lp.registry.interfaces.product import IProduct
93
 
from lp.services.propertycache import (
94
 
    cachedproperty,
95
 
    get_property_cache,
96
 
    )
97
 
 
98
96
 
99
97
 
100
98
def recursive_blocked_query(spec):
222
220
    @cachedproperty
223
221
    def subscriptions(self):
224
222
        """Sort the subscriptions"""
225
 
        from lp.registry.model.person import person_sort_key
226
223
        return sorted(
227
 
            self._subscriptions, key=lambda sub: person_sort_key(sub.person))
 
224
            self._subscriptions, key=lambda sub: sub.person.displayname)
228
225
 
229
226
    @property
230
227
    def target(self):
537
534
                return sub
538
535
        return None
539
536
 
540
 
    def subscribe(self, person, subscribed_by=None, essential=False):
541
 
        """See ISpecification."""
542
 
        if subscribed_by is None:
543
 
            subscribed_by = person
544
 
        # Create or modify a user's subscription to this blueprint.
545
 
        # First see if a relevant subscription exists, and if so, return it
 
537
    def subscribe(self, person, user, essential):
 
538
        """Create or modify a user's subscription to this blueprint."""
 
539
        # first see if a relevant subscription exists, and if so, return it
546
540
        sub = self.subscription(person)
547
541
        if sub is not None:
548
542
            if sub.essential != essential:
556
550
                # that we can get away with not examining the attribute
557
551
                # at all - it's a boolean!
558
552
                notify(ObjectModifiedEvent(
559
 
                        sub, sub, ['essential'], user=subscribed_by))
 
553
                        sub, sub, ['essential'], user=user))
560
554
            return sub
561
555
        # since no previous subscription existed, create and return a new one
562
556
        sub = SpecificationSubscription(specification=self,
563
557
            person=person, essential=essential)
564
558
        property_cache = get_property_cache(self)
565
559
        if 'subscription' in property_cache:
566
 
            from lp.registry.model.person import person_sort_key
567
560
            property_cache.subscriptions.append(sub)
568
561
            property_cache.subscriptions.sort(
569
 
                key=lambda sub: person_sort_key(sub.person))
570
 
        notify(ObjectCreatedEvent(sub, user=subscribed_by))
 
562
                key=lambda sub: sub.person.displayname)
 
563
        notify(ObjectCreatedEvent(sub, user=user))
571
564
        return sub
572
565
 
573
 
    def unsubscribe(self, person, unsubscribed_by):
 
566
    def unsubscribe(self, person):
574
567
        """See ISpecification."""
575
568
        # see if a relevant subscription exists, and if so, delete it
576
 
        if person is None:
577
 
            person = unsubscribed_by
578
569
        for sub in self.subscriptions:
579
570
            if sub.person.id == person.id:
580
 
                if not sub.canBeUnsubscribedByUser(unsubscribed_by):
581
 
                    raise UserCannotUnsubscribePerson(
582
 
                        '%s does not have permission to unsubscribe %s.' % (
583
 
                            unsubscribed_by.displayname,
584
 
                            person.displayname))
585
571
                get_property_cache(self).subscriptions.remove(sub)
586
572
                SpecificationSubscription.delete(sub.id)
587
573
                return