Move a module.
[mailman.git] / src / mailman / model / member.py
blob48bb5037fcf4f38c38bea0eb96f7890d9f288c19
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)
8 # any later version.
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
13 # more details.
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
22 __metaclass__ = type
23 __all__ = [
24 'Member',
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
38 class Member(Model):
39 implements(IMember)
41 id = Int(primary=True)
42 role = Enum()
43 mailing_list = Unicode()
44 is_moderated = Bool()
46 address_id = Int()
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):
52 self.role = role
53 self.mailing_list = mailing_list
54 self.address = address
55 self.is_moderated = False
57 def __repr__(self):
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)
63 if pref is not None:
64 return pref
65 pref = getattr(self.address.preferences, preference)
66 if pref is not None:
67 return pref
68 if self.address.user:
69 pref = getattr(self.address.user.preferences, preference)
70 if pref is not None:
71 return pref
72 return getattr(system_preferences, preference)
74 @property
75 def acknowledge_posts(self):
76 return self._lookup('acknowledge_posts')
78 @property
79 def preferred_language(self):
80 return self._lookup('preferred_language')
82 @property
83 def receive_list_copy(self):
84 return self._lookup('receive_list_copy')
86 @property
87 def receive_own_postings(self):
88 return self._lookup('receive_own_postings')
90 @property
91 def delivery_mode(self):
92 return self._lookup('delivery_mode')
94 @property
95 def delivery_status(self):
96 return self._lookup('delivery_status')
98 @property
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)