29
29
from storm.locals import And, Date, Desc, Int, Reference
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.autorespond import (
36
36
IAutoResponseRecord, IAutoResponseSet, Response)
66
66
def __init__(self, mailing_list):
67
67
self._mailing_list = mailing_list
69
def todays_count(self, address, response_type):
70
def todays_count(self, store, address, response_type):
70
71
"""See `IAutoResponseSet`."""
71
return config.db.store.find(
72
73
AutoResponseRecord,
73
74
And(AutoResponseRecord.address == address,
74
75
AutoResponseRecord.mailing_list == self._mailing_list,
75
76
AutoResponseRecord.response_type == response_type,
76
77
AutoResponseRecord.date_sent == today())).count()
78
def response_sent(self, address, response_type):
80
def response_sent(self, store, address, response_type):
79
81
"""See `IAutoResponseSet`."""
80
82
response = AutoResponseRecord(
81
83
self._mailing_list, address, response_type)
82
config.db.store.add(response)
84
def last_response(self, address, response_type):
87
def last_response(self, store, address, response_type):
85
88
"""See `IAutoResponseSet`."""
86
results = config.db.store.find(
87
90
AutoResponseRecord,
88
91
And(AutoResponseRecord.address == address,
89
92
AutoResponseRecord.mailing_list == self._mailing_list,
90
93
AutoResponseRecord.response_type == response_type)
91
).order_by(Desc(AutoResponseRecord.date_sent))
94
).order_by(Desc(AutoResponseRecord.date_sent))
92
95
return (None if results.count() == 0 else results.first())