Commit d3b176ce authored by Florian Fuchs's avatar Florian Fuchs

added pagination

parent 9f4ae7f6
......@@ -42,15 +42,6 @@ from mailmanclient import __version__
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 @@ class Client:
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 @@ class Client:
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 @@ class _List:
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,
......
......@@ -139,9 +139,26 @@ And you can print all the known mailing lists.
>>> for mlist in client.lists:
... print mlist
<List "test-one@example.com">
<List "test-three@example.com">
<List "test-two@example.com">
<List "test-three@example.net">
<List "test-three@example.com">
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 "test-one@example.com">
<List "test-two@example.com">
>>> page = page.next
>>> page.nr
2
>>> for m_list in page:
... print m_list
<List "test-three@example.net">
<List "test-three@example.com">
If you only want to know all lists for a specific domain, use the domain object.
......@@ -211,6 +228,37 @@ We can also view the memberships for a single mailing list.
<Member "anna@example.com" on "test-one.example.com">
<Member "bill@example.com" 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 "anna@example.com" on "test-one.example.com">
<Member "bill@example.com" on "test-one.example.com">
>>> page = page.next
>>> page.nr
2
>>> for member in page:
... print member
<Member "anna@example.com" on "test-two.example.com">
<Member "cris@example.com" 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 "anna@example.com" on "test-one.example.com">
>>> page = page.next
>>> page.nr
2
>>> for member in page:
... print member
<Member "bill@example.com" on "test-one.example.com">
We can get a single membership too.
>>> cris_test_two = test_two.get_member('cris@example.com')
......@@ -515,10 +563,10 @@ list:
>>> for member in client.members:
... print '%s: %s' %(member, member.role)
<Member "foo@example.com" on "test-one.example.com">: owner
<Member "bar@example.com" on "test-one.example.com">: moderator
<Member "bar@example.com" on "test-one.example.com">: member
<Member "bill@example.com" on "test-one.example.com">: member
<Member "foo@example.com" on "test-one.example.com">: owner
<Member "anna@example.com" on "test-two.example.com">: member
Both owners and moderators can be removed:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment