summaryrefslogtreecommitdiff
path: root/src/mailman/model/uid.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-22 17:33:33 -0400
committerBarry Warsaw2012-04-22 17:33:33 -0400
commit4488631dff02731ff03f2fef01ee27bbd944812b (patch)
treea4064e30019764ffac7f5d65893b49779cb6918b /src/mailman/model/uid.py
parent7da6bb2bdba138877e53a70d224b253af14c65bc (diff)
parentcd3bab07fe2de591fee0dd27e9d47076a7e7db0f (diff)
downloadmailman-4488631dff02731ff03f2fef01ee27bbd944812b.tar.gz
mailman-4488631dff02731ff03f2fef01ee27bbd944812b.tar.zst
mailman-4488631dff02731ff03f2fef01ee27bbd944812b.zip
Diffstat (limited to 'src/mailman/model/uid.py')
-rw-r--r--src/mailman/model/uid.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mailman/model/uid.py b/src/mailman/model/uid.py
index c3564aa40..08eae8aff 100644
--- a/src/mailman/model/uid.py
+++ b/src/mailman/model/uid.py
@@ -17,7 +17,7 @@
"""Unique IDs."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -28,8 +28,8 @@ __all__ = [
from storm.locals import Int
from storm.properties import UUID
-from mailman.config import config
from mailman.database.model import Model
+from mailman.database.transaction import dbconnection
@@ -48,23 +48,29 @@ class UID(Model):
id = Int(primary=True)
uid = UUID()
- def __init__(self, uid):
+ @dbconnection
+ def __init__(self, store, uid):
super(UID, self).__init__()
self.uid = uid
- config.db.store.add(self)
+ store.add(self)
def __repr__(self):
return '<UID {0} at {1}>'.format(self.uid, id(self))
@staticmethod
- def record(uid):
+ @dbconnection
+ # Note that the parameter order is deliberate reversed here. Normally,
+ # `store` is the first parameter after `self`, but since this is a
+ # staticmethod and there is no self, the decorator will see the uid in
+ # arg[0].
+ def record(uid, store):
"""Record the uid in the database.
:param uid: The unique id.
:type uid: unicode
:raises ValueError: if the id is not unique.
"""
- existing = config.db.store.find(UID, uid=uid)
+ existing = store.find(UID, uid=uid)
if existing.count() != 0:
raise ValueError(uid)
return UID(uid)