diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-06-18 16:32:54 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-06-20 17:44:26 +0200 |
commit | d77ed60b6f63f24d0523598fe9b7edc14a12658f (patch) | |
tree | 977323f7f7f532ecc2643d50d408943de810be84 /kittystore | |
parent | a76d36799e25e3e37b6900bfe981e63d4ef6c931 (diff) | |
download | kittystore-d77ed60b6f63f24d0523598fe9b7edc14a12658f.tar.gz kittystore-d77ed60b6f63f24d0523598fe9b7edc14a12658f.tar.xz kittystore-d77ed60b6f63f24d0523598fe9b7edc14a12658f.zip |
Add a method to return the top participants
Diffstat (limited to 'kittystore')
-rw-r--r-- | kittystore/storm/store.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py index 6a5364c..3b596db 100644 --- a/kittystore/storm/store.py +++ b/kittystore/storm/store.py @@ -20,7 +20,7 @@ from email.utils import unquote from zope.interface import implements from mailman.interfaces.messages import IMessageStore from storm.locals import Desc -from storm.expr import And, Or +from storm.expr import And, Or, Count, Alias from dateutil.tz import tzutc from kittystore import MessageNotFound @@ -487,6 +487,31 @@ class StormStore(object): )[num:num+1].one() return result + def get_top_participants(self, list_name, start, end, limit=None): + """ Return all the participants between two given dates. + + :param list_name: The name of the mailing list in which this email + should be searched. + :param start: A datetime object representing the starting date of + the interval to query. + :param end: A datetime object representing the ending date of + the interval to query. + :param limit: Limit the number of participants to return. If None or + not supplied, return them all. + :returns: The list of thread-starting messages. + """ + number = Alias(Count(Email.sender_email), "number") + part = self.db.find( + (Email.sender_name, Email.sender_email, number), + And( + Email.list_name == unicode(list_name), + Email.date >= start, + Email.date < end, + )).group_by(Email.sender_email, Email.sender_name).order_by(Desc(number)) + if limit is not None: + part = part.config(limit=limit) + return list(part) + # Attachments |