~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/model/domain.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:
26
26
    ]
27
27
 
28
28
 
 
29
from sqlalchemy import Column, Integer, Unicode
29
30
from urlparse import urljoin, urlparse
30
 
from storm.locals import Int, Unicode
31
31
from zope.event import notify
32
32
from zope.interface import implementer
33
33
 
44
44
class Domain(Model):
45
45
    """Domains."""
46
46
 
47
 
    id = Int(primary=True)
48
 
 
49
 
    mail_host = Unicode()
50
 
    base_url = Unicode()
51
 
    description = Unicode()
52
 
    contact_address = Unicode()
 
47
    __tablename__ = 'domain'
 
48
 
 
49
    id = Column(Integer, primary_key=True)
 
50
 
 
51
    mail_host = Column(Unicode) # TODO: add index?
 
52
    base_url = Column(Unicode)
 
53
    description = Column(Unicode)
 
54
    contact_address = Column(Unicode)
53
55
 
54
56
    def __init__(self, mail_host,
55
57
                 description=None,
92
94
    @dbconnection
93
95
    def mailing_lists(self, store):
94
96
        """See `IDomain`."""
95
 
        mailing_lists = store.find(
96
 
            MailingList,
97
 
            MailingList.mail_host == self.mail_host)
 
97
        mailing_lists = store.query(MailingList).filter(
 
98
            MailingList.mail_host == self.mail_host
 
99
            ).order_by(MailingList._list_id)
98
100
        for mlist in mailing_lists:
99
101
            yield mlist
100
102
 
140
142
    def remove(self, store, mail_host):
141
143
        domain = self[mail_host]
142
144
        notify(DomainDeletingEvent(domain))
143
 
        store.remove(domain)
 
145
        store.delete(domain)
144
146
        notify(DomainDeletedEvent(mail_host))
145
147
        return domain
146
148
 
147
149
    @dbconnection
148
150
    def get(self, store, mail_host, default=None):
149
151
        """See `IDomainManager`."""
150
 
        domains = store.find(Domain, mail_host=mail_host)
 
152
        domains = store.query(Domain).filter_by(mail_host=mail_host)
151
153
        if domains.count() < 1:
152
154
            return default
153
155
        assert domains.count() == 1, (
164
166
 
165
167
    @dbconnection
166
168
    def __len__(self, store):
167
 
        return store.find(Domain).count()
 
169
        return store.query(Domain).count()
168
170
 
169
171
    @dbconnection
170
172
    def __iter__(self, store):
171
173
        """See `IDomainManager`."""
172
 
        for domain in store.find(Domain):
 
174
        for domain in store.query(Domain).order_by(Domain.mail_host).all():
173
175
            yield domain
174
176
 
175
177
    @dbconnection
176
178
    def __contains__(self, store, mail_host):
177
179
        """See `IDomainManager`."""
178
 
        return store.find(Domain, mail_host=mail_host).count() > 0
 
180
        return store.query(Domain).filter_by(mail_host=mail_host).count() > 0