summaryrefslogtreecommitdiff
path: root/src/mailman/model/uid.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-22 16:34:15 -0400
committerBarry Warsaw2012-04-22 16:34:15 -0400
commitaa12d1c5a4544e7005a6a93e2fff6e130b30e8b6 (patch)
tree133091548bacfb926f179845c17350c3c8aa1104 /src/mailman/model/uid.py
parentc95c06c080eded049e2f7516d61f579661dfb1c0 (diff)
downloadmailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.tar.gz
mailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.tar.zst
mailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.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)