summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Mailman/database/model/user.py4
-rw-r--r--Mailman/database/usermanager.py6
-rw-r--r--Mailman/docs/usermanager.txt46
-rw-r--r--Mailman/docs/users.txt52
4 files changed, 47 insertions, 61 deletions
diff --git a/Mailman/database/model/user.py b/Mailman/database/model/user.py
index 2d87b9648..84b5a4595 100644
--- a/Mailman/database/model/user.py
+++ b/Mailman/database/model/user.py
@@ -61,10 +61,10 @@ class User(Model):
def register(self, address, real_name=None):
# First, see if the address already exists
- addrobj = Address.get_by(address=address)
+ addrobj = config.db.store.find(Address, address=address).one()
if addrobj is None:
if real_name is None:
- real_name = ''
+ real_name = u''
addrobj = Address(address=address, real_name=real_name)
addrobj.preferences = Preferences()
# Link the address to the user if it is not already linked.
diff --git a/Mailman/database/usermanager.py b/Mailman/database/usermanager.py
index f58e52e68..ab41409d8 100644
--- a/Mailman/database/usermanager.py
+++ b/Mailman/database/usermanager.py
@@ -46,11 +46,13 @@ class UserManager(object):
return user
def delete_user(self, user):
- user.delete()
+ config.db.store.remove(user)
@property
def users(self):
- for user in User.query.filter_by().all():
+ # Avoid circular imports.
+ from Mailman.database.model import User
+ for user in config.db.store.find(User):
yield user
def get_user(self, address):
diff --git a/Mailman/docs/usermanager.txt b/Mailman/docs/usermanager.txt
index b8a9d2e66..95cded2aa 100644
--- a/Mailman/docs/usermanager.txt
+++ b/Mailman/docs/usermanager.txt
@@ -7,7 +7,6 @@ variable MANAGERS_INIT_FUNCTION. The instance is accessible on the global
config object.
>>> from Mailman.configuration import config
- >>> from Mailman.database import flush
>>> from Mailman.interfaces import IUserManager
>>> from zope.interface.verify import verifyObject
>>> usermgr = config.db.user_manager
@@ -25,13 +24,12 @@ have a password.
>>> from Mailman.interfaces import IUser
>>> user = usermgr.create_user()
- >>> flush()
>>> verifyObject(IUser, user)
True
>>> sorted(address.address for address in user.addresses)
[]
>>> user.real_name
- ''
+ u''
>>> print user.password
None
@@ -42,59 +40,53 @@ The user has preferences, but none of them will be specified.
A user can be assigned a real name.
- >>> user.real_name = 'Anne Person'
- >>> flush()
+ >>> user.real_name = u'Anne Person'
>>> sorted(user.real_name for user in usermgr.users)
- ['Anne Person']
+ [u'Anne Person']
A user can be assigned a password.
- >>> user.password = 'secret'
- >>> flush()
+ >>> user.password = u'secret'
>>> sorted(user.password for user in usermgr.users)
- ['secret']
+ [u'secret']
You can also create a user with an address to start out with.
- >>> user_2 = usermgr.create_user('bperson@example.com')
- >>> flush()
+ >>> user_2 = usermgr.create_user(u'bperson@example.com')
>>> verifyObject(IUser, user_2)
True
>>> sorted(address.address for address in user_2.addresses)
- ['bperson@example.com']
+ [u'bperson@example.com']
>>> sorted(user.real_name for user in usermgr.users)
- ['', 'Anne Person']
+ [u'', u'Anne Person']
As above, you can assign a real name to such users.
- >>> user_2.real_name = 'Ben Person'
- >>> flush()
+ >>> user_2.real_name = u'Ben Person'
>>> sorted(user.real_name for user in usermgr.users)
- ['Anne Person', 'Ben Person']
+ [u'Anne Person', u'Ben Person']
You can also create a user with just a real name.
- >>> user_3 = usermgr.create_user(real_name='Claire Person')
- >>> flush()
+ >>> user_3 = usermgr.create_user(real_name=u'Claire Person')
>>> verifyObject(IUser, user_3)
True
>>> sorted(address.address for address in user.addresses)
[]
>>> sorted(user.real_name for user in usermgr.users)
- ['Anne Person', 'Ben Person', 'Claire Person']
+ [u'Anne Person', u'Ben Person', u'Claire Person']
Finally, you can create a user with both an address and a real name.
- >>> user_4 = usermgr.create_user('dperson@example.com', 'Dan Person')
- >>> flush()
+ >>> user_4 = usermgr.create_user(u'dperson@example.com', u'Dan Person')
>>> verifyObject(IUser, user_3)
True
>>> sorted(address.address for address in user_4.addresses)
- ['dperson@example.com']
+ [u'dperson@example.com']
>>> sorted(address.real_name for address in user_4.addresses)
- ['Dan Person']
+ [u'Dan Person']
>>> sorted(user.real_name for user in usermgr.users)
- ['Anne Person', 'Ben Person', 'Claire Person', 'Dan Person']
+ [u'Anne Person', u'Ben Person', u'Claire Person', u'Dan Person']
Deleting users
@@ -104,9 +96,8 @@ You delete users by going through the user manager. The deleted user is no
longer available through the user manager iterator.
>>> usermgr.delete_user(user)
- >>> flush()
>>> sorted(user.real_name for user in usermgr.users)
- ['Ben Person', 'Claire Person', 'Dan Person']
+ [u'Ben Person', u'Claire Person', u'Dan Person']
Finding users
@@ -127,9 +118,8 @@ object.
If the address is not in the user database or does not have a user associated
with it, you will get None back.
- >>> print usermgr.get_user('zperson@example.com')
+ >>> print usermgr.get_user(u'zperson@example.com')
None
>>> user_4.unlink(address)
- >>> flush()
>>> print usermgr.get_user(address.address)
None
diff --git a/Mailman/docs/users.txt b/Mailman/docs/users.txt
index 130c97210..d346d37fe 100644
--- a/Mailman/docs/users.txt
+++ b/Mailman/docs/users.txt
@@ -7,7 +7,6 @@ they control.
See usermanager.txt for examples of how to create, delete, and find users.
- >>> from Mailman.database import flush
>>> from Mailman.configuration import config
>>> usermgr = config.db.user_manager
@@ -18,23 +17,21 @@ User data
Users may have a real name and a password.
>>> user_1 = usermgr.create_user()
- >>> user_1.password = 'my password'
- >>> user_1.real_name = 'Zoe Person'
- >>> flush()
+ >>> user_1.password = u'my password'
+ >>> user_1.real_name = u'Zoe Person'
>>> sorted(user.real_name for user in usermgr.users)
- ['Zoe Person']
+ [u'Zoe Person']
>>> sorted(user.password for user in usermgr.users)
- ['my password']
+ [u'my password']
The password and real name can be changed at any time.
- >>> user_1.real_name = 'Zoe X. Person'
- >>> user_1.password = 'another password'
- >>> flush()
+ >>> user_1.real_name = u'Zoe X. Person'
+ >>> user_1.password = u'another password'
>>> sorted(user.real_name for user in usermgr.users)
- ['Zoe X. Person']
+ [u'Zoe X. Person']
>>> sorted(user.password for user in usermgr.users)
- ['another password']
+ [u'another password']
Users addresses
@@ -47,25 +44,23 @@ many addresses, but addresses may be controlled by only one user.
The easiest way to link a user to an address is to just register the new
address on a user object.
- >>> user_1.register('zperson@example.com', 'Zoe Person')
+ >>> user_1.register(u'zperson@example.com', u'Zoe Person')
<Address: Zoe Person <zperson@example.com> [not verified] at 0x...>
- >>> user_1.register('zperson@example.org')
+ >>> user_1.register(u'zperson@example.org')
<Address: zperson@example.org [not verified] at 0x...>
- >>> flush()
>>> sorted(address.address for address in user_1.addresses)
- ['zperson@example.com', 'zperson@example.org']
+ [u'zperson@example.com', u'zperson@example.org']
>>> sorted(address.real_name for address in user_1.addresses)
- ['', 'Zoe Person']
+ [u'', u'Zoe Person']
You can also create the address separately and then link it to the user.
- >>> address_1 = usermgr.create_address('zperson@example.net')
+ >>> address_1 = usermgr.create_address(u'zperson@example.net')
>>> user_1.link(address_1)
- >>> flush()
>>> sorted(address.address for address in user_1.addresses)
- ['zperson@example.com', 'zperson@example.net', 'zperson@example.org']
+ [u'zperson@example.com', u'zperson@example.net', u'zperson@example.org']
>>> sorted(address.real_name for address in user_1.addresses)
- ['', '', 'Zoe Person']
+ [u'', u'', u'Zoe Person']
But don't try to link an address to more than one user.
@@ -79,27 +74,27 @@ You can also ask whether a given user controls a given address.
>>> user_1.controls(address_1.address)
True
- >>> user_1.controls('bperson@example.com')
+ >>> user_1.controls(u'bperson@example.com')
False
Given a text email address, the user manager can find the user that controls
that address.
- >>> usermgr.get_user('zperson@example.com') is user_1
+ >>> usermgr.get_user(u'zperson@example.com') is user_1
True
- >>> usermgr.get_user('zperson@example.net') is user_1
+ >>> usermgr.get_user(u'zperson@example.net') is user_1
True
- >>> usermgr.get_user('zperson@example.org') is user_1
+ >>> usermgr.get_user(u'zperson@example.org') is user_1
True
- >>> print usermgr.get_user('bperson@example.com')
+ >>> print usermgr.get_user(u'bperson@example.com')
None
Addresses can also be unlinked from a user.
>>> user_1.unlink(address_1)
- >>> user_1.controls('zperson@example.net')
+ >>> user_1.controls(u'zperson@example.net')
False
- >>> print usermgr.get_user('aperson@example.net')
+ >>> print usermgr.get_user(u'aperson@example.net')
None
But don't try to unlink the address from a user it's not linked to.
@@ -141,11 +136,10 @@ Some of these preferences are booleans and they can be set to True or False.
>>> from Mailman.constants import DeliveryMode
>>> prefs = user_1.preferences
>>> prefs.acknowledge_posts = True
- >>> prefs.preferred_language = 'it'
+ >>> prefs.preferred_language = u'it'
>>> prefs.receive_list_copy = False
>>> prefs.receive_own_postings = False
>>> prefs.delivery_mode = DeliveryMode.regular
- >>> flush()
>>> show_prefs(user_1.preferences)
acknowledge_posts : True
preferred_language : it