1 # Copyright (C) 2007-2009 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Model for members."""
20 from __future__
import absolute_import
, unicode_literals
27 from storm
.locals import *
28 from zope
.interface
import implements
30 from mailman
.config
import config
31 from mailman
.core
.constants
import system_preferences
32 from mailman
.database
.model
import Model
33 from mailman
.database
.types
import Enum
34 from mailman
.interfaces
.member
import IMember
41 id = Int(primary
=True)
43 mailing_list
= Unicode()
47 address
= Reference(address_id
, 'Address.id')
48 preferences_id
= Int()
49 preferences
= Reference(preferences_id
, 'Preferences.id')
51 def __init__(self
, role
, mailing_list
, address
):
53 self
.mailing_list
= mailing_list
54 self
.address
= address
55 self
.is_moderated
= False
58 return '<Member: {0} on {1} as {2}>'.format(
59 self
.address
, self
.mailing_list
, self
.role
)
61 def _lookup(self
, preference
):
62 pref
= getattr(self
.preferences
, preference
)
65 pref
= getattr(self
.address
.preferences
, preference
)
69 pref
= getattr(self
.address
.user
.preferences
, preference
)
72 return getattr(system_preferences
, preference
)
75 def acknowledge_posts(self
):
76 return self
._lookup
('acknowledge_posts')
79 def preferred_language(self
):
80 return self
._lookup
('preferred_language')
83 def receive_list_copy(self
):
84 return self
._lookup
('receive_list_copy')
87 def receive_own_postings(self
):
88 return self
._lookup
('receive_own_postings')
91 def delivery_mode(self
):
92 return self
._lookup
('delivery_mode')
95 def delivery_status(self
):
96 return self
._lookup
('delivery_status')
99 def options_url(self
):
100 # XXX Um, this is definitely wrong
101 return 'http://example.com/' + self
.address
.address
103 def unsubscribe(self
):
104 config
.db
.store
.remove(self
.preferences
)
105 config
.db
.store
.remove(self
)