------------------------------------------------------------
revno: 45
committer: Florian Fuchs <[email protected]>
branch nick: mailman.client
timestamp: Thu 2013-03-21 18:22:32 -0700
message:
added pagination
modified:
src/mailmanclient/_client.py
src/mailmanclient/docs/using.txt
--
lp:mailman.client
https://code.launchpad.net/~mailman-coders/mailman.client/trunk
Your team Mailman Coders is subscribed to branch lp:mailman.client.
To unsubscribe from this branch go to
https://code.launchpad.net/~mailman-coders/mailman.client/trunk/+edit-subscription
=== modified file 'src/mailmanclient/_client.py'
--- src/mailmanclient/_client.py 2013-03-22 00:38:47 +0000
+++ src/mailmanclient/_client.py 2013-03-22 01:22:32 +0000
@@ -42,15 +42,6 @@
DEFAULT_PAGE_ITEM_COUNT = 50
-def _member_key(member_dict):
- """Return the keys for sorting a member.
-
- :param member_dict: The JSON dictionary for a member.
- :return: 2-tuple of (fqdn_listname, address)
- """
- return (member_dict['list_id'], member_dict['address'])
-
-
class MailmanConnectionError(Exception):
"""Custom Exception to catch connection errors."""
pass
@@ -162,8 +153,10 @@
if 'entries' not in content:
return []
return [_List(self._connection, entry['self_link'])
- for entry in sorted(content['entries'],
- key=itemgetter('fqdn_listname'))]
+ for entry in content['entries']]
+
+ def get_list_page(self, count=50, page=1):
+ return _Page(self._connection, 'lists', _List, count, page)
@property
def domains(self):
@@ -180,8 +173,10 @@
if 'entries' not in content:
return []
return [_Member(self._connection, entry['self_link'])
- for entry in sorted(content['entries'],
- key=_member_key)]
+ for entry in content['entries']]
+
+ def get_member_page(self, count=50, page=1):
+ return _Page(self._connection, 'members', _Member, count, page)
@property
def users(self):
@@ -381,6 +376,10 @@
for entry in sorted(content['entries'],
key=itemgetter('address'))]
+ def get_member_page(self, count=50, page=1):
+ url = 'lists/{0}/roster/member'.format(self.fqdn_listname)
+ return _Page(self._connection, url, _Member, count, page)
+
@property
def settings(self):
return _Settings(self._connection,
=== modified file 'src/mailmanclient/docs/using.txt'
--- src/mailmanclient/docs/using.txt 2013-03-22 00:38:47 +0000
+++ src/mailmanclient/docs/using.txt 2013-03-22 01:22:32 +0000
@@ -139,9 +139,26 @@
>>> for mlist in client.lists:
... print mlist
<List "[email protected]">
- <List "[email protected]">
- <List "[email protected]">
- <List "[email protected]">
+ <List "[email protected]">
+ <List "[email protected]">
+ <List "[email protected]">
+
+List results can be retrieved as pages:
+
+ >>> page = client.get_list_page(count=2, page=1)
+ >>> page.nr
+ 1
+ >>> for m_list in page:
+ ... print m_list
+ <List "[email protected]">
+ <List "[email protected]">
+ >>> page = page.next
+ >>> page.nr
+ 2
+ >>> for m_list in page:
+ ... print m_list
+ <List "[email protected]">
+ <List "[email protected]">
If you only want to know all lists for a specific domain, use the domain object.
@@ -211,6 +228,37 @@
<Member "[email protected]" on "test-one.example.com">
<Member "[email protected]" on "test-one.example.com">
+Membership lists can be paginated, to recieve only a part of the result.
+
+ >>> page = client.get_member_page(count=2, page=1)
+ >>> page.nr
+ 1
+ >>> for member in page:
+ ... print member
+ <Member "[email protected]" on "test-one.example.com">
+ <Member "[email protected]" on "test-one.example.com">
+
+ >>> page = page.next
+ >>> page.nr
+ 2
+ >>> for member in page:
+ ... print member
+ <Member "[email protected]" on "test-two.example.com">
+ <Member "[email protected]" on "test-two.example.com">
+
+ >>> page = test_one.get_member_page(count=1, page=1)
+ >>> page.nr
+ 1
+ >>> for member in page:
+ ... print member
+ <Member "[email protected]" on "test-one.example.com">
+ >>> page = page.next
+ >>> page.nr
+ 2
+ >>> for member in page:
+ ... print member
+ <Member "[email protected]" on "test-one.example.com">
+
We can get a single membership too.
>>> cris_test_two = test_two.get_member('[email protected]')
@@ -515,10 +563,10 @@
>>> for member in client.members:
... print '%s: %s' %(member, member.role)
+ <Member "[email protected]" on "test-one.example.com">: owner
<Member "[email protected]" on "test-one.example.com">: moderator
<Member "[email protected]" on "test-one.example.com">: member
<Member "[email protected]" on "test-one.example.com">: member
- <Member "[email protected]" on "test-one.example.com">: owner
<Member "[email protected]" on "test-two.example.com">: member
Both owners and moderators can be removed:
_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders