14477.2.2
by Curtis Hovey
Move code karma subscribers to lp.code. |
1 |
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
|
8687.15.14
by Karl Fogel
Add the copyright header block to files under lib/lp/blueprints/. |
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
3237.1.12
by Bjorn Tillenius
fix test failures. |
3 |
|
4 |
__metaclass__ = type |
|
5 |
||
6 |
||
11824.1.4
by Tim Penhey
Fix imports for SpecificationGoalStatus. |
7 |
from lp.blueprints.enums import SpecificationGoalStatus |
7675.110.3
by Curtis Hovey
Ran the migration script to move registry code to lp.registry. |
8 |
from lp.registry.interfaces.person import IPerson |
14606.3.1
by William Grant
Merge canonical.database into lp.services.database. |
9 |
from lp.services.database.sqlbase import block_implicit_flushes |
3237.1.12
by Bjorn Tillenius
fix test failures. |
10 |
|
11 |
||
5821.2.27
by James Henstridge
* Add block_implicit_flushes decorator that blocks flushes performed |
12 |
@block_implicit_flushes
|
3237.1.12
by Bjorn Tillenius
fix test failures. |
13 |
def specification_goalstatus(spec, event): |
4285.2.1
by Mark Shuttleworth
Massive renaming of distrorelease to distroseries |
14 |
"""Update goalstatus if productseries or distroseries is changed."""
|
7876.3.12
by Francis J. Lacoste
Event.user is a principal, so we need an IPerson case. |
15 |
delta = spec.getDelta( |
16 |
event.object_before_modification, IPerson(event.user)) |
|
3237.1.12
by Bjorn Tillenius
fix test failures. |
17 |
if delta is None: |
18 |
return
|
|
4285.2.1
by Mark Shuttleworth
Massive renaming of distrorelease to distroseries |
19 |
if delta.productseries is not None or delta.distroseries is not None: |
3237.1.12
by Bjorn Tillenius
fix test failures. |
20 |
spec.goalstatus = SpecificationGoalStatus.PROPOSED |
11852.1.3
by Tim Penhey
Have the Specification.updateLifecycleStatus method called due to the object modified event in preparation of API exposure. |
21 |
|
22 |
||
23 |
def specification_update_lifecycle_status(spec, event): |
|
24 |
"""Mark the specification as started and/or complete if appropriate.
|
|
25 |
||
26 |
Does nothing if there is no user associated with the event.
|
|
27 |
"""
|
|
28 |
if event.user is None: |
|
29 |
return
|
|
30 |
spec.updateLifecycleStatus(IPerson(event.user)) |
|
14477.2.1
by Curtis Hovey
Moved blueprint karma subscribers to lp.blueprints. |
31 |
|
32 |
||
33 |
@block_implicit_flushes
|
|
34 |
def spec_created(spec, event): |
|
35 |
"""Assign karma to the user who created the spec."""
|
|
36 |
IPerson(event.user).assignKarma( |
|
37 |
'addspec', product=spec.product, distribution=spec.distribution) |
|
38 |
||
39 |
||
40 |
@block_implicit_flushes
|
|
41 |
def spec_modified(spec, event): |
|
42 |
"""Check changes made to the spec and assign karma if needed."""
|
|
43 |
user = IPerson(event.user) |
|
44 |
spec_delta = event.object.getDelta(event.object_before_modification, user) |
|
45 |
if spec_delta is None: |
|
46 |
return
|
|
47 |
||
48 |
# easy 1-1 mappings from attribute changing to karma
|
|
49 |
attrs_actionnames = { |
|
50 |
'title': 'spectitlechanged', |
|
51 |
'summary': 'specsummarychanged', |
|
52 |
'specurl': 'specurlchanged', |
|
53 |
'priority': 'specpriority', |
|
54 |
'productseries': 'specseries', |
|
55 |
'distroseries': 'specseries', |
|
56 |
'milestone': 'specmilestone', |
|
57 |
}
|
|
58 |
||
59 |
for attr, actionname in attrs_actionnames.items(): |
|
60 |
if getattr(spec_delta, attr, None) is not None: |
|
61 |
user.assignKarma( |
|
62 |
actionname, product=spec.product, |
|
63 |
distribution=spec.distribution) |
|
64 |
||
65 |
||
66 |
@block_implicit_flushes
|
|
67 |
def spec_branch_created(spec_branch, event): |
|
68 |
"""Assign karma to the user who linked the spec to the branch."""
|
|
69 |
spec_branch.branch.target.assignKarma( |
|
70 |
spec_branch.registrant, 'specbranchcreated') |