~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/model/listmanager.py

  • Committer: Barry Warsaw
  • Date: 2011-08-18 00:39:11 UTC
  • mfrom: (7036.1.4 bug-827036)
  • Revision ID: barry@list.org-20110818003911-9gef1p84g2pg4p10
 * Four new events are created, and notifications are sent during mailing list
   lifecycle changes:
   - ListCreatingEvent - sent before the mailing list is created
   - ListCreatedEvent  - sent after the mailing list is created
   - ListDeletingEvent - sent before the mailing list is deleted
   - ListDeletedEvent  - sent after the mailing list is deleted
 * Using the above events, when a mailing list is deleted, all its members are
   deleted, as well as all held message requests (but not the held messages
   themselves).  (LP: 827036)

Also: relax the find_member() argument constraints so that even the subscriber
email address is optional.  This is mirrored in the REST API's
.../members/find resource.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
import datetime
29
29
 
 
30
from zope.event import notify
30
31
from zope.interface import implements
31
32
 
32
33
from mailman.config import config
33
34
from mailman.interfaces.address import InvalidEmailAddressError
34
 
from mailman.interfaces.listmanager import IListManager, ListAlreadyExistsError
 
35
from mailman.interfaces.listmanager import (
 
36
    IListManager, ListAlreadyExistsError, ListCreatedEvent, ListCreatingEvent,
 
37
    ListDeletedEvent, ListDeletingEvent)
35
38
from mailman.model.mailinglist import MailingList
36
39
 
37
40
 
46
49
        listname, at, hostname = fqdn_listname.partition('@')
47
50
        if len(hostname) == 0:
48
51
            raise InvalidEmailAddressError(fqdn_listname)
 
52
        notify(ListCreatingEvent(fqdn_listname))
49
53
        mlist = config.db.store.find(
50
54
            MailingList,
51
55
            MailingList.list_name == listname,
55
59
        mlist = MailingList(fqdn_listname)
56
60
        mlist.created_at = datetime.datetime.now()
57
61
        config.db.store.add(mlist)
 
62
        notify(ListCreatedEvent(mlist))
58
63
        return mlist
59
64
 
60
65
    def get(self, fqdn_listname):
70
75
 
71
76
    def delete(self, mlist):
72
77
        """See `IListManager`."""
 
78
        fqdn_listname = mlist.fqdn_listname
 
79
        notify(ListDeletingEvent(mlist))
73
80
        config.db.store.remove(mlist)
 
81
        notify(ListDeletedEvent(fqdn_listname))
74
82
 
75
83
    @property
76
84
    def mailing_lists(self):