summaryrefslogtreecommitdiff
path: root/src/mailman/model/uid.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-06-03 13:21:38 -0400
committerBarry Warsaw2012-06-03 13:21:38 -0400
commite1aa901fbdcc6d7fbb495a1d9ca1a5079008164a (patch)
tree9146fed874216bfb88707848568d7598ec2e8522 /src/mailman/model/uid.py
parent847409ba333375bd9c168e28f15748e58970404f (diff)
parent3c8a07fc76176a8ea89ee6b73aef571d0b2c81ed (diff)
downloadmailman-e1aa901fbdcc6d7fbb495a1d9ca1a5079008164a.tar.gz
mailman-e1aa901fbdcc6d7fbb495a1d9ca1a5079008164a.tar.zst
mailman-e1aa901fbdcc6d7fbb495a1d9ca1a5079008164a.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)