18
18
"""Implementations of the pending requests interfaces."""
20
from __future__ import absolute_import, unicode_literals
20
from __future__ import absolute_import, print_function, unicode_literals
22
22
__metaclass__ = type
29
29
from zope.component import getUtility
30
30
from zope.interface import implements
32
from mailman.config import config
33
32
from mailman.database.model import Model
33
from mailman.database.transaction import dbconnection
34
34
from mailman.database.types import Enum
35
35
from mailman.interfaces.pending import IPendable, IPendings
36
36
from mailman.interfaces.requests import IListRequests, RequestType
49
49
self.mailing_list = mailing_list
53
return config.db.store.find(
54
_Request, mailing_list=self.mailing_list).count()
53
def count(self, store):
54
return store.find(_Request, mailing_list=self.mailing_list).count()
56
def count_of(self, request_type):
57
return config.db.store.find(
57
def count_of(self, store, request_type):
59
60
mailing_list=self.mailing_list, request_type=request_type).count()
62
def held_requests(self):
63
results = config.db.store.find(
64
_Request, mailing_list=self.mailing_list)
64
def held_requests(self, store):
65
results = store.find(_Request, mailing_list=self.mailing_list)
65
66
for request in results:
68
def of_type(self, request_type):
69
results = config.db.store.find(
70
def of_type(self, store, request_type):
71
73
mailing_list=self.mailing_list, request_type=request_type)
72
74
for request in results:
75
def hold_request(self, request_type, key, data=None):
78
def hold_request(self, store, request_type, key, data=None):
76
79
if request_type not in RequestType:
77
80
raise TypeError(request_type)
87
90
token = getUtility(IPendings).add(pendable, timedelta(days=5000))
89
92
request = _Request(key, request_type, self.mailing_list, data_hash)
90
config.db.store.add(request)
93
def get_request(self, request_id, request_type=None):
94
result = config.db.store.get(_Request, request_id)
97
def get_request(self, store, request_id, request_type=None):
98
result = store.get(_Request, request_id)
97
101
if request_type is not None and result.request_type != request_type:
104
108
data.update(pendable)
105
109
return result.key, data
107
def delete_request(self, request_id):
108
request = config.db.store.get(_Request, request_id)
112
def delete_request(self, store, request_id):
113
request = store.get(_Request, request_id)
109
114
if request is None:
110
115
raise KeyError(request_id)
111
116
# Throw away the pended data.
112
117
getUtility(IPendings).confirm(request.data_hash)
113
config.db.store.remove(request)
118
store.remove(request)