11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
1 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
||
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
4 |
"""Classes for managing the NameBlacklist table."""
|
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
5 |
|
6 |
__metaclass__ = type |
|
7 |
__all__ = [ |
|
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
8 |
'NameBlacklist', |
9 |
'NameBlacklistSet', |
|
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
10 |
]
|
11 |
||
12 |
||
13 |
from storm.locals import ( |
|
14 |
Int, |
|
7675.1022.4
by Curtis Hovey
Added admin the nameblacklist interface and model. |
15 |
Reference, |
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
16 |
Unicode, |
17 |
)
|
|
18 |
from zope.interface import implements |
|
19 |
||
20 |
from canonical.launchpad.interfaces.lpstorm import IStore |
|
11848.2.2
by Edwin Grubbs
Added tests. |
21 |
from lp.registry.interfaces.nameblacklist import ( |
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
22 |
INameBlacklist, |
23 |
INameBlacklistSet, |
|
11848.2.2
by Edwin Grubbs
Added tests. |
24 |
)
|
7675.1022.4
by Curtis Hovey
Added admin the nameblacklist interface and model. |
25 |
from lp.registry.model.person import Person |
12243.4.3
by j.c.sackett
Moved lp.services.stormbase to lp.services.database.stormbase |
26 |
from lp.services.database.stormbase import StormBase |
12243.4.2
by j.c.sackett
Updated all uses of storm.base.Storm with lp.services.stormbase.StormBase |
27 |
|
28 |
||
29 |
class NameBlacklist(StormBase): |
|
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
30 |
"""Class for the NameBlacklist table."""
|
31 |
||
32 |
implements(INameBlacklist) |
|
33 |
||
34 |
__storm_table__ = 'NameBlacklist' |
|
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
35 |
|
36 |
id = Int(primary=True) |
|
37 |
regexp = Unicode(name='regexp', allow_none=False) |
|
38 |
comment = Unicode(name='comment', allow_none=True) |
|
7675.1022.4
by Curtis Hovey
Added admin the nameblacklist interface and model. |
39 |
admin_id = Int(name='admin', allow_none=True) |
40 |
admin = Reference(admin_id, Person.id) |
|
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
41 |
|
42 |
||
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
43 |
class NameBlacklistSet: |
44 |
"""Class for creating and retrieving NameBlacklist objects."""
|
|
11848.2.1
by Edwin Grubbs
Added NameBlackList and NameBlackListSet. |
45 |
|
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
46 |
implements(INameBlacklistSet) |
11848.2.2
by Edwin Grubbs
Added tests. |
47 |
|
11848.2.5
by Edwin Grubbs
Added ability to view the name blacklist. |
48 |
def getAll(self): |
49 |
"""See `INameBlacklistSet`."""
|
|
50 |
store = IStore(NameBlacklist) |
|
51 |
return store.find(NameBlacklist).order_by(NameBlacklist.regexp) |
|
52 |
||
7675.1022.4
by Curtis Hovey
Added admin the nameblacklist interface and model. |
53 |
def create(self, regexp, comment=None, admin=None): |
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
54 |
"""See `INameBlacklistSet`."""
|
55 |
nameblacklist = NameBlacklist() |
|
11848.2.2
by Edwin Grubbs
Added tests. |
56 |
nameblacklist.regexp = regexp |
57 |
nameblacklist.comment = comment |
|
7675.1022.4
by Curtis Hovey
Added admin the nameblacklist interface and model. |
58 |
nameblacklist.admin = admin |
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
59 |
store = IStore(NameBlacklist) |
11848.2.2
by Edwin Grubbs
Added tests. |
60 |
store.add(nameblacklist) |
61 |
return nameblacklist |
|
62 |
||
63 |
def get(self, id): |
|
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
64 |
"""See `INameBlacklistSet`."""
|
11848.2.13
by Edwin Grubbs
Added breadcrumbs. |
65 |
try: |
66 |
id = int(id) |
|
67 |
except ValueError: |
|
68 |
return None |
|
11848.2.3
by Edwin Grubbs
Changed BlackList to Blacklist. |
69 |
store = IStore(NameBlacklist) |
70 |
return store.find(NameBlacklist, NameBlacklist.id == id).one() |
|
11848.2.6
by Edwin Grubbs
Added working +edit and +add views for INameBlacklist. |
71 |
|
72 |
def getByRegExp(self, regexp): |
|
73 |
"""See `INameBlacklistSet`."""
|
|
74 |
store = IStore(NameBlacklist) |
|
75 |
return store.find(NameBlacklist, NameBlacklist.regexp == regexp).one() |