~abompard/mailman/bug-1312884

« back to all changes in this revision

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

  • Committer: Barry Warsaw
  • Date: 2014-11-01 16:49:15 UTC
  • mfrom: (7251.1.38 abhilash)
  • Revision ID: barry@list.org-20141101164915-06wqfmya6wf47n6n
Database
--------
 * The ORM layer, previously implemented with Storm, has been replaced by
   SQLAlchemy, thanks to the fantastic work by Abhilash Raj and Aurélien
   Bompard.  Alembic is now used for all database schema migrations.
 * The new logger `mailman.database` logs any errors at the database layer.

API
---
 * Several changes to the internal API:
   - `IListManager.mailing_lists` is guaranteed to be sorted in List-ID order.
   - `IDomains.mailing_lists` is guaranteed to be sorted in List-ID order.
   - Iteration over domains via the `IDomainManager` is guaranteed to be sorted
     by `IDomain.mail_host` order.
   - `ITemporaryDatabase` interface and all implementations are removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
            raise InvalidEmailAddressError(fqdn_listname)
53
53
        list_id = '{0}.{1}'.format(listname, hostname)
54
54
        notify(ListCreatingEvent(fqdn_listname))
55
 
        mlist = store.find(
56
 
            MailingList,
57
 
            MailingList._list_id == list_id).one()
 
55
        mlist = store.query(MailingList).filter_by(_list_id=list_id).first()
58
56
        if mlist:
59
57
            raise ListAlreadyExistsError(fqdn_listname)
60
58
        mlist = MailingList(fqdn_listname)
68
66
        """See `IListManager`."""
69
67
        listname, at, hostname = fqdn_listname.partition('@')
70
68
        list_id = '{0}.{1}'.format(listname, hostname)
71
 
        return store.find(MailingList, MailingList._list_id == list_id).one()
 
69
        return store.query(MailingList).filter_by(_list_id=list_id).first()
72
70
 
73
71
    @dbconnection
74
72
    def get_by_list_id(self, store, list_id):
75
73
        """See `IListManager`."""
76
 
        return store.find(MailingList, MailingList._list_id == list_id).one()
 
74
        return store.query(MailingList).filter_by(_list_id=list_id).first()
77
75
 
78
76
    @dbconnection
79
77
    def delete(self, store, mlist):
80
78
        """See `IListManager`."""
81
79
        fqdn_listname = mlist.fqdn_listname
82
80
        notify(ListDeletingEvent(mlist))
83
 
        store.find(ContentFilter, ContentFilter.mailing_list == mlist).remove()
84
 
        store.remove(mlist)
 
81
        store.query(ContentFilter).filter_by(mailing_list=mlist).delete()
 
82
        store.delete(mlist)
85
83
        notify(ListDeletedEvent(fqdn_listname))
86
84
 
87
85
    @property
88
86
    @dbconnection
89
87
    def mailing_lists(self, store):
90
88
        """See `IListManager`."""
91
 
        for mlist in store.find(MailingList):
 
89
        for mlist in store.query(MailingList).order_by(
 
90
                MailingList._list_id).all():
92
91
            yield mlist
93
92
 
94
93
    @dbconnection
95
94
    def __iter__(self, store):
96
95
        """See `IListManager`."""
97
 
        for mlist in store.find(MailingList):
 
96
        for mlist in store.query(MailingList).all():
98
97
            yield mlist
99
98
 
100
99
    @property
101
100
    @dbconnection
102
101
    def names(self, store):
103
102
        """See `IListManager`."""
104
 
        result_set = store.find(MailingList)
 
103
        result_set = store.query(MailingList)
105
104
        for mail_host, list_name in result_set.values(MailingList.mail_host,
106
105
                                                      MailingList.list_name):
107
106
            yield '{0}@{1}'.format(list_name, mail_host)
110
109
    @dbconnection
111
110
    def list_ids(self, store):
112
111
        """See `IListManager`."""
113
 
        result_set = store.find(MailingList)
 
112
        result_set = store.query(MailingList)
114
113
        for list_id in result_set.values(MailingList._list_id):
115
 
            yield list_id
 
114
            assert isinstance(list_id, tuple) and len(list_id) == 1
 
115
            yield list_id[0]
116
116
 
117
117
    @property
118
118
    @dbconnection
119
119
    def name_components(self, store):
120
120
        """See `IListManager`."""
121
 
        result_set = store.find(MailingList)
 
121
        result_set = store.query(MailingList)
122
122
        for mail_host, list_name in result_set.values(MailingList.mail_host,
123
123
                                                      MailingList.list_name):
124
124
            yield list_name, mail_host