Merge lp:~nigelbabu/launchpad/90628-spec-sub into lp:launchpad

Proposed by Nigel Babu
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 13106
Proposed branch: lp:~nigelbabu/launchpad/90628-spec-sub
Merge into: lp:launchpad
Diff against target: 122 lines (+27/-8)
3 files modified
lib/lp/blueprints/doc/specification-notifications.txt (+8/-3)
lib/lp/blueprints/model/specification.py (+17/-2)
lib/lp/blueprints/stories/standalone/subscribing.txt (+2/-3)
To merge this branch: bzr merge lp:~nigelbabu/launchpad/90628-spec-sub
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+62003@code.launchpad.net

Description of the change

Updated subscriptions to specifications to be sorted by name and cached.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you very much for this branch.

In our initial review of the code, we discovered that one change did not make sense. We discovered the the test was faulty so an additional change was need to test just the new subscription email. Testing also revealed a guard was need around my own suggestion to update the property_cache in subscribe(person).

This branch looks good to land, and I will do so now.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/blueprints/doc/specification-notifications.txt'
2--- lib/lp/blueprints/doc/specification-notifications.txt 2010-10-18 22:24:59 +0000
3+++ lib/lp/blueprints/doc/specification-notifications.txt 2011-05-23 20:02:28 +0000
4@@ -63,21 +63,27 @@
5
6 >>> for subscription in svg_support.subscriptions:
7 ... print subscription.person.preferredemail.email
8+ andrew.bennetts@ubuntulinux.com
9+ daf@canonical.com
10 foo.bar@canonical.com
11 robertc@robertcollins.net
12- andrew.bennetts@ubuntulinux.com
13 stuart.bishop@canonical.com
14- daf@canonical.com
15
16 Let's set a different approver and add a subscriber.
17
18 >>> from lp.registry.interfaces.person import IPersonSet
19+
20+ >>> stub.test_emails = []
21 >>> mark = getUtility(IPersonSet).getByEmail('mark@example.com')
22 >>> sample_person = getUtility(IPersonSet).getByEmail(
23 ... 'test@canonical.com')
24 >>> svg_support.approver = mark
25 >>> svg_support.subscribe(sample_person, sample_person, False)
26 <...>
27+ >>> transaction.commit()
28+ >>> for fromaddr, toaddrs, message in stub.test_emails:
29+ ... print toaddrs
30+ ['test@canonical.com']
31
32 Now if we edit the status, a notification will be sent to all the
33 previous people, and to the approver and the added subscriber:
34@@ -107,7 +113,6 @@
35 ['robertc@robertcollins.net']
36 ['stuart.bishop@canonical.com']
37 ['test@canonical.com']
38- ['test@canonical.com']
39
40 Now let's take a look at what the notification looks like:
41
42
43=== modified file 'lib/lp/blueprints/model/specification.py'
44--- lib/lp/blueprints/model/specification.py 2011-03-16 08:41:17 +0000
45+++ lib/lp/blueprints/model/specification.py 2011-05-23 20:02:28 +0000
46@@ -52,6 +52,10 @@
47 from canonical.launchpad.helpers import (
48 get_contact_email_addresses,
49 )
50+from lp.services.propertycache import (
51+ cachedproperty,
52+ get_property_cache,
53+ )
54 from lp.blueprints.adapters import SpecificationDelta
55 from lp.blueprints.enums import (
56 NewSpecificationDefinitionStatus,
57@@ -182,7 +186,7 @@
58 date_started = UtcDateTimeCol(notNull=False, default=None)
59
60 # useful joins
61- subscriptions = SQLMultipleJoin('SpecificationSubscription',
62+ _subscriptions = SQLMultipleJoin('SpecificationSubscription',
63 joinColumn='specification', orderBy='id')
64 subscribers = SQLRelatedJoin('Person',
65 joinColumn='specification', otherColumn='person',
66@@ -213,6 +217,12 @@
67 otherColumn='specification', orderBy='title',
68 intermediateTable='SpecificationDependency')
69
70+ @cachedproperty
71+ def subscriptions(self):
72+ """Sort the subscriptions"""
73+ return sorted(
74+ self._subscriptions, key=lambda sub: sub.person.displayname)
75+
76 @property
77 def target(self):
78 """See ISpecification."""
79@@ -545,6 +555,11 @@
80 # since no previous subscription existed, create and return a new one
81 sub = SpecificationSubscription(specification=self,
82 person=person, essential=essential)
83+ property_cache = get_property_cache(self)
84+ if 'subscription' in property_cache:
85+ property_cache.subscriptions.append(sub)
86+ property_cache.subscriptions.sort(
87+ key=lambda sub: sub.person.displayname)
88 notify(ObjectCreatedEvent(sub, user=user))
89 return sub
90
91@@ -553,6 +568,7 @@
92 # see if a relevant subscription exists, and if so, delete it
93 for sub in self.subscriptions:
94 if sub.person.id == person.id:
95+ get_property_cache(self).subscriptions.remove(sub)
96 SpecificationSubscription.delete(sub.id)
97 return
98
99@@ -694,7 +710,6 @@
100 self.id, self.name, self.target.name)
101
102
103-
104 class HasSpecificationsMixin:
105 """A mixin class that implements many of the common shortcut properties
106 for other classes that have specifications.
107
108=== modified file 'lib/lp/blueprints/stories/standalone/subscribing.txt'
109--- lib/lp/blueprints/stories/standalone/subscribing.txt 2010-12-07 01:03:17 +0000
110+++ lib/lp/blueprints/stories/standalone/subscribing.txt 2011-05-23 20:02:28 +0000
111@@ -273,10 +273,9 @@
112 ... img = a_tags[0].first('img')
113 ... print img['src'],
114 ... print a_tags[1].string
115+ /@@/subscriber-essential Andrew Bennetts
116+ /@@/subscriber-inessential Dafydd Harries
117 /@@/subscriber-inessential Foo Bar
118 /@@/subscriber-essential Robert Collins
119- /@@/subscriber-essential Andrew Bennetts
120 /@@/subscriber-inessential Stuart Bishop
121- /@@/subscriber-inessential Dafydd Harries
122-
123